Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion grafi_dev/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ def run(
host: str = "127.0.0.1",
port: int = 8080,
assistant_name: str = "assistant",
is_async: bool = True,
open_browser: bool = True,
):
"""Run the assistant in *script* and launch the web UI."""
Expand All @@ -71,7 +72,7 @@ def run(

# Pass the assistant instance directly to create_app
uvicorn.run(
lambda: create_app(assistant),
lambda: create_app(assistant=assistant, is_async=is_async), # type: ignore
factory=True, # <─ tells Uvicorn to call it
host=host,
port=port,
Expand Down
16 changes: 11 additions & 5 deletions grafi_dev/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,16 +76,22 @@ def get_request_ids(conv_id: str):


# ---------- FastAPI factory ---------------------------------------------
def create_app(assistant: Assistant) -> FastAPI:
def create_app(assistant: Assistant, is_async: bool = True) -> FastAPI:
api = FastAPI(title="Graphite-Dev API")

@api.post("/chat", response_model=ChatReply)
async def chat(req: ChatRequest):
try:
out = assistant.execute(
_execution_context(req.conversation_id, req.assistant_request_id),
_to_messages(req.messages),
)
if is_async:
out = await assistant.a_execute(
_execution_context(req.conversation_id, req.assistant_request_id),
_to_messages(req.messages),
)
else:
out = assistant.execute(
_execution_context(req.conversation_id, req.assistant_request_id),
_to_messages(req.messages),
)
logger.info(out)
return ChatReply(messages=out)
except Exception as exc:
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"

[project]
name = "grafi-dev"
version = "0.0.2"
version = "0.0.3"
description = "Run a grafi Assistant locally with a live workflow graph & trace viewer"
authors = [{ name = "Craig Li", email = "craig@binome.dev" }]
readme = "README.md"
Expand Down