Skip to content

Commit

Permalink
Merge pull request #31 from wri/fix-api-deploy
Browse files Browse the repository at this point in the history
Fix api deploy
  • Loading branch information
yellowcap authored Nov 29, 2024
2 parents 0b92853 + 6c260dc commit 109788c
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 10 deletions.
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -171,4 +171,7 @@ data/
.DS_Store

# VS Code
.vscode
.vscode

# Custom zeno
ee-zeno-service-account.json
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,4 @@ WORKDIR /app
RUN uv sync --frozen

# Command to run the application.
CMD ["uv", "run", "uvicorn", "api:app", "--reload"]
CMD ["uv", "run", "uvicorn", "api:app", "--reload", "--host", "0.0.0.0"]
13 changes: 8 additions & 5 deletions api.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,21 @@
from typing import Annotated

from fastapi import Body, FastAPI
from fastapi.middleware.cors import CORSMiddleware
from fastapi.responses import StreamingResponse

from zeno.agents.maingraph.utils.state import GraphState
from zeno.agents.maingraph.agent import graph

app = FastAPI()

# https://www.softgrade.org/sse-with-fastapi-react-langgraph/
# https://www.workfall.com/learning/blog/how-to-stream-json-data-using-server-sent-events-and-fastapi-in-python-over-http/

app.add_middleware(
CORSMiddleware,
allow_origins=["*"],
allow_credentials=True,
allow_methods=["*"],
allow_headers=["*"],
)

def pack(data):
return json.dumps(data) + "\n"
Expand All @@ -36,8 +41,6 @@ def event_stream(query: str):
yield pack({"tool_calls": msg.tool_calls})
if hasattr(msg, "artifact"):
yield pack({"artifact": msg.artifact})
else:
yield pack({key2: val2})


@app.post("/stream")
Expand Down
5 changes: 2 additions & 3 deletions docker-compose.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
services:
api:
build:
context: ./zeno
context: .
ports:
- "8000:8000"
environment:
Expand All @@ -15,8 +15,7 @@ services:
- .env

volumes:
- ./zeno:/app
- ./data:/app/data
- .:/app

frontend:
build:
Expand Down

0 comments on commit 109788c

Please sign in to comment.