4
4
import autogen
5
5
import json
6
6
7
+ AUTOGEN_VERSION = packaging .version .parse (autogen .__version__ )
8
+
7
9
8
10
def default_llm_config (config_list , timeout = 180 ):
9
11
"""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):
21
23
}
22
24
23
25
# 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" ):
26
27
llm_config ["request_timeout" ] = timeout
27
28
llm_config ["use_cache" ] = False
28
- elif version < packaging .version .parse ("0.2.0b4" ):
29
+ elif AUTOGEN_VERSION < packaging .version .parse ("0.2.0b4" ):
29
30
llm_config ["timeout" ] = timeout
30
31
llm_config ["cache" ] = None
31
32
else :
@@ -52,6 +53,10 @@ def init():
52
53
f .write ("Timestamp: " + datetime .now ().isoformat () + "\n " )
53
54
f .write ("pyautogen version: " + str (autogen .__version__ ) + "\n " )
54
55
56
+ # Start logging
57
+ if AUTOGEN_VERSION < packaging .version .parse ("0.2.0b1" ):
58
+ autogen .Completion .start_logging (compact = False )
59
+
55
60
56
61
def finalize (agents ):
57
62
"""Helper function to finalize logging in a testbed scenario.
@@ -78,3 +83,9 @@ def messages_to_json(agent):
78
83
fname = agent .name + "_messages.json"
79
84
with open (os .path .join (script_dir , fname ), "wt" ) as fh :
80
85
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