-
Notifications
You must be signed in to change notification settings - Fork 53
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
51 additions
and
2 deletions.
There are no files selected for viewing
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
NEO4J_URI=bolt://xxx | ||
NEO4J_USERNAME=neo4j | ||
NEO4J_PASSWORD=xxx | ||
NEO4J_DATABASE=neo4j |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
from langchain_openai import ChatOpenAI | ||
from langchain_community.graphs import Neo4jGraph | ||
from langchain.prompts import PromptTemplate | ||
from dotenv import load_dotenv | ||
import json | ||
load_dotenv() | ||
graph=Neo4jGraph() | ||
schema=graph.get_schema | ||
llm=ChatOpenAI(model="gpt-4o") | ||
template=""" | ||
Task: Generate Cypher statement to query a graph database. | ||
Instructions: | ||
Use only the provided nodes, relationship and properties from the schema provided below: | ||
{schema} | ||
Do not use any other relationship types or properties that are not provided. | ||
sample question and queries given below: | ||
question:display the os name which is used maximum time | ||
query:MATCH (:Machine)-[:RUNS]->(os:OS) RETURN os.name AS osName ,count(os) as os order by os DESC limit 1 | ||
The question is: | ||
{question} | ||
your response will be only json with below key nothing else | ||
'query': | ||
""" | ||
prompt=PromptTemplate.from_template(template) | ||
chain=prompt | llm | ||
response=chain.invoke({"schema":schema,"question":"display all racks name and count of machine it is holding"}) | ||
response=response.content | ||
response=response.replace("json","") | ||
response=response.replace("`","") | ||
query=json.loads(response)["query"] | ||
print(query) | ||
result=graph.query(query=query) | ||
print(result) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
Task: Generate Cypher statement to query a graph database. | ||
Instructions: | ||
Use only the provided nodes, relationship and properties from the schema provided below: | ||
{schema} | ||
Do not use any other relationship types or properties that are not provided. | ||
The question is: | ||
{question} | ||
your response will be only json with below key nothing else | ||
'query': |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
display all distinctint os count | ||
display all distinctint machine count based on os | ||
display all racks name and count of machine it is holding |
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.