update:function call最优设置成doubao-pro-32k-functioncall-241028

This commit is contained in:
hrz 2025-03-09 21:26:13 +08:00
parent 63b326b01c
commit d789c7f393
3 changed files with 31 additions and 26 deletions

View file

@ -73,8 +73,9 @@ selected_module:
# TTS将根据配置名称对应的type调用实际的TTS适配器 # TTS将根据配置名称对应的type调用实际的TTS适配器
TTS: EdgeTTS TTS: EdgeTTS
# 记忆模块,默认使用本地压缩记忆,如果想使用超长记忆,推荐使用mem0ai # 记忆模块,默认使用本地压缩记忆,如果想使用超长记忆,推荐使用mem0ai
Memory: mem_local_short Memory: nomem
# 意图识别模块,默认不开启。开启后,可以播放音乐、控制音量、识别退出指令 # 意图识别模块,默认不开启。开启后,可以播放音乐、控制音量、识别退出指令
# 如果意图识别设置成 function_call,建议使用:DoubaoLLM,推荐把的model_name设置为:doubao-pro-32k-functioncall-241028
Intent: nointent Intent: nointent
# 意图识别,是用于理解用户意图的模块,例如:播放音乐 # 意图识别,是用于理解用户意图的模块,例如:播放音乐
@ -86,7 +87,6 @@ Intent:
intent_llm: intent_llm:
type: intent_llm type: intent_llm
# 意图识别使用function_call,缺点:需要所选择的LLM支持function_call,优点:按需调用工具、速度快 # 意图识别使用function_call,缺点:需要所选择的LLM支持function_call,优点:按需调用工具、速度快
# 新手使用function_call,建议使用:AliLLM,并把的model_name设置为:qwen-max
function_call: function_call:
type: function_call type: function_call
@ -129,6 +129,13 @@ LLM:
base_url: https://dashscope.aliyuncs.com/compatible-mode/v1 base_url: https://dashscope.aliyuncs.com/compatible-mode/v1
model_name: qwen-turbo model_name: qwen-turbo
api_key: 你的deepseek web key api_key: 你的deepseek web key
DoubaoLLM:
# 定义LLM API类型
type: openai
# 可在这里开通 https://console.volcengine.com/ark/region:ark+cn-beijing/model/detail?Id=doubao-pro-32k&projectName=undefined
base_url: https://ark.cn-beijing.volces.com/api/v3
model_name: doubao-pro-32k-functioncall-241028
api_key: 你的doubao web key
DeepSeekLLM: DeepSeekLLM:
# 定义LLM API类型 # 定义LLM API类型
type: openai type: openai

View file

@ -90,14 +90,13 @@ class ConnectionHandler:
self.auth_code_gen = AuthCodeGenerator.get_instance() self.auth_code_gen = AuthCodeGenerator.get_instance()
self.is_device_verified = False # 添加设备验证状态标志 self.is_device_verified = False # 添加设备验证状态标志
self.music_handler = _music self.music_handler = _music
self.close_after_chat = False # 是否在聊天结束后关闭连接 self.close_after_chat = False # 是否在聊天结束后关闭连接
self.use_function_call_mode = False self.use_function_call_mode = False
if self.config["selected_module"]["Intent"] == 'function_call': if self.config["selected_module"]["Intent"] == 'function_call':
self.use_function_call_mode = True self.use_function_call_mode = True
self.logger.bind(tag=TAG).info(f"use_function_call_mode:{self.use_function_call_mode}") self.logger.bind(tag=TAG).info(f"use_function_call_mode:{self.use_function_call_mode}")
async def handle_connection(self, ws): async def handle_connection(self, ws):
try: try:
# 获取并验证headers # 获取并验证headers
@ -214,7 +213,6 @@ class ConnectionHandler:
return False return False
return not self.is_device_verified return not self.is_device_verified
def chat(self, query): def chat(self, query):
if self.isNeedAuth(): if self.isNeedAuth():
self.llm_finish_task = True self.llm_finish_task = True
@ -256,7 +254,7 @@ class ConnectionHandler:
current_text = full_text[processed_chars:] # 从未处理的位置开始 current_text = full_text[processed_chars:] # 从未处理的位置开始
# 查找最后一个有效标点 # 查找最后一个有效标点
punctuations = ("。", "?", "!", "?", "!", ";", ";", ":", ":") punctuations = ("。", "?", "!", ";", ":")
last_punct_pos = -1 last_punct_pos = -1
for punct in punctuations: for punct in punctuations:
pos = current_text.rfind(punct) pos = current_text.rfind(punct)
@ -318,7 +316,7 @@ class ConnectionHandler:
future = asyncio.run_coroutine_threadsafe(self.memory.query_memory(query), self.loop) future = asyncio.run_coroutine_threadsafe(self.memory.query_memory(query), self.loop)
memory_str = future.result() memory_str = future.result()
#self.logger.bind(tag=TAG).info(f"记忆内容: {memory_str}") # self.logger.bind(tag=TAG).info(f"记忆内容: {memory_str}")
# 使用支持functions的streaming接口 # 使用支持functions的streaming接口
llm_responses = self.llm.response_with_functions( llm_responses = self.llm.response_with_functions(
@ -351,7 +349,7 @@ class ConnectionHandler:
current_text = full_text[processed_chars:] # 从未处理的位置开始 current_text = full_text[processed_chars:] # 从未处理的位置开始
# 查找最后一个有效标点 # 查找最后一个有效标点
punctuations = ("。", "?", "!", "?", "!", ";", ";", ":", ":") punctuations = ("。", "?", "!", ";", ":")
last_punct_pos = -1 last_punct_pos = -1
for punct in punctuations: for punct in punctuations:
pos = current_text.rfind(punct) pos = current_text.rfind(punct)

View file

@ -79,7 +79,7 @@ class LLMProvider(LLMProviderBase):
} }
if current_function_call: if current_function_call:
logger.bind(tag=TAG).debug(f"ollama Function call detected: {current_function_call}") logger.bind(tag=TAG).debug(f"openai Function call detected: {current_function_call}")
yield {"type": "function_call", "function_call": current_function_call} yield {"type": "function_call", "function_call": current_function_call}
except Exception as e: except Exception as e: