diff --git a/docs/docs/use_cases/graph/graph_gremlin_cosmosdb_qa.ipynb b/docs/docs/use_cases/graph/graph_gremlin_cosmosdb_qa.ipynb index ae05928466750..3ae5d2f2d8ba4 100644 --- a/docs/docs/use_cases/graph/graph_gremlin_cosmosdb_qa.ipynb +++ b/docs/docs/use_cases/graph/graph_gremlin_cosmosdb_qa.ipynb @@ -27,12 +27,12 @@ "metadata": {}, "outputs": [], "source": [ - "from langchain_community.graphs import GremlinGraph\n", + "import nest_asyncio\n", "from langchain.chains.graph_qa import GremlinQAChain\n", - "from langchain_openai import AzureChatOpenAI\n", "from langchain.schema import Document\n", + "from langchain_community.graphs import GremlinGraph\n", "from langchain_community.graphs.graph_document import GraphDocument, Node, Relationship\n", - "import nest_asyncio" + "from langchain_openai import AzureChatOpenAI" ] }, { @@ -48,9 +48,9 @@ "cosmosdb_access_Key = \"longstring==\"\n", "\n", "graph = GremlinGraph(\n", - " url=f\"=wss://{cosmosdb_name}.gremlin.cosmos.azure.com:443/\", \n", - " username=f\"/dbs/{cosmosdb_db_id}/colls/{cosmosdb_db_graph_id}\", \n", - " password=cosmosdb_access_Key\n", + " url=f\"=wss://{cosmosdb_name}.gremlin.cosmos.azure.com:443/\",\n", + " username=f\"/dbs/{cosmosdb_db_id}/colls/{cosmosdb_db_graph_id}\",\n", + " password=cosmosdb_access_Key,\n", ")" ] }, @@ -75,21 +75,51 @@ "metadata": {}, "outputs": [], "source": [ - "source_doc = Document(page_content=\"Matrix is a movie where Keanu Reeves, Laurence Fishburne and Carrie-Anne Moss acted.\")\n", - "movie = Node(id=\"The Matrix\", properties={\"label\":\"movie\", \"title\": \"The Matrix\"})\n", - "actor1 = Node(id=\"Keanu Reeves\", properties={\"label\":\"actor\", \"name\": \"Keanu Reeves\"})\n", - "actor2 = Node(id=\"Laurence Fishburne\", properties={\"label\":\"actor\", \"name\": \"Laurence Fishburne\"})\n", - "actor3 = Node(id=\"Carrie-Anne Moss\", properties={\"label\":\"actor\", \"name\": \"Carrie-Anne Moss\"})\n", - "rel1 = Relationship(id=5, type=\"ActedIn\", source=actor1, target=movie, properties={\"label\":\"ActedIn\"})\n", - "rel2 = Relationship(id=6, type=\"ActedIn\", source=actor2, target=movie, properties={\"label\":\"ActedIn\"})\n", - "rel3 = Relationship(id=7, type=\"ActedIn\", source=actor3, target=movie, properties={\"label\":\"ActedIn\"})\n", - "rel4 = Relationship(id=8, type=\"Starring\", source=movie, target=actor1, properties={\"label\":\"Strarring\"})\n", - "rel5 = Relationship(id=9, type=\"Starring\", source=movie, target=actor2, properties={\"label\":\"Strarring\"})\n", - "rel6 = Relationship(id=10, type=\"Straring\", source=movie, target=actor3, properties={\"label\":\"Strarring\"})\n", + "source_doc = Document(\n", + " page_content=\"Matrix is a movie where Keanu Reeves, Laurence Fishburne and Carrie-Anne Moss acted.\"\n", + ")\n", + "movie = Node(id=\"The Matrix\", properties={\"label\": \"movie\", \"title\": \"The Matrix\"})\n", + "actor1 = Node(id=\"Keanu Reeves\", properties={\"label\": \"actor\", \"name\": \"Keanu Reeves\"})\n", + "actor2 = Node(\n", + " id=\"Laurence Fishburne\", properties={\"label\": \"actor\", \"name\": \"Laurence Fishburne\"}\n", + ")\n", + "actor3 = Node(\n", + " id=\"Carrie-Anne Moss\", properties={\"label\": \"actor\", \"name\": \"Carrie-Anne Moss\"}\n", + ")\n", + "rel1 = Relationship(\n", + " id=5, type=\"ActedIn\", source=actor1, target=movie, properties={\"label\": \"ActedIn\"}\n", + ")\n", + "rel2 = Relationship(\n", + " id=6, type=\"ActedIn\", source=actor2, target=movie, properties={\"label\": \"ActedIn\"}\n", + ")\n", + "rel3 = Relationship(\n", + " id=7, type=\"ActedIn\", source=actor3, target=movie, properties={\"label\": \"ActedIn\"}\n", + ")\n", + "rel4 = Relationship(\n", + " id=8,\n", + " type=\"Starring\",\n", + " source=movie,\n", + " target=actor1,\n", + " properties={\"label\": \"Strarring\"},\n", + ")\n", + "rel5 = Relationship(\n", + " id=9,\n", + " type=\"Starring\",\n", + " source=movie,\n", + " target=actor2,\n", + " properties={\"label\": \"Strarring\"},\n", + ")\n", + "rel6 = Relationship(\n", + " id=10,\n", + " type=\"Straring\",\n", + " source=movie,\n", + " target=actor3,\n", + " properties={\"label\": \"Strarring\"},\n", + ")\n", "graph_doc = GraphDocument(\n", " nodes=[movie, actor1, actor2, actor3],\n", " relationships=[rel1, rel2, rel3, rel4, rel5, rel6],\n", - " source=source_doc\n", + " source=source_doc,\n", ")" ] }, @@ -105,7 +135,7 @@ "nest_asyncio.apply()\n", "\n", "# Add the document to the CosmosDB graph.\n", - "graph.add_graph_documents([graph_doc]) " + "graph.add_graph_documents([graph_doc])" ] }, { @@ -154,13 +184,13 @@ "metadata": {}, "outputs": [], "source": [ - "\n", "chain = GremlinQAChain.from_llm(\n", - " AzureChatOpenAI(temperature=0,\n", - " azure_deployment=\"gpt-4-turbo\",\n", - " ), \n", - " graph=graph, \n", - " verbose=True\n", + " AzureChatOpenAI(\n", + " temperature=0,\n", + " azure_deployment=\"gpt-4-turbo\",\n", + " ),\n", + " graph=graph,\n", + " verbose=True,\n", ")" ] },