27 lines
781 B
Python
27 lines
781 B
Python
import os
|
|
from pathlib import Path
|
|
|
|
from graph_builder import build_graph_from_documents, load_graph, save_graph, sync_graph_to_neo4j
|
|
from react_agent import react_agent
|
|
|
|
GRAPH_PATH = "graph/kg.graphml"
|
|
|
|
|
|
def get_or_build_graph(force_rebuild: bool = False):
|
|
if not force_rebuild and Path(GRAPH_PATH).exists():
|
|
return load_graph(GRAPH_PATH)
|
|
graph = build_graph_from_documents()
|
|
save_graph(graph, GRAPH_PATH)
|
|
if os.getenv("NEO4J_URI") and os.getenv("NEO4J_PASSWORD"):
|
|
sync_graph_to_neo4j(graph)
|
|
return graph
|
|
|
|
|
|
def ask_question(graph, question: str):
|
|
return react_agent(question, [], graph)
|
|
|
|
|
|
if __name__ == "__main__":
|
|
graph = get_or_build_graph()
|
|
print(ask_question(graph, "Čo sa učí na predmete Slovenský jazyk a literatúra?"))
|