-
Notifications
You must be signed in to change notification settings - Fork 24
Expand file tree
/
Copy pathlangchain_rag_user.py
More file actions
38 lines (27 loc) · 1.04 KB
/
langchain_rag_user.py
File metadata and controls
38 lines (27 loc) · 1.04 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
from ai_engine import UAgentResponse
from messages.requests import RagRequest
from uagents import Agent, Context, Protocol
QUESTION = "How to install uagents using pip"
URL = "https://fetch.ai/docs/guides/agents/installing-uagent"
DEEP_READ = "no"
RAG_AGENT_ADDRESS = "YOUR_LANGCHAIN_RAG_AGENT_ADDRESS"
user = Agent(
name="langchain_rag_user",
port=8000,
endpoint=["http://127.0.0.1:8000/submit"],
)
rag_user = Protocol("LangChain RAG user")
@rag_user.on_interval(60, messages=RagRequest)
async def ask_question(ctx: Context):
ctx.logger.info(
f"Asking RAG agent to answer {QUESTION} based on document located at {URL}, reading nested pages too: {DEEP_READ}"
)
await ctx.send(
RAG_AGENT_ADDRESS, RagRequest(question=QUESTION, url=URL, deep_read=DEEP_READ)
)
@rag_user.on_message(model=UAgentResponse)
async def handle_data(ctx: Context, sender: str, data: UAgentResponse):
ctx.logger.info(f"Got response from RAG agent: {data.message}")
user.include(rag_user)
if __name__ == "__main__":
user.run()