Update src/txagent/txagent.py
Browse files- src/txagent/txagent.py +15 -12
src/txagent/txagent.py
CHANGED
@@ -14,8 +14,9 @@ from .toolrag import ToolRAGModel
|
|
14 |
import torch
|
15 |
import logging
|
16 |
|
17 |
-
|
18 |
-
logging.basicConfig(level=logging.INFO)
|
|
|
19 |
|
20 |
from .utils import NoRepeatSentenceProcessor, ReasoningTraceChecker, tool_result_format
|
21 |
|
@@ -404,16 +405,8 @@ class TxAgent:
|
|
404 |
return None
|
405 |
|
406 |
def build_logits_processor(self, messages, llm):
|
407 |
-
# Disabled logits processor due to vLLM V1 limitation
|
408 |
logger.warning("Logits processor disabled due to vLLM V1 limitation")
|
409 |
return None
|
410 |
-
# Original code (commented out):
|
411 |
-
# tokenizer = llm.get_tokenizer()
|
412 |
-
# if self.avoid_repeat and len(messages) > 2:
|
413 |
-
# assistant_messages = [msg['content'] for msg in messages[-3:] if msg['role'] == 'assistant'][:2]
|
414 |
-
# forbidden_ids = [tokenizer.encode(msg, add_special_tokens=False) for msg in assistant_messages]
|
415 |
-
# return [NoRepeatSentenceProcessor(forbidden_ids, 5)]
|
416 |
-
# return None
|
417 |
|
418 |
def llm_infer(self, messages, temperature=0.1, tools=None,
|
419 |
output_begin_string=None, max_new_tokens=512,
|
@@ -656,7 +649,10 @@ Summarize the function calls' responses in one sentence with all necessary infor
|
|
656 |
yield history
|
657 |
next_round = False
|
658 |
conversation.extend(function_call_messages)
|
659 |
-
|
|
|
|
|
|
|
660 |
|
661 |
elif special_tool_call in ['RequireClarification', 'DirectResponse']:
|
662 |
last_msg = history[-1] if history else ChatMessage(role="assistant", content="Response needed.")
|
@@ -717,6 +713,8 @@ Summarize the function calls' responses in one sentence with all necessary infor
|
|
717 |
history.append(ChatMessage(role="assistant", content="**🧠 Final Analysis:**\n" + final_answer.strip()))
|
718 |
logger.info("Final answer provided: %s", final_answer[:100])
|
719 |
yield history
|
|
|
|
|
720 |
else:
|
721 |
history.append(ChatMessage(role="assistant", content=last_thought))
|
722 |
yield history
|
@@ -734,8 +732,12 @@ Summarize the function calls' responses in one sentence with all necessary infor
|
|
734 |
history.append(ChatMessage(role="assistant", content="**🧠 Final Analysis:**\n" + final_answer.strip()))
|
735 |
logger.info("Forced final answer: %s", final_answer[:100])
|
736 |
yield history
|
|
|
737 |
else:
|
738 |
-
|
|
|
|
|
|
|
739 |
|
740 |
except Exception as e:
|
741 |
logger.error("Exception in run_gradio_chat: %s", e, exc_info=True)
|
@@ -752,4 +754,5 @@ Summarize the function calls' responses in one sentence with all necessary infor
|
|
752 |
history.append(ChatMessage(role="assistant", content="**🧠 Final Analysis:**\n" + final_answer.strip()))
|
753 |
logger.info("Forced final answer after error: %s", final_answer[:100])
|
754 |
yield history
|
|
|
755 |
return error_msg
|
|
|
14 |
import torch
|
15 |
import logging
|
16 |
|
17 |
+
# Configure logging with a more specific logger name
|
18 |
+
logging.basicConfig(level=logging.INFO, format='%(asctime)s - %(name)s - %(levelname)s - %(message)s')
|
19 |
+
logger = logging.getLogger("TxAgent")
|
20 |
|
21 |
from .utils import NoRepeatSentenceProcessor, ReasoningTraceChecker, tool_result_format
|
22 |
|
|
|
405 |
return None
|
406 |
|
407 |
def build_logits_processor(self, messages, llm):
|
|
|
408 |
logger.warning("Logits processor disabled due to vLLM V1 limitation")
|
409 |
return None
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
410 |
|
411 |
def llm_infer(self, messages, temperature=0.1, tools=None,
|
412 |
output_begin_string=None, max_new_tokens=512,
|
|
|
649 |
yield history
|
650 |
next_round = False
|
651 |
conversation.extend(function_call_messages)
|
652 |
+
content = function_call_messages[0]['content']
|
653 |
+
if content:
|
654 |
+
return content
|
655 |
+
return "No content returned after Finish tool call."
|
656 |
|
657 |
elif special_tool_call in ['RequireClarification', 'DirectResponse']:
|
658 |
last_msg = history[-1] if history else ChatMessage(role="assistant", content="Response needed.")
|
|
|
713 |
history.append(ChatMessage(role="assistant", content="**🧠 Final Analysis:**\n" + final_answer.strip()))
|
714 |
logger.info("Final answer provided: %s", final_answer[:100])
|
715 |
yield history
|
716 |
+
next_round = False # Ensure we exit after final answer
|
717 |
+
return final_answer
|
718 |
else:
|
719 |
history.append(ChatMessage(role="assistant", content=last_thought))
|
720 |
yield history
|
|
|
732 |
history.append(ChatMessage(role="assistant", content="**🧠 Final Analysis:**\n" + final_answer.strip()))
|
733 |
logger.info("Forced final answer: %s", final_answer[:100])
|
734 |
yield history
|
735 |
+
return final_answer
|
736 |
else:
|
737 |
+
error_msg = "Reasoning rounds exceeded limit."
|
738 |
+
history.append(ChatMessage(role="assistant", content=error_msg))
|
739 |
+
yield history
|
740 |
+
return error_msg
|
741 |
|
742 |
except Exception as e:
|
743 |
logger.error("Exception in run_gradio_chat: %s", e, exc_info=True)
|
|
|
754 |
history.append(ChatMessage(role="assistant", content="**🧠 Final Analysis:**\n" + final_answer.strip()))
|
755 |
logger.info("Forced final answer after error: %s", final_answer[:100])
|
756 |
yield history
|
757 |
+
return final_answer
|
758 |
return error_msg
|