Skip to content

Commit f6a8968

Browse files
authored
Merge branch 'main' into aw-faq
2 parents 6fc029b + 3991f86 commit f6a8968

File tree

5 files changed

+1387
-15
lines changed

5 files changed

+1387
-15
lines changed

autogen/code_utils.py

+10-11
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import signal
21
import subprocess
32
import sys
43
import os
@@ -9,6 +8,7 @@
98
from hashlib import md5
109
import logging
1110
from autogen import oai
11+
from concurrent.futures import ThreadPoolExecutor, TimeoutError
1212

1313
try:
1414
import docker
@@ -307,21 +307,20 @@ def execute_code(
307307
text=True,
308308
)
309309
else:
310-
signal.signal(signal.SIGALRM, timeout_handler)
311-
try:
312-
signal.alarm(timeout)
313-
# run the code in a subprocess in the current docker container in the working directory
314-
result = subprocess.run(
310+
with ThreadPoolExecutor(max_workers=1) as executor:
311+
future = executor.submit(
312+
subprocess.run,
315313
cmd,
316314
cwd=work_dir,
317315
capture_output=True,
318316
text=True,
319317
)
320-
signal.alarm(0)
321-
except TimeoutError:
322-
if original_filename is None:
323-
os.remove(filepath)
324-
return 1, TIMEOUT_MSG, None
318+
try:
319+
result = future.result(timeout=timeout)
320+
except TimeoutError:
321+
if original_filename is None:
322+
os.remove(filepath)
323+
return 1, TIMEOUT_MSG, None
325324
if original_filename is None:
326325
os.remove(filepath)
327326
if result.returncode:

notebook/agentchat_RetrieveChat.ipynb

+9-3
Original file line numberDiff line numberDiff line change
@@ -194,8 +194,13 @@
194194
"\n",
195195
"# 2. create the RetrieveUserProxyAgent instance named \"ragproxyagent\"\n",
196196
"# By default, the human_input_mode is \"ALWAYS\", which means the agent will ask for human input at every step. We set it to \"NEVER\" here.\n",
197-
"# `docs_path` is the path to the docs directory. By default, it is set to \"./docs\". Here we generated the documentations from FLAML's docstrings.\n",
198-
"# Navigate to the website folder and run `pydoc-markdown` and it will generate folder `reference` under `website/docs`.\n",
197+
"# `docs_path` is the path to the docs directory. It can also be the path to a single file, or the url to a single file. By default, \n",
198+
"# it is set to None, which works only if the collection is already created.\n",
199+
"# \n",
200+
"# Here we generated the documentations from FLAML's docstrings. Not needed if you just want to try this notebook but not to reproduce the\n",
201+
"# outputs. Clone the FLAML (https://github.com/microsoft/FLAML) repo and navigate to its website folder. Pip install and run `pydoc-markdown`\n",
202+
"# and it will generate folder `reference` under `website/docs`.\n",
203+
"#\n",
199204
"# `task` indicates the kind of task we're working on. In this example, it's a `code` task.\n",
200205
"# `chunk_token_size` is the chunk token size for the retrieve chat. By default, it is set to `max_tokens * 0.6`, here we set it to 2000.\n",
201206
"ragproxyagent = RetrieveUserProxyAgent(\n",
@@ -204,11 +209,12 @@
204209
" max_consecutive_auto_reply=10,\n",
205210
" retrieve_config={\n",
206211
" \"task\": \"code\",\n",
207-
" \"docs_path\": \"../website/docs/reference\",\n",
212+
" \"docs_path\": \"~/code/FLAML/website/docs/reference\", # change this to your own path, such as https://raw.githubusercontent.com/microsoft/autogen/main/README.md\n",
208213
" \"chunk_token_size\": 2000,\n",
209214
" \"model\": config_list[0][\"model\"],\n",
210215
" \"client\": chromadb.PersistentClient(path=\"/tmp/chromadb\"),\n",
211216
" \"embedding_model\": \"all-mpnet-base-v2\",\n",
217+
" \"get_or_create\": False, # set to True if you want to recreate the collection\n",
212218
" },\n",
213219
")"
214220
]

0 commit comments

Comments
 (0)