-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapi_example.py
More file actions
30 lines (25 loc) · 772 Bytes
/
Copy pathapi_example.py
File metadata and controls
30 lines (25 loc) · 772 Bytes
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
import asyncio
from flowk import Graph # pyre-ignore
from pydantic import BaseModel # pyre-ignore
class AgentState(BaseModel):
message: str
reply: str = ""
g = Graph(state_schema=AgentState)
@g.node()
async def process_message(message: str, state: dict):
print(f"Server processing: {message}")
await asyncio.sleep(1) # simulate work
state["reply"] = f"Echo: {message}"
return state["reply"]
g.entrypoint = process_message
# To run this script:
# Option 1: pip install "flowk[api]"
# Option 2: pip install fastapi uvicorn
#
# Then run: python api_example.py
if __name__ == "__main__":
# This single line spins up a production-ready Web API!
# - POST /invoke
# - POST /stream
# - GET /docs (Swagger UI)
g.serve(port=8080)