main
HuangHai 3 months ago
parent 5b23f1fb30
commit ccdc45baa3

@ -2,6 +2,7 @@ from config.logger import setup_logging
from http import HTTPStatus
import dashscope
from core.providers.llm.base import LLMProviderBase
from plugins_func.functions.get_weather import GET_WEATHER_FUNCTION_DESC
TAG = __name__
logger = setup_logging()
@ -36,6 +37,17 @@ class LLMProvider(LLMProviderBase):
call_params["prompt"] = prompt
logger.bind(tag=TAG).debug(f"【阿里百练API服务】处理后的prompt: {prompt}")
# 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=dialogue,
# result_format='message',
# tools=[GET_WEATHER_FUNCTION_DESC]
# )
# print(response)
responses = dashscope.Generation.call(**call_params)
if responses.status_code != HTTPStatus.OK:
logger.bind(tag=TAG).error(

@ -1,14 +1,42 @@
import dashscope
from pywin.framework.toolmenu import tools
messages = [
{'role': 'system', 'content': 'You are a helpful assistant.'},
{'role': 'user', 'content': '你是谁?'}
]
GET_WEATHER_FUNCTION_DESC = {
"type": "function",
"function": {
"name": "get_weather",
"description": (
"获取某个地点的天气,用户应提供一个位置,比如用户说杭州天气,参数为:杭州。"
"如果用户说的是省份,默认用省会城市。如果用户说的不是省份或城市而是一个地名,"
"默认用该地所在省份的省会城市。"
),
"parameters": {
"type": "object",
"properties": {
"location": {
"type": "string",
"description": "地点名,例如杭州。可选参数,如果不提供则不传"
},
"lang": {
"type": "string",
"description": "返回用户使用的语言code例如zh_CN/zh_HK/en_US/ja_JP等默认zh_CN"
}
},
"required": ["lang"]
}
}
}
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'
result_format='message',
tools=[GET_WEATHER_FUNCTION_DESC]
)
print(response)

Loading…
Cancel
Save