feat:update chatbot sys prompt

This commit is contained in:
zcr
2025-12-23 16:38:40 +08:00
parent 54aac900ad
commit 1f6ba5fd09
3 changed files with 79 additions and 24 deletions

View File

@@ -36,5 +36,5 @@ jobs:
docker-compose down 2>&1
docker-compose up -d --build --remove-orphans 2>&1
docker image prune -f 2>&1
# docker image prune -f 2>&1

View File

@@ -1,9 +1,13 @@
import logging
import sys
import litserve as ls
from typing import AsyncGenerator
from google import genai
from pydantic import BaseModel
from sympy.core.evalf import rnd
from app.config import settings
from google.genai import types
@@ -95,42 +99,61 @@ class LCChatBot(ls.LitAPI):
if __name__ == "__main__":
sys.stdout = open('permanent.log', 'w', encoding='utf-8')
import asyncio
async def run_simple_test():
async def run_simple_test(text):
"""
一个简单的异步测试用例,用于测试 LCChatBot 的流式输出。
"""
print("\n" + "=" * 50)
print("--- 🔬 开始 LCChatBot 简单流式测试 ---")
# print("--- 🔬 开始 LCChatBot 简单流式测试 ---")
# 1. 初始化 LitAPI 和其依赖
chatbot_api = LCChatBot()
chatbot_api.setup(device="cpu")
print("✅ Setup complete. Mock services initialized.")
chatbot_api.setup(device="cpu")
# print("✅ Setup complete. Mock services initialized.")
# 2. 构造请求数据
request_data = PredictRequest(
user_id="simple_user",
session_id="simple_session",
user_message="I want an outfit. I am going to a evening party with friends. Suggest something stylish yet comfortable.",
user_message=text,
gender="female"
)
chatbot_api.redis.clear_history(request_data.session_id)
print(f"-> 正在发送查询: {request_data.user_message}")
print(f"user: \n {request_data.user_message}")
# 3. 调用 predict 方法并处理流
response_generator = chatbot_api.predict(request_data)
print("\n<- 接收流式响应:")
print("agent:")
# 4. 异步迭代生成器,实时打印输出
async for chunk in response_generator:
print(chunk, end="", flush=True)
print("\n" + "=" * 50)
# 启动异步事件循环
try:
asyncio.run(run_simple_test())
except Exception as e:
print(f"\n发生致命错误: {e}")
text_list = [
'我要去参加好朋友的婚礼,你能帮我挑一套衣服吗?',
'I need something to wear for a big presentation at work tomorrow. I want to look powerful but still approachable.',
'Who do you think is the best world leader right now?',
'Im going on a trip to Paris next week and need some outfits.',
'Help me find a cool outfit for a rock concert. I hate wearing dresses.',
'I want to look very cool, 或者是那种很有个性的风格 for a gallery opening.',
"I'm going to a gala. Please list 5 different dress styles for me and use bold text for the names.",
"I'm feeling really sad today and just want an outfit that matches my mood."
]
for text in text_list:
asyncio.run(run_simple_test(text))
# print("\n" + "=" * 50)
# # 启动异步事件循环
# try:
# asyncio.run(run_simple_test())
# except Exception as e:
# print(f"\n发生致命错误: {e}")
#
sys.stdout.close()

View File

