From a1969d0dc0ab5288b9d86c91c3a22a4d316f84bd Mon Sep 17 00:00:00 2001 From: GuanyiLi-Craig Date: Wed, 11 Jun 2025 21:13:37 +0100 Subject: [PATCH 1/3] add async flag --- grafi_dev/server.py | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/grafi_dev/server.py b/grafi_dev/server.py index 582e6fc..22baf1f 100644 --- a/grafi_dev/server.py +++ b/grafi_dev/server.py @@ -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 = False) -> 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: From 34107e9db1071f88786d41cac23329710cea89d9 Mon Sep 17 00:00:00 2001 From: GuanyiLi-Craig Date: Wed, 11 Jun 2025 21:17:34 +0100 Subject: [PATCH 2/3] add async flag to cli --- grafi_dev/cli.py | 3 ++- grafi_dev/server.py | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/grafi_dev/cli.py b/grafi_dev/cli.py index 5f829fe..1839f97 100644 --- a/grafi_dev/cli.py +++ b/grafi_dev/cli.py @@ -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.""" @@ -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, diff --git a/grafi_dev/server.py b/grafi_dev/server.py index 22baf1f..a9ad43a 100644 --- a/grafi_dev/server.py +++ b/grafi_dev/server.py @@ -76,7 +76,7 @@ def get_request_ids(conv_id: str): # ---------- FastAPI factory --------------------------------------------- -def create_app(assistant: Assistant, is_async: bool = False) -> FastAPI: +def create_app(assistant: Assistant, is_async: bool = True) -> FastAPI: api = FastAPI(title="Graphite-Dev API") @api.post("/chat", response_model=ChatReply) From 6e856603fc489b6def3c7a97716c15d8a6ecda12 Mon Sep 17 00:00:00 2001 From: GuanyiLi-Craig Date: Wed, 11 Jun 2025 21:17:56 +0100 Subject: [PATCH 3/3] update version --- pyproject.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pyproject.toml b/pyproject.toml index 09b43c5..c9e494d 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -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"