thinkall commited on
Commit
b2cf656
1 Parent(s): 6c624af

Fix init_sender not defined

Browse files
Files changed (1) hide show
  1. autogen_utils.py +25 -7
autogen_utils.py CHANGED
@@ -54,7 +54,9 @@ def get_retrieve_config(docs_path, model_name, collection_name):
54
  def termination_msg(x):
55
  """Check if a message is a termination message."""
56
  _msg = str(x.get("content", "")).upper().strip().strip("\n").strip(".")
57
- return isinstance(x, dict) and (_msg.endswith("TERMINATE") or _msg.startswith("TERMINATE"))
 
 
58
 
59
 
60
  def _is_termination_msg(message):
@@ -107,7 +109,12 @@ def new_generate_oai_reply(
107
 
108
 
109
  def initialize_agents(
110
- llm_config, agent_name, system_msg, agent_type, retrieve_config=None, code_execution_config=False
 
 
 
 
 
111
  ):
112
  agent_name = agent_name.strip()
113
  system_msg = system_msg.strip()
@@ -175,9 +182,13 @@ async def get_human_input(name, prompt: str, instance=None) -> str:
175
  """Get human input."""
176
  if instance is None:
177
  return input(prompt)
178
- get_input_widget = pn.widgets.TextAreaInput(placeholder=prompt, name="", sizing_mode="stretch_width")
 
 
179
  get_input_checkbox = pn.widgets.Checkbox(name="Check to Submit Feedback")
180
- instance.send(pn.Row(get_input_widget, get_input_checkbox), user=name, respond=False)
 
 
181
  ts = time.time()
182
  while True:
183
  if time.time() - ts > TIMEOUT:
@@ -221,7 +232,10 @@ async def check_termination_and_human_reply(
221
  # if the human input is empty, and the message is a termination message, then we will terminate the conversation
222
  reply = reply if reply or not self._is_termination_msg(message) else "exit"
223
  else:
224
- if self._consecutive_auto_reply_counter[sender] >= self._max_consecutive_auto_reply_dict[sender]:
 
 
 
225
  if self.human_input_mode == "NEVER":
226
  reply = "exit"
227
  else:
@@ -280,7 +294,9 @@ async def format_code(code_to_format: str) -> str:
280
  filename = f"temp_code_{int(time.time())}_{random.randint(10000, 99999)}.py"
281
  with open(filename, "w") as file:
282
  file.write(code_to_format)
283
- isort.file(filename, profile="black", known_first_party=["autogen"], float_to_top=True)
 
 
284
 
285
  formatted_code = ""
286
  with open(filename, "r") as file:
@@ -358,7 +374,8 @@ agent = RetrieveUserProxyAgent(
358
 
359
  """
360
  _code = _code.replace(
361
- """'chromadb.PersistentClient(path=".chromadb")'""", "chromadb.PersistentClient(path='.chromadb')"
 
362
  )
363
  elif isinstance(agent, GPTAssistantAgent):
364
  _code = f"""from auotgen.agentchat.contrib.gpt_assistant_agent import GPTAssistantAgent
@@ -429,6 +446,7 @@ agent = AssistantAgent(
429
  code += _code + "\n" + "agents.append(agent)\n\n"
430
 
431
  _code = """
 
432
  for agent in agents:
433
  if "UserProxy" in str(type(agent)):
434
  init_sender = agent
 
54
  def termination_msg(x):
55
  """Check if a message is a termination message."""
56
  _msg = str(x.get("content", "")).upper().strip().strip("\n").strip(".")
57
+ return isinstance(x, dict) and (
58
+ _msg.endswith("TERMINATE") or _msg.startswith("TERMINATE")
59
+ )
60
 
61
 
62
  def _is_termination_msg(message):
 
109
 
110
 
111
  def initialize_agents(
112
+ llm_config,
113
+ agent_name,
114
+ system_msg,
115
+ agent_type,
116
+ retrieve_config=None,
117
+ code_execution_config=False,
118
  ):
119
  agent_name = agent_name.strip()
120
  system_msg = system_msg.strip()
 
182
  """Get human input."""
183
  if instance is None:
184
  return input(prompt)
185
+ get_input_widget = pn.widgets.TextAreaInput(
186
+ placeholder=prompt, name="", sizing_mode="stretch_width"
187
+ )
188
  get_input_checkbox = pn.widgets.Checkbox(name="Check to Submit Feedback")
189
+ instance.send(
190
+ pn.Row(get_input_widget, get_input_checkbox), user=name, respond=False
191
+ )
192
  ts = time.time()
193
  while True:
194
  if time.time() - ts > TIMEOUT:
 
232
  # if the human input is empty, and the message is a termination message, then we will terminate the conversation
233
  reply = reply if reply or not self._is_termination_msg(message) else "exit"
234
  else:
235
+ if (
236
+ self._consecutive_auto_reply_counter[sender]
237
+ >= self._max_consecutive_auto_reply_dict[sender]
238
+ ):
239
  if self.human_input_mode == "NEVER":
240
  reply = "exit"
241
  else:
 
294
  filename = f"temp_code_{int(time.time())}_{random.randint(10000, 99999)}.py"
295
  with open(filename, "w") as file:
296
  file.write(code_to_format)
297
+ isort.file(
298
+ filename, profile="black", known_first_party=["autogen"], float_to_top=True
299
+ )
300
 
301
  formatted_code = ""
302
  with open(filename, "r") as file:
 
374
 
375
  """
376
  _code = _code.replace(
377
+ """'chromadb.PersistentClient(path=".chromadb")'""",
378
+ "chromadb.PersistentClient(path='.chromadb')",
379
  )
380
  elif isinstance(agent, GPTAssistantAgent):
381
  _code = f"""from auotgen.agentchat.contrib.gpt_assistant_agent import GPTAssistantAgent
 
446
  code += _code + "\n" + "agents.append(agent)\n\n"
447
 
448
  _code = """
449
+ init_sender = None
450
  for agent in agents:
451
  if "UserProxy" in str(type(agent)):
452
  init_sender = agent