Add main.py
This commit is contained in:
@@ -0,0 +1,29 @@
|
|||||||
|
"""
|
||||||
|
Entry point demonstrating the RAG agent.
|
||||||
|
|
||||||
|
Runs three example scenarios:
|
||||||
|
1. Add a sample text directly via tool call.
|
||||||
|
2. Search for a keyword.
|
||||||
|
3. Load documents from a directory using init_documents.
|
||||||
|
"""
|
||||||
|
|
||||||
|
import asyncio
|
||||||
|
from pathlib import Path
|
||||||
|
from langchain_core.messages import HumanMessage
|
||||||
|
from agent import agent
|
||||||
|
|
||||||
|
async def demo():
|
||||||
|
# 1. Add sample text
|
||||||
|
await agent.ainvoke(
|
||||||
|
{"messages": [HumanMessage(content="Add document: Sample")]},
|
||||||
|
{"configurable": {"thread_id": "demo-1"}},
|
||||||
|
)
|
||||||
|
# 2. Search
|
||||||
|
result = await agent.ainvoke(
|
||||||
|
{"messages": [HumanMessage(content="Search for Python")]},
|
||||||
|
{"configurable": {"thread_id": "demo-1"}},
|
||||||
|
)
|
||||||
|
print("Search result:\n", result["messages"][-1].content)
|
||||||
|
|
||||||
|
if __name__ == "__main__": # pragma: no cover
|
||||||
|
asyncio.run(demo())
|
||||||
Reference in New Issue
Block a user