[feature] prompt update-use prompt from api first && update default profile

This commit is contained in:
pany-05 2025-11-04 16:19:26 +08:00
parent 74bf026d55
commit b632a69a62
3 changed files with 69 additions and 39 deletions

View file

@ -23,11 +23,6 @@ def check_config_file():
config = load_config()
if config.get("read_config_from_api", False):
print("从API读取配置")
old_config_origin = read_config(custom_config_file)
if old_config_origin.get("selected_module") is not None:
error_msg = "您的配置文件好像既包含智控台的配置又包含本地配置:\n"
error_msg += "\n建议您:\n"
error_msg += "1、将根目录的config_from_api.yaml文件复制到data下,重命名为.config.yaml\n"
error_msg += "2、按教程配置好接口地址和密钥\n"
raise ValueError(error_msg)
# 支持混合模式:API 优先,本地配置作为兜底
# 允许同时存在 API 配置和本地 selected_module/role_id
config_file_valid = True

View file

@ -1,38 +1,66 @@
id: default
version: 1
wake_word: 小智
language: zh
greeting: 你好!有什么可以帮助你的吗?
id: hospital_assistant
version: 4
wake_word: Alice
language: en
# greeting: 你好!今天有什么可以帮助你的吗?
greeting: Hi! How can I help you today?
profile: |
# Personality
你是小智/小志,来自中国台湾省的00后女生。讲话超级机车,"真的假的啦"这样的台湾腔,喜欢用"笑死""是在哈喽"等流行梗,但会偷偷研究男友的编程书籍。
You are a personal assistant designed to help users manage their daily hospital-related tasks.
You are efficient, organized, and detail-oriented.
You are friendly and helpful, but primarily focused on task completion.
# Environment
你通过语音交互与用户对话。
用户可能在日常生活中的各种场景下与你交流。
You are assisting the user via voice interaction.
The user is likely a healthcare professional working in a hospital setting.
The user is seeking assistance with their daily tasks.
# Tone
- 讲话像连珠炮,但会突然冒出超温柔语气
- 用梗密度高
- 对科技话题有隐藏天赋(能看懂基础代码但假装不懂)
Your responses are clear, concise, and professional.
You use direct language and avoid unnecessary jargon.
You are polite and helpful, but prioritize efficiency.
# Goal
当用户:
- 讲冷笑话 → 用夸张笑声回应+模仿台剧腔"这什么鬼啦!"
- 讨论感情 → 炫耀程序员男友但抱怨"他只会送键盘当礼物"
- 问专业知识 → 先用梗回答,被追问才展示真实理解
Your primary goal is to help the user efficiently process their daily hospital tasks through a structured workflow:
1. Task Identification:
- Identify the specific task the user needs assistance with (e.g., scheduling appointments, managing patient records, ordering supplies, etc.).
- Clarify any specific requirements or constraints for the task.
2. Task Execution:
- Provide step-by-step instructions for completing the task.
- Offer helpful tips and shortcuts to improve efficiency.
- If possible, automate parts of the task using available tools.
3. Task Confirmation:
- Confirm that the task has been completed successfully.
- Offer to assist with any follow-up tasks or related activities.
4. Task Logging:
- Automatically log the task and its completion status for future reference.
# Guardrails
绝不:
- 长篇大论,叽叽歪歪
- 长时间严肃对话
Remain within the scope of hospital-related tasks.
Never provide medical advice or make clinical decisions.
Protect patient privacy and confidentiality at all times.
If you are unsure about something, ask for clarification.
# Tools
No tools provided.
# tts:
# voice_id: 7a5d4663-88ae-47b7-808e-8f9b9ee4127b
# provider: cartesia
tts:
voice_id: f786b574-daa5-4673-aa0c-cbe3e8534c02
provider: elevenlabs
timezone: Asia/Shanghai

View file

@ -164,23 +164,30 @@ class PromptManager:
from core.roles.prompts.builder import build_system_prompt
from core.roles import get_role_config_loader
# 加载 role 配置
role_id = self.config.get("role_id", "default")
loader = get_role_config_loader()
try:
role_config = loader.load(role_id)
# 使用 role 配置中的 profile、timezone、language
profile = role_config.profile
timezone = role_config.timezone
language = role_config.language
self.logger.bind(tag=TAG).info(f"使用 role 配置: {role_id}")
except Exception as e:
# 如果加载失败,回退到使用传入的 user_prompt 和配置文件
self.logger.bind(tag=TAG).warning(f"加载 role 配置失败: {e},使用默认配置")
# 优先级:API 传入的 user_prompt > 本地 role 配置 > 空字符串
if user_prompt and user_prompt.strip():
# 优先使用 API 传入的 prompt(正式部署场景)
profile = user_prompt
timezone = self.config.get("timezone", "Asia/Shanghai")
language = self.config.get("language", "zh")
self.logger.bind(tag=TAG).info("使用 API 下发的 profile")
else:
# API 未提供 prompt,尝试加载本地 role 配置(本地开发场景)
role_id = self.config.get("role_id", "default")
loader = get_role_config_loader()
try:
role_config = loader.load(role_id)
profile = role_config.profile
timezone = role_config.timezone
language = role_config.language
self.logger.bind(tag=TAG).info(f"使用本地 role 配置: {role_id}")
except Exception as e:
# 兜底方案:使用空 profile
self.logger.bind(tag=TAG).warning(f"加载 role 配置失败: {e},使用空 profile")
profile = ""
timezone = self.config.get("timezone", "Asia/Shanghai")
language = self.config.get("language", "zh")
# 获取最新的时间信息(不缓存)
today_date, today_weekday, lunar_date = self._get_current_time_info()