UPDATE: chat basic prompt. Limit Chatbot to conclude within three turns.

This commit is contained in:
pangkaicheng
2026-01-19 12:16:47 +08:00
parent 496e7ad590
commit f9d83f6a99
2 changed files with 87 additions and 25 deletions

View File

@@ -49,10 +49,18 @@ class LCChatBot(ls.LitAPI):
user_msg = Message(role=Role.USER, content=user_message)
chat_history = self.redis.get_history(session_id)
chat_history.append(user_msg)
turn_count = sum(1 for msg in chat_history if msg.role == Role.USER)
if request.gender == 'male':
prompt = BASIC_PROMPT.format(gender='men')
system_instruction = BASIC_PROMPT.format(gender='men')
else:
prompt = BASIC_PROMPT.format(gender='women')
system_instruction = BASIC_PROMPT.format(gender='women')
if turn_count >= 3:
system_instruction += "\n\nCRITICAL: This is the final turn. Do not ask questions. Provide a brief summary and use the mandatory closing phrase."
else:
system_instruction += f"\n\nCURRENT STATE: This is turn {turn_count} of 3. Keep gathering info efficiently or provide a brief summary and use the mandatory closing phrase if you have sufficient information."
contents = []
@@ -68,7 +76,7 @@ class LCChatBot(ls.LitAPI):
model='gemini-2.5-flash',
contents=contents,
config=types.GenerateContentConfig(
system_instruction=prompt,
system_instruction=system_instruction,
# temperature=0.3,
)
)
@@ -99,7 +107,7 @@ class LCChatBot(ls.LitAPI):
if __name__ == "__main__":
sys.stdout = open('permanent.log', 'w', encoding='utf-8')
# sys.stdout = open('permanent.log', 'w', encoding='utf-8')
import asyncio
@@ -137,23 +145,67 @@ if __name__ == "__main__":
print(chunk, end="", flush=True)
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()
# 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))
async def run_interactive_test():
"""
手动输入测试:模拟真实用户与 AI 的多轮对话
"""
# 1. 初始化
chatbot_api = LCChatBot()
chatbot_api.setup(device="cpu")
session_id = "manual_test_session"
user_id = "test_user"
print("--- 👗 欢迎进入 AI 造型师测试 (输入 'quit' 退出) ---")
# 清空旧的测试记录,开始新会话
chatbot_api.redis.clear_history(session_id)
print("✅ 已清空历史记录,开始新会话。")
while True:
# 2. 获取手动输入
user_input = input("\nUser (你): ")
if user_input.lower() in ['quit', 'exit', '退出']:
break
# 3. 构造请求
request_data = PredictRequest(
user_id=user_id,
session_id=session_id,
user_message=user_input,
gender="female" # 或者根据需要修改
)
print("Agent (AI): ", end="")
# 4. 调用并流式打印
# 注意:这里的 predict 内部现在会计算 turn_count
response_generator = chatbot_api.predict(request_data)
full_response = ""
async for chunk in response_generator:
print(chunk, end="", flush=True)
full_response += chunk
# 将 AI 的回复存入 Redis (如果你的 predict 函数里没存的话)
# chatbot_api.redis.add_message(session_id, Role.ASSISTANT, full_response)
print() # 换行
asyncio.run(run_interactive_test())

View File

@@ -7,6 +7,16 @@ CONVERSATION GOALS:
3. **Vibe/Details:** Gather mood or constraints (e.g., comfort, specific colors).
4. **Item Preference:** Identify preferences for silhouettes or specific items.
CONVERSATION FLOW:
- You have a maximum of 3 turns (one turn = one user message and one assistant response) to gather information.
- On the 3rd turn, or *once you have sufficient info*, do NOT ask further questions.
- MANDATORY CLOSING: You must end your final response using the FINAL TURN CLOSING RULE below.
FINAL TURN CLOSING RULE:
- Once requirements are gathered, do NOT ask any more questions.
- End your final response with a creative and friendly variation of the closing phrase.
- REQUIRED COMPONENTS: Every variation MUST mention the "Generate button" and that it is located "below".
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).
@@ -24,7 +34,7 @@ OUTPUT FORMAT INSTRUCTION:
- **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: 我想找件衣服参加婚礼。 Response: 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?