Ali2206 commited on
Commit
5f685bd
·
verified ·
1 Parent(s): bb4ae6e

Update src/txagent/txagent.py

Browse files
Files changed (1) hide show
  1. src/txagent/txagent.py +17 -15
src/txagent/txagent.py CHANGED
@@ -826,12 +826,11 @@ Generate **one summarized sentence** about "function calls' responses" with nece
826
  history.extend(current_gradio_history)
827
  if special_tool_call == 'Finish':
828
  next_round = False
829
- conversation.extend(function_call_messages)
830
- if function_call_messages and len(function_call_messages) > 0:
831
  return function_call_messages[0]['content']
832
  else:
833
- print("[⚠️ Warning] function_call_messages is empty")
834
- return "An internal reasoning error occurred — no tool response was returned."
835
  elif special_tool_call == 'RequireClarification' or special_tool_call == 'DirectResponse':
836
  history.append(
837
  ChatMessage(role="assistant", content=history[-1].content))
@@ -874,9 +873,10 @@ Generate **one summarized sentence** about "function calls' responses" with nece
874
  if each.metadata is not None:
875
  each.metadata['status'] = 'done'
876
  if '[FinalAnswer]' in last_thought:
877
- _, final_answer = last_thought.split('[FinalAnswer]', 1)
 
878
  history.append(
879
- ChatMessage(role="assistant", content=final_answer.strip())
880
  )
881
  yield history
882
  return
@@ -894,10 +894,11 @@ Generate **one summarized sentence** about "function calls' responses" with nece
894
  for each in history:
895
  if each.metadata is not None:
896
  each.metadata['status'] = 'done'
897
- if '[FinalAnswer]' in last_thought:
898
- _, final_answer = last_thought.split('[FinalAnswer]', 1)
 
899
  history.append(
900
- ChatMessage(role="assistant", content=final_answer.strip())
901
  )
902
  yield history
903
  else:
@@ -914,14 +915,15 @@ Generate **one summarized sentence** about "function calls' responses" with nece
914
  for each in history:
915
  if each.metadata is not None:
916
  each.metadata['status'] = 'done'
917
- if '[FinalAnswer]' in last_thought or '"name": "Finish",' in last_outputs_str:
918
- if '[FinalAnswer]' in last_thought:
919
- _, final_answer = last_thought.split('[FinalAnswer]', 1)
 
920
  else:
921
- final_answer = last_thought
922
  history.append(
923
- ChatMessage(role="assistant", content=final_answer.strip())
924
  )
925
  yield history
926
  else:
927
- return None
 
826
  history.extend(current_gradio_history)
827
  if special_tool_call == 'Finish':
828
  next_round = False
829
+ if function_call_messages:
830
+ conversation.extend(function_call_messages)
831
  return function_call_messages[0]['content']
832
  else:
833
+ return "No final response was generated."
 
834
  elif special_tool_call == 'RequireClarification' or special_tool_call == 'DirectResponse':
835
  history.append(
836
  ChatMessage(role="assistant", content=history[-1].content))
 
873
  if each.metadata is not None:
874
  each.metadata['status'] = 'done'
875
  if '[FinalAnswer]' in last_thought:
876
+ parts = last_thought.split('[FinalAnswer]', 1)
877
+ final_answer = parts[1].strip() if len(parts) > 1 else "No detailed final answer found."
878
  history.append(
879
+ ChatMessage(role="assistant", content=final_answer)
880
  )
881
  yield history
882
  return
 
894
  for each in history:
895
  if each.metadata is not None:
896
  each.metadata['status'] = 'done'
897
+ if '[FinalAnswer]' in last_outputs_str:
898
+ parts = last_outputs_str.split('[FinalAnswer]', 1)
899
+ final_answer = parts[1].strip() if len(parts) > 1 else "No final answer found."
900
  history.append(
901
+ ChatMessage(role="assistant", content=final_answer)
902
  )
903
  yield history
904
  else:
 
915
  for each in history:
916
  if each.metadata is not None:
917
  each.metadata['status'] = 'done'
918
+ if '[FinalAnswer]' in last_outputs_str or '"name": "Finish",' in last_outputs_str:
919
+ if '[FinalAnswer]' in last_outputs_str:
920
+ parts = last_outputs_str.split('[FinalAnswer]', 1)
921
+ final_answer = parts[1].strip() if len(parts) > 1 else "No final answer found."
922
  else:
923
+ final_answer = last_outputs_str
924
  history.append(
925
+ ChatMessage(role="assistant", content=final_answer)
926
  )
927
  yield history
928
  else:
929
+ yield [{"role": "assistant", "content": f"⚠️ An error occurred: {e}"}]