Skip to content

Commit f790109

Browse files
authored
Re-added completion logging when using older versions of autogen. (#701)
1 parent 1b1cfaf commit f790109

File tree

1 file changed

+14
-3
lines changed

1 file changed

+14
-3
lines changed

samples/tools/testbed/includes/testbed_utils.py

+14-3
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
import autogen
55
import json
66

7+
AUTOGEN_VERSION = packaging.version.parse(autogen.__version__)
8+
79

810
def default_llm_config(config_list, timeout=180):
911
"""Return a default config list with a given timeout, and with caching disabled.
@@ -21,11 +23,10 @@ def default_llm_config(config_list, timeout=180):
2123
}
2224

2325
# Add options depending on the version
24-
version = packaging.version.parse(autogen.__version__)
25-
if version < packaging.version.parse("0.2.0b1"):
26+
if AUTOGEN_VERSION < packaging.version.parse("0.2.0b1"):
2627
llm_config["request_timeout"] = timeout
2728
llm_config["use_cache"] = False
28-
elif version < packaging.version.parse("0.2.0b4"):
29+
elif AUTOGEN_VERSION < packaging.version.parse("0.2.0b4"):
2930
llm_config["timeout"] = timeout
3031
llm_config["cache"] = None
3132
else:
@@ -52,6 +53,10 @@ def init():
5253
f.write("Timestamp: " + datetime.now().isoformat() + "\n")
5354
f.write("pyautogen version: " + str(autogen.__version__) + "\n")
5455

56+
# Start logging
57+
if AUTOGEN_VERSION < packaging.version.parse("0.2.0b1"):
58+
autogen.Completion.start_logging(compact=False)
59+
5560

5661
def finalize(agents):
5762
"""Helper function to finalize logging in a testbed scenario.
@@ -78,3 +83,9 @@ def messages_to_json(agent):
7883
fname = agent.name + "_messages.json"
7984
with open(os.path.join(script_dir, fname), "wt") as fh:
8085
fh.write(messages_to_json(agent))
86+
87+
# Stop logging, and write logs to disk
88+
if AUTOGEN_VERSION < packaging.version.parse("0.2.0b1"):
89+
with open(os.path.join(script_dir, "completion_log.json"), "wt") as fh:
90+
fh.write(json.dumps(autogen.Completion.logged_history, indent=4))
91+
autogen.Completion.stop_logging()

0 commit comments

Comments
 (0)