Skip to content

Commit 3e890a3

Browse files
Gl/add async flag (#7)
* add async flag * add async flag to cli * update version
1 parent a774210 commit 3e890a3

3 files changed

Lines changed: 14 additions & 7 deletions

File tree

grafi_dev/cli.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ def run(
5252
host: str = "127.0.0.1",
5353
port: int = 8080,
5454
assistant_name: str = "assistant",
55+
is_async: bool = True,
5556
open_browser: bool = True,
5657
):
5758
"""Run the assistant in *script* and launch the web UI."""
@@ -71,7 +72,7 @@ def run(
7172

7273
# Pass the assistant instance directly to create_app
7374
uvicorn.run(
74-
lambda: create_app(assistant),
75+
lambda: create_app(assistant=assistant, is_async=is_async), # type: ignore
7576
factory=True, # <─ tells Uvicorn to call it
7677
host=host,
7778
port=port,

grafi_dev/server.py

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -76,16 +76,22 @@ def get_request_ids(conv_id: str):
7676

7777

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

8282
@api.post("/chat", response_model=ChatReply)
8383
async def chat(req: ChatRequest):
8484
try:
85-
out = assistant.execute(
86-
_execution_context(req.conversation_id, req.assistant_request_id),
87-
_to_messages(req.messages),
88-
)
85+
if is_async:
86+
out = await assistant.a_execute(
87+
_execution_context(req.conversation_id, req.assistant_request_id),
88+
_to_messages(req.messages),
89+
)
90+
else:
91+
out = assistant.execute(
92+
_execution_context(req.conversation_id, req.assistant_request_id),
93+
_to_messages(req.messages),
94+
)
8995
logger.info(out)
9096
return ChatReply(messages=out)
9197
except Exception as exc:

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
44

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

0 commit comments

Comments
 (0)