|
@@ -3,6 +3,8 @@
|
|
# vim:fenc=utf-8
|
|
# vim:fenc=utf-8
|
|
|
|
|
|
import random
|
|
import random
|
|
|
|
+from typing import Dict, List
|
|
|
|
+
|
|
from openai import OpenAI
|
|
from openai import OpenAI
|
|
from datetime import datetime
|
|
from datetime import datetime
|
|
import chat_service
|
|
import chat_service
|
|
@@ -35,14 +37,14 @@ class ResponseTypeDetector:
|
|
)
|
|
)
|
|
self.model_name = chat_service.VOLCENGINE_MODEL_DOUBAO_PRO_1_5
|
|
self.model_name = chat_service.VOLCENGINE_MODEL_DOUBAO_PRO_1_5
|
|
|
|
|
|
- def detect_type(self, dialogue_history, next_message, enable_random=False):
|
|
|
|
|
|
+ def detect_type(self, dialogue_history: List[Dict], next_message: Dict, enable_random=False):
|
|
if configs.get().get('debug_flags', {}).get('disable_llm_api_call', False):
|
|
if configs.get().get('debug_flags', {}).get('disable_llm_api_call', False):
|
|
return MessageType.TEXT
|
|
return MessageType.TEXT
|
|
composed_dialogue = self.compose_dialogue(dialogue_history)
|
|
composed_dialogue = self.compose_dialogue(dialogue_history)
|
|
- next_message = DialogueManager.format_dialogue_content(next_message)
|
|
|
|
|
|
+ fmt_next_message = DialogueManager.format_dialogue_content(next_message)
|
|
prompt = prompt_templates.RESPONSE_TYPE_DETECT_PROMPT.format(
|
|
prompt = prompt_templates.RESPONSE_TYPE_DETECT_PROMPT.format(
|
|
dialogue_history=composed_dialogue,
|
|
dialogue_history=composed_dialogue,
|
|
- message=next_message
|
|
|
|
|
|
+ message=fmt_next_message
|
|
)
|
|
)
|
|
# logger.debug(prompt)
|
|
# logger.debug(prompt)
|
|
messages = [
|
|
messages = [
|
|
@@ -55,11 +57,12 @@ class ResponseTypeDetector:
|
|
if response == '语音':
|
|
if response == '语音':
|
|
return MessageType.VOICE
|
|
return MessageType.VOICE
|
|
if enable_random:
|
|
if enable_random:
|
|
- suitable_for_voice = self.if_message_suitable_for_voice(next_message)
|
|
|
|
- logger.debug(f"voice suitable[{suitable_for_voice}], message: {next_message}")
|
|
|
|
|
|
+ next_message_content = next_message['content']
|
|
|
|
+ suitable_for_voice = self.if_message_suitable_for_voice(next_message_content)
|
|
|
|
+ logger.debug(f"voice suitable[{suitable_for_voice}], message: {next_message_content}")
|
|
if suitable_for_voice:
|
|
if suitable_for_voice:
|
|
if random.random() < 0.2:
|
|
if random.random() < 0.2:
|
|
- logger.info(f"enable voice response randomly for message: {next_message}")
|
|
|
|
|
|
+ logger.info(f"enable voice response randomly for message: {next_message_content}")
|
|
return MessageType.VOICE
|
|
return MessageType.VOICE
|
|
return MessageType.TEXT
|
|
return MessageType.TEXT
|
|
|
|
|