-
Notifications
You must be signed in to change notification settings - Fork 0
/
api.py
37 lines (28 loc) · 845 Bytes
/
api.py
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
from fastapi import FastAPI
from swarm import Swarm
from agents import based_agent
from fastapi.concurrency import run_in_threadpool
app = FastAPI()
client = Swarm()
messages = []
@app.get("/")
def read_root():
return {"message": "API is working"}
@app.get("/wallet")
def wallet_info(address: str):
return {"data": address}
@app.get("/chat")
async def process_data(message: str):
print("Message received:", message)
messages.append({"role": "user", "content": message})
response = await run_in_threadpool(
client.run, # Pass the blocking function
agent=based_agent,
messages=messages,
context_variables={},
stream=False,
debug=False,
)
# print(response)
messages.extend(response.messages)
return {"result": "Processed", "response": response.messages}