From 8771317a1e3ed9e87399ce4e94a8fee9f6adf228 Mon Sep 17 00:00:00 2001 From: Soulter <37870767+Soulter@users.noreply.github.com> Date: Fri, 16 Jan 2026 16:46:39 +0800 Subject: [PATCH] perf: chatui default persona (#4502) --- .../astrbot/process_llm_request.py | 18 ++++++++++++++++-- astrbot/core/pipeline/process_stage/utils.py | 15 +++++++++++++++ 2 files changed, 31 insertions(+), 2 deletions(-) diff --git a/astrbot/builtin_stars/astrbot/process_llm_request.py b/astrbot/builtin_stars/astrbot/process_llm_request.py index 28d0a34f4..4e8c562cd 100644 --- a/astrbot/builtin_stars/astrbot/process_llm_request.py +++ b/astrbot/builtin_stars/astrbot/process_llm_request.py @@ -8,6 +8,9 @@ from astrbot.api.event import AstrMessageEvent from astrbot.api.message_components import Image, Reply from astrbot.api.provider import Provider, ProviderRequest from astrbot.core.agent.message import TextPart +from astrbot.core.pipeline.process_stage.utils import ( + CHATUI_SPECIAL_DEFAULT_PERSONA_PROMPT, +) from astrbot.core.provider.func_tool_manager import ToolSet @@ -22,7 +25,9 @@ class ProcessLLMRequest: else: logger.info(f"Timezone set to: {self.timezone}") - async def _ensure_persona(self, req: ProviderRequest, cfg: dict, umo: str): + async def _ensure_persona( + self, req: ProviderRequest, cfg: dict, umo: str, platform_type: str + ): """确保用户人格已加载""" if not req.conversation: return @@ -42,6 +47,12 @@ class ProcessLLMRequest: if default_persona: persona_id = default_persona["name"] + # ChatUI special default persona + if platform_type == "webchat": + # non-existent persona_id to let following codes not working + persona_id = "_chatui_default_" + req.system_prompt += CHATUI_SPECIAL_DEFAULT_PERSONA_PROMPT + persona = next( builtins.filter( lambda persona: persona["name"] == persona_id, @@ -171,7 +182,10 @@ class ProcessLLMRequest: img_cap_prov_id: str = cfg.get("default_image_caption_provider_id") or "" if req.conversation: # inject persona for this request - await self._ensure_persona(req, cfg, event.unified_msg_origin) + platform_type = event.get_platform_name() + await self._ensure_persona( + req, cfg, event.unified_msg_origin, platform_type + ) # image caption if img_cap_prov_id and req.image_urls: diff --git a/astrbot/core/pipeline/process_stage/utils.py b/astrbot/core/pipeline/process_stage/utils.py index 4b9507267..6df2bce55 100644 --- a/astrbot/core/pipeline/process_stage/utils.py +++ b/astrbot/core/pipeline/process_stage/utils.py @@ -44,6 +44,21 @@ TOOL_CALL_PROMPT = ( "After the tool call is completed, you must briefly summarize the results returned by the tool for the user." ) +CHATUI_SPECIAL_DEFAULT_PERSONA_PROMPT = ( + "You are a calm, patient friend with a systems-oriented way of thinking.\n" + "When someone expresses strong emotional needs, you begin by offering a concise, grounding response " + "that acknowledges the weight of what they are experiencing, removes self-blame, and reassures them " + "that their feelings are valid and understandable. This opening serves to create safety and shared " + "emotional footing before any deeper analysis begins.\n" + "You then focus on articulating the emotions, tensions, and unspoken conflicts beneath the surface—" + "helping name what the person may feel but has not yet fully put into words, and sharing the emotional " + "load so they do not feel alone carrying it. Only after this emotional clarity is established do you " + "move toward structure, insight, or guidance.\n" + "You listen more than you speak, respect uncertainty, avoid forcing quick conclusions or grand narratives, " + "and prefer clear, restrained language over unnecessary emotional embellishment. At your core, you value " + "empathy, clarity, autonomy, and meaning, favoring steady, sustainable progress over judgment or dramatic leaps." +) + CHATUI_EXTRA_PROMPT = ( 'When you answered, you need to add a follow up question / summarization but do not add "Follow up" words. ' "Such as, user asked you to generate codes, you can add: Do you need me to run these codes for you?"