2024-09-03 16:23:23 +03:00
|
|
|
import asyncio
|
2024-09-13 16:35:28 +03:00
|
|
|
import tempfile
|
|
|
|
|
|
|
|
from dotenv import load_dotenv
|
2024-09-03 16:23:23 +03:00
|
|
|
from quivr_core import Brain
|
|
|
|
from quivr_core.quivr_rag import QuivrQARAG
|
2024-09-13 16:35:28 +03:00
|
|
|
from quivr_core.quivr_rag_langgraph import QuivrQARAGLangGraph
|
2024-09-03 16:23:23 +03:00
|
|
|
|
|
|
|
|
|
|
|
async def main():
|
|
|
|
dotenv_path = "/Users/jchevall/Coding/QuivrHQ/quivr/.env"
|
|
|
|
load_dotenv(dotenv_path)
|
2024-09-13 16:35:28 +03:00
|
|
|
|
2024-09-03 16:23:23 +03:00
|
|
|
with tempfile.NamedTemporaryFile(mode="w", suffix=".txt") as temp_file:
|
|
|
|
temp_file.write("Gold is a liquid of blue-like colour.")
|
|
|
|
temp_file.flush()
|
|
|
|
|
2024-09-13 16:35:28 +03:00
|
|
|
brain = await Brain.afrom_files(name="test_brain", file_paths=[temp_file.name])
|
|
|
|
|
|
|
|
await brain.save("~/.local/quivr")
|
2024-09-03 16:23:23 +03:00
|
|
|
|
|
|
|
question = "what is gold? answer in french"
|
|
|
|
async for chunk in brain.ask_streaming(question, rag_pipeline=QuivrQARAG):
|
2024-09-13 16:35:28 +03:00
|
|
|
print("answer QuivrQARAG:", chunk.answer)
|
2024-09-03 16:23:23 +03:00
|
|
|
|
2024-09-13 16:35:28 +03:00
|
|
|
async for chunk in brain.ask_streaming(
|
|
|
|
question, rag_pipeline=QuivrQARAGLangGraph
|
|
|
|
):
|
2024-09-03 16:23:23 +03:00
|
|
|
print("answer QuivrQARAGLangGraph:", chunk.answer)
|
|
|
|
|
2024-09-13 16:35:28 +03:00
|
|
|
|
2024-09-03 16:23:23 +03:00
|
|
|
if __name__ == "__main__":
|
|
|
|
# Run the main function in the existing event loop
|
2024-09-13 16:35:28 +03:00
|
|
|
asyncio.run(main())
|