From 175768b2e5c42586125fe5e3c877f22822b2b58e Mon Sep 17 00:00:00 2001 From: lonpatovaadelina Date: Wed, 3 Jun 2026 09:02:25 +0000 Subject: [PATCH] =?UTF-8?q?=D0=94=D0=BE=D1=80=D0=B0=D0=B1=D0=BE=D1=82?= =?UTF-8?q?=D0=BA=D0=B0:=201.=20=D0=92=20vectorstore.py=20=D0=B7=D0=B0?= =?UTF-8?q?=D0=BC=D0=B5=D0=BD=D0=B8=D1=82=D1=8C=20=D0=B8=D0=BC=D0=BF=D0=BE?= =?UTF-8?q?=D1=80=D1=82=20Ollama=20=D0=BD=D0=B0=20from=20langchain?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- main.py | 39 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) create mode 100644 main.py diff --git a/main.py b/main.py new file mode 100644 index 0000000..7e59d3a --- /dev/null +++ b/main.py @@ -0,0 +1,39 @@ +import os +from dotenv import load_dotenv + +from vectorstore import create_vectorstore, load_documents +from agent import create_agent + +def main(): + load_dotenv() # загружает TAVILY_API_KEY из .env + + persist_dir = "./chroma_db" + vectorstore = create_vectorstore(persist_directory=persist_dir) + + docs_dir = "./documents" + load_documents(docs_dir, vectorstore) + + agent_executor = create_agent(vectorstore) + + print("RAG-агент готов. Введите 'exit' для выхода.") + while True: + query = input("\nЗапрос: ").strip() + if query.lower() in ("exit", "quit"): + break + if not query: + continue + + result = agent_executor.invoke({"input": query}) + # Ожидаем, что агент вернёт dict с полями 'output' и, опционально, 'source' + if isinstance(result, dict): + output = result.get("output", "") + source = result.get("source", "unknown") + else: + output = str(result) + source = "unknown" + + print(f"\n{output}") + print(f"Источник: {source}") + +if __name__ == "__main__": + main() \ No newline at end of file