remove:emoji插件,修复tool被截断的问题
This commit is contained in:
@@ -28,7 +28,7 @@ from src.llm_models.payload_content.tool_option import ToolCall, ToolDefinitionI
|
||||
from src.services.llm_service import LLMServiceClient
|
||||
|
||||
from .builtin_tools import get_builtin_tools
|
||||
from .context_messages import AssistantMessage, LLMContextMessage, SessionBackedMessage
|
||||
from .context_messages import AssistantMessage, LLMContextMessage, SessionBackedMessage, ToolResultMessage
|
||||
from .message_adapter import format_speaker_content
|
||||
from .prompt_cli_renderer import PromptCLIVisualizer
|
||||
|
||||
@@ -609,6 +609,7 @@ class MaisakaChatLoopService:
|
||||
|
||||
selected_indices.reverse()
|
||||
selected_history = [chat_history[index] for index in selected_indices]
|
||||
selected_history = MaisakaChatLoopService._drop_leading_orphan_tool_results(selected_history)
|
||||
return (
|
||||
selected_history,
|
||||
(
|
||||
@@ -617,6 +618,36 @@ class MaisakaChatLoopService:
|
||||
),
|
||||
)
|
||||
|
||||
@staticmethod
|
||||
def _drop_leading_orphan_tool_results(
|
||||
selected_history: List[LLMContextMessage],
|
||||
) -> List[LLMContextMessage]:
|
||||
"""移除窗口前缀中缺少对应 tool_call 的工具结果消息。"""
|
||||
|
||||
if not selected_history:
|
||||
return selected_history
|
||||
|
||||
available_tool_call_ids = {
|
||||
tool_call.call_id
|
||||
for message in selected_history
|
||||
if isinstance(message, AssistantMessage)
|
||||
for tool_call in message.tool_calls
|
||||
if tool_call.call_id
|
||||
}
|
||||
|
||||
first_valid_index = 0
|
||||
while first_valid_index < len(selected_history):
|
||||
message = selected_history[first_valid_index]
|
||||
if not isinstance(message, ToolResultMessage):
|
||||
break
|
||||
if message.tool_call_id in available_tool_call_ids:
|
||||
break
|
||||
first_valid_index += 1
|
||||
|
||||
if first_valid_index == 0:
|
||||
return selected_history
|
||||
return selected_history[first_valid_index:]
|
||||
|
||||
@staticmethod
|
||||
def build_chat_context(user_text: str) -> List[LLMContextMessage]:
|
||||
"""根据用户输入构造最小对话上下文。
|
||||
|
||||
Reference in New Issue
Block a user