|
from langchain.chains import GraphCypherQAChain |
|
from langchain_openai import ChatOpenAI |
|
|
|
def query_knowledge_graph(graph, query): |
|
print("Refreshing the graph schema...") |
|
|
|
graph.refresh_schema() |
|
|
|
print("Setting up the Cypher QA Chain...") |
|
|
|
cypher_chain = GraphCypherQAChain.from_llm( |
|
graph=graph, |
|
cypher_llm=ChatOpenAI(temperature=0, model="gpt-4"), |
|
qa_llm=ChatOpenAI(temperature=0, model="gpt-3.5-turbo-16k"), |
|
|
|
) |
|
|
|
print(f"Executing the query: {query}") |
|
|
|
result = cypher_chain.invoke({"query": query}) |
|
print("Query executed. Processing results...") |
|
return result |
|
|