make code execution async (#219)

* make code execution async

* python 3.10 does not support asyncio.timeout()

* make code execution cancellable

* make code execution async

* python 3.10 does not support asyncio.timeout()

* make code execution cancellable

* make entire callstack for code_executor async

* Update python/src/agnext/components/code_executor/_impl/local_commandline_code_executor.py

Co-authored-by: Jack Gerrits <jackgerrits@users.noreply.github.com>

* fix variable description

* remove unnecessary code

* fix usage of execute_code_blocks

* fix usage of execute_code_blocks

---------

Co-authored-by: Jack Gerrits <jackgerrits@users.noreply.github.com>
Co-authored-by: Eric Zhu <ekzhu@users.noreply.github.com>
This commit is contained in:
peterychang
2024-07-26 18:37:34 -04:00
committed by GitHub
parent 53343972f0
commit 070a97ceaa
8 changed files with 100 additions and 82 deletions

View File

@@ -1,4 +1,3 @@
import asyncio
import re
from typing import List, Optional, Tuple, Union
@@ -81,11 +80,7 @@ class Executor(BaseAgent):
code = self._extract_execution_request(message_content_to_str(message.content))
if code is not None:
execution_requests = [CodeBlock(code=code, language="python")]
future = asyncio.get_event_loop().run_in_executor(
None, self._executor.execute_code_blocks, execution_requests
)
cancellation_token.link_future(future)
result = await future
result = await self._executor.execute_code_blocks(execution_requests)
if result.output.strip() == "":
# Sometimes agents forget to print(). Remind the to print something