Ali2206 commited on
Commit
d836da7
·
verified ·
1 Parent(s): 5b1965f

Update src/txagent/txagent.py

Browse files
Files changed (1) hide show
  1. src/txagent/txagent.py +13 -11
src/txagent/txagent.py CHANGED
@@ -778,7 +778,7 @@ Generate **one summarized sentence** about "function calls' responses" with nece
778
  """
779
  print("\033[1;32;40mstart\033[0m")
780
  print("len(message)", len(message))
781
- if len(message) <= 10:
782
  yield "Hi, I am TxAgent, an assistant for answering biomedical questions. Please provide a valid message with a string longer than 10 characters."
783
  return "Please provide a valid message."
784
  outputs = []
@@ -820,13 +820,17 @@ Generate **one summarized sentence** about "function calls' responses" with nece
820
  history.extend(current_gradio_history)
821
  if special_tool_call == 'Finish':
822
  next_round = False
823
- conversation.extend(function_call_messages)
824
- return function_call_messages[0]['content']
 
 
 
825
  elif special_tool_call == 'RequireClarification' or special_tool_call == 'DirectResponse':
826
- history.append(
827
- ChatMessage(role="assistant", content=history[-1].content))
828
- yield history
829
- return history[-1].content
 
830
  if (self.enable_summary or token_overflow) and not call_agent:
831
  if token_overflow:
832
  print("token_overflow, using summary")
@@ -834,10 +838,8 @@ Generate **one summarized sentence** about "function calls' responses" with nece
834
  last_status = self.function_result_summary(
835
  conversation, status=last_status,
836
  enable_summary=enable_summary)
837
- if function_call_messages is not None:
838
  conversation.extend(function_call_messages)
839
- # Hide intermediate output
840
- pass
841
  else:
842
  next_round = False
843
  conversation.extend(
@@ -904,7 +906,7 @@ Generate **one summarized sentence** about "function calls' responses" with nece
904
  for each in history:
905
  if each.metadata is not None:
906
  each.metadata['status'] = 'done'
907
- if '[FinalAnswer]' in last_thought or '"name": "Finish",' in last_outputs_str:
908
  if '[FinalAnswer]' in last_thought:
909
  _, final_answer = last_thought.split('[FinalAnswer]', 1)
910
  else:
 
778
  """
779
  print("\033[1;32;40mstart\033[0m")
780
  print("len(message)", len(message))
781
+ if not message or len(message.strip()) <= 10:
782
  yield "Hi, I am TxAgent, an assistant for answering biomedical questions. Please provide a valid message with a string longer than 10 characters."
783
  return "Please provide a valid message."
784
  outputs = []
 
820
  history.extend(current_gradio_history)
821
  if special_tool_call == 'Finish':
822
  next_round = False
823
+ if function_call_messages and len(function_call_messages) > 0:
824
+ conversation.extend(function_call_messages)
825
+ return function_call_messages[0]['content']
826
+ else:
827
+ return "No final response available."
828
  elif special_tool_call == 'RequireClarification' or special_tool_call == 'DirectResponse':
829
+ if history:
830
+ history.append(
831
+ ChatMessage(role="assistant", content=history[-1].content))
832
+ yield history
833
+ return history[-1].content
834
  if (self.enable_summary or token_overflow) and not call_agent:
835
  if token_overflow:
836
  print("token_overflow, using summary")
 
838
  last_status = self.function_result_summary(
839
  conversation, status=last_status,
840
  enable_summary=enable_summary)
841
+ if function_call_messages:
842
  conversation.extend(function_call_messages)
 
 
843
  else:
844
  next_round = False
845
  conversation.extend(
 
906
  for each in history:
907
  if each.metadata is not None:
908
  each.metadata['status'] = 'done'
909
+ if '[FinalAnswer]' in last_thought or 'Finish' in last_outputs_str:
910
  if '[FinalAnswer]' in last_thought:
911
  _, final_answer = last_thought.split('[FinalAnswer]', 1)
912
  else: