fix: 当群聊自动回复时,不会带上人格的Prompt #419

This commit is contained in:
Soulter
2025-02-08 10:17:43 +08:00
parent a8b2b09e0f
commit 96237abc03
5 changed files with 18 additions and 12 deletions
+3 -1
View File
@@ -69,7 +69,9 @@ DEFAULT_CONFIG = {
"internal_keywords": {"enable": True, "extra_keywords": []},
"baidu_aip": {"enable": False, "app_id": "", "api_key": "", "secret_key": ""},
},
"admins_id": [],
"admins_id": [
"astrbot"
],
"t2i": False,
"t2i_word_threshold": 150,
"http_proxy": "",
@@ -39,9 +39,8 @@ class ResultDecorateStage:
handlers = star_handlers_registry.get_handlers_by_event_type(EventType.OnDecoratingResultEvent)
for handler in handlers:
# TODO: 如何让这里的 handler 也能使用 LLM 能力。也许需要将 LLMRequestSubStage 提取出来。
await handler.handler(event)
if len(result.chain) > 0:
# 回复前缀
if self.reply_prefix:
+11 -7
View File
@@ -8,7 +8,7 @@ from typing import List, Union
from astrbot.core.message.components import Plain, Image, BaseMessageComponent, Face, At, AtAll, Forward
from astrbot.core.utils.metrics import Metric
from astrbot.core.provider.entites import ProviderRequest
from astrbot.core.db.po import Conversation
@dataclass
class MessageSesion:
@@ -305,9 +305,10 @@ class AstrMessageEvent(abc.ABC):
prompt: str,
func_tool_manager = None,
session_id: str = None,
image_urls: List[str] = None,
contexts: List = None,
system_prompt: str = ""
image_urls: List[str] = [],
contexts: List = [],
system_prompt: str = "",
conversation: Conversation = None
) -> ProviderRequest:
'''
创建一个 LLM 请求。
@@ -316,10 +317,12 @@ class AstrMessageEvent(abc.ABC):
```py
yield event.request_llm(prompt="hi")
```
prompt: 提示词
session_id: 已经过时,留空即可
image_urls: 可以是 base64:// 或者 http:// 开头的图片链接,也可以是本地图片路径。
contexts: 当指定 contexts 时,将会**只**使用 contexts 作为上下文。
contexts: 当指定 contexts 时,将会使用 contexts 作为上下文。
func_tool_manager: 函数工具管理器,用于调用函数工具。用 self.context.get_llm_tool_manager() 获取。
conversation: 可选。如果指定,将在指定的对话中进行 LLM 请求。对话的人格会被用于 LLM 请求,并且结果将会被记录到对话中。
'''
return ProviderRequest(
prompt = prompt,
@@ -327,5 +330,6 @@ class AstrMessageEvent(abc.ABC):
image_urls = image_urls,
func_tool = func_tool_manager,
contexts = contexts,
system_prompt = system_prompt
system_prompt = system_prompt,
conversation=conversation
)
@@ -111,7 +111,7 @@ class ProviderOpenAIOfficial(Provider):
self,
prompt: str,
session_id: str=None,
image_urls: List[str]=None,
image_urls: List[str]=[],
func_tool: FuncCall=None,
contexts=[],
system_prompt=None,
+2 -1
View File
@@ -649,7 +649,8 @@ UID: {user_id} 此 ID 可用于设置管理员。/op <UID> 授权管理员, /deo
prompt=prompt,
func_tool_manager=self.context.get_llm_tool_manager(),
session_id=event.session_id,
contexts=history if history else []
contexts=history if history else [],
conversation=conv,
)
except BaseException as e:
logger.error(f"主动回复失败: {e}")