Skip to content

Commit 141e379

Browse files
committed
feat: Enable asynchronous execution for contract processing and resume functionality using asyncio
1 parent ce67263 commit 141e379

1 file changed

Lines changed: 5 additions & 5 deletions

File tree

api/main.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
from __future__ import annotations
22

3+
import asyncio
34
import os
45
import tempfile
56
import uuid
@@ -131,10 +132,10 @@ async def run_contract(
131132

132133
# "provider": "openai" with no OPENAI_API_KEY triggers heuristic fallback.
133134
# To use a real LLM, set the relevant API key in the environment.
134-
# TODO: wrap in asyncio.to_thread() if adding real LLM support (blocking call).
135-
graph.invoke(
135+
await asyncio.to_thread(
136+
graph.invoke,
136137
{"contract_path": str(tmp_path), "provider": "openai"},
137-
config=config,
138+
config,
138139
)
139140

140141
interrupt_payload = _get_interrupt_payload(config)
@@ -192,8 +193,7 @@ async def resume_contract(
192193
"edited_risks": body.edited_risks,
193194
}
194195

195-
# TODO: wrap in asyncio.to_thread() if adding real LLM support.
196-
graph.invoke(Command(resume=resume_value), config=config)
196+
await asyncio.to_thread(graph.invoke, Command(resume=resume_value), config)
197197

198198
final_state = graph.get_state(config).values
199199
return ResumeResponse(

0 commit comments

Comments
 (0)