feat: 可选启动系统时间提示
This commit is contained in:
@@ -26,6 +26,7 @@ DEFAULT_CONFIG = {
|
||||
"wake_prefix": "",
|
||||
"web_search": False,
|
||||
"identifier": False,
|
||||
"datetime_system_prompt": True,
|
||||
"default_personality": "如果用户寻求帮助或者打招呼,请告诉他可以用 /help 查看 AstrBot 帮助。",
|
||||
"prompt_prefix": ""
|
||||
},
|
||||
@@ -237,6 +238,9 @@ CONFIG_METADATA_2 = {
|
||||
"wake_prefix": {"description": "LLM 聊天额外唤醒前缀", "type": "string", "hint": "使用 LLM 聊天额外的触发条件。如填写 `chat`,则需要消息前缀加上 `/chat` 才能触发 LLM 聊天,是一个防止滥用的手段。"},
|
||||
"web_search": {"description": "启用网页搜索", "type": "bool", "hint": "能访问 Google 时效果最佳。如果 Google 访问失败,程序会依次访问 Bing, Sogo 搜索引擎。"},
|
||||
"identifier": {"description": "启动识别群员", "type": "bool", "hint": "在 Prompt 前加上群成员的名字以让模型更好地了解群聊状态。启用将略微增加 token 开销,"},
|
||||
"datetime_system_prompt": {"description": "启用日期时间系统提示", "type": "bool", "hint": "启用后,会在系统提示词中加上当前机器的日期时间。"},
|
||||
"default_personality": {"description": "默认人格", "type": "string", "hint": "默认人格(情境设置/System Prompt)文本。"},
|
||||
"prompt_prefix": {"description": "Prompt 前缀文本", "type": "string", "hint": "添加之后,会在每次对话的 Prompt 前加上此文本。"},
|
||||
}
|
||||
},
|
||||
"content_safety": {
|
||||
|
||||
@@ -13,7 +13,6 @@ from astrbot.core.star.star import star_map
|
||||
class LLMRequestSubStage(Stage):
|
||||
|
||||
async def initialize(self, ctx: PipelineContext) -> None:
|
||||
self.curr_provider = ctx.plugin_manager.context.get_using_provider()
|
||||
self.prompt_prefix = ctx.astrbot_config['provider_settings']['prompt_prefix']
|
||||
self.identifier = ctx.astrbot_config['provider_settings']['identifier']
|
||||
self.ctx = ctx
|
||||
@@ -35,14 +34,15 @@ class LLMRequestSubStage(Stage):
|
||||
|
||||
tools = self.ctx.plugin_manager.context.get_llm_tool_manager()
|
||||
|
||||
provider = self.ctx.plugin_manager.context.get_using_provider()
|
||||
try:
|
||||
llm_response = await self.curr_provider.text_chat(
|
||||
llm_response = await provider.text_chat(
|
||||
prompt=event.message_str,
|
||||
session_id=event.session_id,
|
||||
image_urls=image_urls,
|
||||
func_tool=tools
|
||||
)
|
||||
await Metric.upload(llm_tick=1, model_name=self.curr_provider.get_model(), provider_type=self.curr_provider.meta().type)
|
||||
await Metric.upload(llm_tick=1, model_name=provider.get_model(), provider_type=provider.meta().type)
|
||||
|
||||
if llm_response.role == 'assistant':
|
||||
# text completion
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import traceback
|
||||
import base64
|
||||
import json
|
||||
import datetime
|
||||
|
||||
from openai import AsyncOpenAI, NOT_GIVEN
|
||||
from openai.types.chat.chat_completion import ChatCompletion
|
||||
@@ -28,6 +29,7 @@ class ProviderOpenAIOfficial(Provider):
|
||||
self.chosen_api_key = None
|
||||
self.api_keys: List = provider_config.get("key", [])
|
||||
self.chosen_api_key = self.api_keys[0] if len(self.api_keys) > 0 else None
|
||||
self.enable_datetime = provider_config.get("datetime_system_prompt", True)
|
||||
|
||||
self.client = AsyncOpenAI(
|
||||
api_key=self.chosen_api_key,
|
||||
@@ -136,15 +138,19 @@ class ProviderOpenAIOfficial(Provider):
|
||||
new_record = await self.assemble_context(prompt, image_urls)
|
||||
|
||||
context_query = []
|
||||
|
||||
if not contexts:
|
||||
context_query = [*self.session_memory[session_id], new_record]
|
||||
system_prompt = ""
|
||||
if self.curr_personality["prompt"]:
|
||||
context_query.insert(0, {"role": "system", "content": self.curr_personality["prompt"]})
|
||||
system_prompt = self.curr_personality["prompt"]
|
||||
if self.enable_datetime:
|
||||
system_prompt += f"Current datetime: {datetime.datetime.now().strftime('%Y-%m-%d %H:%M')}"
|
||||
if system_prompt:
|
||||
context_query.insert(0, {"role": "system", "content": system_prompt})
|
||||
else:
|
||||
context_query = contexts
|
||||
|
||||
logger.debug(f"请求上下文:{context_query}")
|
||||
logger.debug(f"请求上下文:{context_query}, {self.get_model()}")
|
||||
|
||||
payloads = {
|
||||
"messages": context_query,
|
||||
|
||||
Reference in New Issue
Block a user