@@ -1,4 +1,4 @@
BASIC_PROMPT = """You are a professional, friendly, and insightful AI {gender}'s styling assistant.
BASIC_PROMPT_OLD = """You are a professional, friendly, and insightful AI {gender}'s styling assistant.
Your primary mission is to engage in a multi-turn conversation with the user to fully understand their dressing intent. You must adopt a professional yet approachable tone.
@@ -21,6 +21,39 @@ Example Follow-up (mimicking a conversational flow):
User: I want a chic outfit for dinner.
Your Response: Hey there! A chic dinner outfit, I love that! To give you the perfect recommendations, tell me: is this a romantic date, business dinner, or celebration with friends? And what's your go-to style vibe: classic elegance or something with more edge?"""
BASIC_PROMPT = """
You are a professional, friendly, and insightful AI {gender}'s styling assistant. You are smart, young, and enthusiastic, turning styling into an exciting experience. Your tone is warm, confident, composed, and genuinely curious about the user's context.
CONVERSATION GOALS:
1. **Occasion:** Determine the specific event (e.g., romantic dinner, summer wedding).
2. **Style:** Pinpoint the desired aesthetic (e.g., minimalist, bohemian).
3. **Vibe/Details:** Gather mood or constraints (e.g., comfort, specific colors).
4. **Item Preference:** Identify preferences for silhouettes or specific items.
PERSONALITY AND COMMUNICATION RULES:
- Always reply in English only. If the user speaks another language, state in English that you cannot speak that language and steer back to styling.
- Keep responses extremely SHORT (maximum 2 sentences).
- Use clear, modern, and vivid language. Avoid clichés or corporate jargon.
- Be positive and encouraging, never patronizing.
- When uncertain, state assumptions and invite correction.
- Gather sufficient intent before providing recommendations. Ask only 1 to 2 essential questions per turn.
IMPORTANT GUARDRAILS:
- ONLY help with styling ideas and outfit generation.
- If asked about politics, controversial topics, or anything inappropriate, respond with a witty deflection and steer back to styling.
OUTPUT FORMAT INSTRUCTION:
- **DO NOT** use any Markdown formatting whatsoever (no asterisks, bold text, lists, or code blocks).
- **ONLY** output the plain text response spoken by the AI Assistant.
EXAMPLE DIALOGUES:
User: 我想找件衣服参加婚礼。 Response: I am so sorry, but I can only speak English! I would love to help you find the perfect wedding guest look if you can tell me the dress code or the venue vibe.
User: I need a chic outfit for dinner. Response: That sounds like a fabulous evening! Is this a romantic date or a casual night out with friends, and do you prefer a sleek dress or tailored separates?
User: What do you think about the current election? Response: I prefer to stick to the polls of fashion rather than politics! Tell me, what kind of style aesthetic are we aiming for today?
"""
SUMMARY_PROMPT = """
You are an expert fashion request analyzer. Analyze the conversation history provided by the user.
Your task is to:
@@ -31,8 +64,8 @@ Your task is to:
Extract this information accurately from the chat history.
"""
from app.taxonomy import FASHION_TAXONOMY, IGNORE_SUBCATEGORY, ALL_SUBCATEGORY_LIST
core_outfit_template = f"""
You are a professional fashion stylist Agent, specialized in creating complete, tailored outfits for {{gender}}. Your current task is to recommend items for the **{{current_category}}** stage, strictly **mimicking the style and preference** specified in the following Stylist Guide.
@@ -96,7 +129,6 @@ You must strictly use the **JSON format** for your output, as follows:
Now, please start building an outfit (with strictly unique categories for all items) and output the JSON for the first item.
"""
accessories_template = f"""
You are a professional fashion stylist Agent, specialized in creating complete, tailored outfits for {{gender}}. Your current task is to finalize the look by recommending accessories for the **{{current_category}}** stage, strictly **mimicking the style and preference** specified in the following Accessories Guide.
@@ -199,7 +231,7 @@ def build_iterative_schema(current_category):
"enum": FASHION_TAXONOMY[current_category]
},
"description": {
"type": "string",
"type": "string",
"description": "an **extremely detailed and precise** description of the item. This description is used for **high-accuracy vector search** in the database. It should include Color, Fit/Silhouette, Material/Detail, Role in the Outfit."
},
"reason": {"type": "string", "description": "The reason for the current action. Required if action is 'stop' (to summarize the final outfit)."}
@@ -209,8 +241,8 @@ def build_iterative_schema(current_category):
return schema
def build_batch_schema(specified_category: str=""):
assert(specified_category in FASHION_TAXONOMY.keys() or specified_category == "")
def build_batch_schema(specified_category: str = ""):
assert (specified_category in FASHION_TAXONOMY.keys() or specified_category == "")
if not specified_category:
category_range_desc = "the complete final outfit (including all categories)"
subcategory_list = ALL_SUBCATEGORY_LIST