Commit 9419c31

benny-dou <60535774+benny-dou@users.noreply.github.com>
2025-03-12 11:10:30
fix(gpt): fix tool response not showing
1 parent a7d83fc
Changed files (1)
src
llm
src/llm/gpt.py
@@ -5,7 +5,7 @@ from loguru import logger
 from pyrogram.client import Client
 from pyrogram.types import Message
 
-from config import GPT, PREFIX, cache
+from config import GPT, PREFIX, TEXT_LENGTH, cache
 from llm.contexts import get_conversation_contexts, get_conversations
 from llm.models import get_model_config_with_contexts, get_model_type
 from llm.response import send_to_gpt
@@ -15,7 +15,7 @@ from llm.utils import BOT_TIPS, llm_cleanup_files
 from messages.parser import parse_msg
 from messages.progress import modify_progress
 from messages.sender import send2tg
-from messages.utils import equal_prefix, startswith_prefix
+from messages.utils import count_without_entities, equal_prefix, startswith_prefix
 
 HELP = f"""🤖**GPT对话**
 `{PREFIX.GPT}` 命令当前模型:
@@ -111,7 +111,12 @@ async def gpt_response(client: Client, message: Message, *, gpt_stream: bool = G
     # skip send a new request if tool_model is the same as the current model
     if response and config["completions"]["model"] == GPT.TOOLS_MODEL and response.get("content"):
         texts = f"🤖**{response['model']}**: ({BOT_TIPS})\n\n{response['content']}"
-        await modify_progress(message=status_msg, del_status=True, **kwargs)
+        length = await count_without_entities(texts)
+        if length <= TEXT_LENGTH:
+            await modify_progress(message=status_msg, text=texts, force_update=True, **kwargs)
+        else:
+            await send2tg(client, message, texts=texts, **kwargs)
+            await modify_progress(message=status_msg, del_status=True, **kwargs)
         llm_cleanup_files(config["completions"]["messages"])
         return