forked from Eyuvaraj/FetchAI-Hackathon
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
58 lines (40 loc) · 1.41 KB
/
main.py
File metadata and controls
58 lines (40 loc) · 1.41 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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
import json
from openai import chat
from fastapi import FastAPI
from uagents import Model
from uagents.query import query
from pydantic import BaseModel
QUESTIONNAIRE_ADDRESS = "agent1qff6gfj65rz50ae2pjpnhrvqu3a5yypsqcmphuagkmxqdpwf3vwv53vu8xv"
MODELDECRIPTOR_ADDRESS = "agent1qgk2srf2axh35fklj9p5nt7xwvsq2965540t5q7eav8wwfjh59g52m34y2t"
class TestRequest(Model):
message: str
class TestRequest(Model):
message: list
async def agent_query_QuestionnaireAgent(req):
response = await query(destination=QUESTIONNAIRE_ADDRESS, message=req, timeout=15.0)
data = json.loads(response.decode_payload())
return data["text"]
async def agent_query_ModelDescriptorAgent(req):
response = await query(destination=QUESTIONNAIRE_ADDRESS, message=req, timeout=15.0)
data = json.loads(response.decode_payload())
return data["text"]
app = FastAPI()
@app.get("/")
def read_root():
return "Hello from the Agent controller"
@app.post("/new_request")
async def make_agent_call(req: TestRequest):
try:
res = await agent_query_QuestionnaireAgent(req)
return {"data": res}
except Exception as e:
print(e)
return "unsuccessful agent call"
class messages(BaseModel):
role: str
content: str
@app.post("/post_messages")
async def Post_Messages(request: list[messages]):
for item in request:
print(item.role, item.content)
return {"message": "success"}