|
@@ -1,11 +1,13 @@
|
|
|
#! /usr/bin/env python
|
|
|
# -*- coding: utf-8 -*-
|
|
|
# vim:fenc=utf-8
|
|
|
-
|
|
|
+import random
|
|
|
from enum import Enum, auto
|
|
|
from typing import Dict, List, Optional, Tuple, Any
|
|
|
from datetime import datetime
|
|
|
import time
|
|
|
+
|
|
|
+import prompt_templates
|
|
|
from logging_service import logger
|
|
|
|
|
|
import pymysql.cursors
|
|
@@ -572,6 +574,35 @@ class DialogueManager:
|
|
|
last_message_role, aggregated_message, ChatServiceType.COZE_CHAT))
|
|
|
return messages
|
|
|
|
|
|
+ def build_active_greeting_config(self):
|
|
|
+ # FIXME: 这里的抽象不好
|
|
|
+ chat_config = {'user_id': self.user_id}
|
|
|
+ prompt_context = self.get_prompt_context(None)
|
|
|
+
|
|
|
+ current_time = datetime.now().strftime('%Y-%m-%d %H:%M:%S')
|
|
|
+ system_message = {'role': 'system', 'content': 'You are a helpful AI assistant.'}
|
|
|
+ # TODO: 随机选择一个prompt 或 带策略选择 或根据用户标签选择
|
|
|
+ # TODO:需要区分用户是否有历史交互、是否发送过相似内容
|
|
|
+ greeting_prompts = [
|
|
|
+ prompt_templates.GREETING_WITH_IMAGE_GAME,
|
|
|
+ prompt_templates.GREETING_WITH_NAME_POETRY,
|
|
|
+ prompt_templates.GREETING_WITH_AVATAR_STORY
|
|
|
+ ]
|
|
|
+ selected_prompt = greeting_prompts[random.randint(0, len(greeting_prompts) - 1)]
|
|
|
+ prompt = selected_prompt.format(**prompt_context)
|
|
|
+ user_message = {'role': 'user', 'content': prompt}
|
|
|
+ messages = [system_message, user_message]
|
|
|
+ if selected_prompt == prompt_templates.GREETING_WITH_AVATAR_STORY:
|
|
|
+ messages.append({
|
|
|
+ "role": 'user',
|
|
|
+ "content": [
|
|
|
+ {"type": "image_url", "image_url": {"url": self.user_profile['avatar']}}
|
|
|
+ ]
|
|
|
+ })
|
|
|
+ chat_config['use_multimodal_model'] = True
|
|
|
+ chat_config['messages'] = messages
|
|
|
+ return chat_config
|
|
|
+
|
|
|
def build_chat_configuration(
|
|
|
self,
|
|
|
user_message: Optional[str] = None,
|