main
HuangHai 3 months ago
parent 5bcda82b36
commit ec510889bb

@ -1,11 +1,12 @@
from config.logger import setup_logging from config.logger import setup_logging
from http import HTTPStatus from http import HTTPStatus
from dashscope import Application import dashscope
from core.providers.llm.base import LLMProviderBase from core.providers.llm.base import LLMProviderBase
TAG = __name__ TAG = __name__
logger = setup_logging() logger = setup_logging()
class LLMProvider(LLMProviderBase): class LLMProvider(LLMProviderBase):
def __init__(self, config): def __init__(self, config):
self.api_key = config["api_key"] self.api_key = config["api_key"]
@ -26,7 +27,8 @@ class LLMProvider(LLMProviderBase):
"api_key": self.api_key, "api_key": self.api_key,
"app_id": self.app_id, "app_id": self.app_id,
"session_id": session_id, "session_id": session_id,
"messages": dialogue "messages": dialogue,
"model" : "qwen-plus"
} }
if self.memory_id != False: if self.memory_id != False:
# 百练memory需要prompt参数 # 百练memory需要prompt参数
@ -35,7 +37,7 @@ class LLMProvider(LLMProviderBase):
call_params["prompt"] = prompt call_params["prompt"] = prompt
logger.bind(tag=TAG).debug(f"【阿里百练API服务】处理后的prompt: {prompt}") logger.bind(tag=TAG).debug(f"【阿里百练API服务】处理后的prompt: {prompt}")
responses = Application.call(**call_params) responses = dashscope.Generation.call(**call_params)
if responses.status_code != HTTPStatus.OK: if responses.status_code != HTTPStatus.OK:
logger.bind(tag=TAG).error( logger.bind(tag=TAG).error(
f"code={responses.status_code}, " f"code={responses.status_code}, "

@ -0,0 +1,14 @@
import dashscope
messages = [
{'role': 'system', 'content': 'You are a helpful assistant.'},
{'role': 'user', 'content': '你是谁?'}
]
response = dashscope.Generation.call(
# 若没有配置环境变量请用百炼API Key将下行替换为api_key="sk-xxx",
api_key='sk-01d13a39e09844038322108ecdbd1bbc',
model="qwen-plus", # 此处以qwen-plus为例可按需更换模型名称。模型列表https://help.aliyun.com/zh/model-studio/getting-started/models
messages=messages,
result_format='message'
)
print(response)

@ -250,8 +250,8 @@ config USE_AUDIO_PROCESSOR
config USE_REALTIME_CHAT config USE_REALTIME_CHAT
bool "启用可语音打断的实时对话模式(需要 AEC 支持)" bool "启用可语音打断的实时对话模式(需要 AEC 支持)"
default n default y
depends on USE_AUDIO_PROCESSOR && (BOARD_TYPE_ESP_BOX_3 || BOARD_TYPE_ESP_BOX || BOARD_TYPE_ESP_BOX_LITE || BOARD_TYPE_LICHUANG_DEV || BOARD_TYPE_ESP32S3_KORVO2_V3) depends on USE_AUDIO_PROCESSOR && (BOARD_TYPE_BREAD_COMPACT_WIFI || BOARD_TYPE_ESP_BOX_3 || BOARD_TYPE_ESP_BOX || BOARD_TYPE_ESP_BOX_LITE || BOARD_TYPE_LICHUANG_DEV || BOARD_TYPE_ESP32S3_KORVO2_V3)
help help
需要 ESP32 S3 与 AEC 开启,因为性能不够,不建议和微信聊天界面风格同时开启 需要 ESP32 S3 与 AEC 开启,因为性能不够,不建议和微信聊天界面风格同时开启

Loading…
Cancel
Save