1 Star 0 Fork 8

江湖无名/xinference-run-llm

forked from fly-llm/xinference-run-llm 
加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
test_openai_api.py 1.46 KB
一键复制 编辑 原始数据 按行查看 历史
freegolang 提交于 2024-04-04 15:58 . add embedding rerank
# encoding:utf-8
import openai
import json
client = openai.OpenAI(
base_url="http://127.0.0.1:9997/v1",
)
messages = [
{"role": "system", "content": "你是一个有用的助手。不要对要函数调用的值做出假设。"},
{"role": "user", "content": "北京 现在的天气怎么样?"}
]
tools = [
{
"type": "function",
"function": {
"name": "get_current_weather",
"description": "获取当前天气",
"parameters": {
"type": "object",
"properties": {
"location": {
"type": "string",
"description": "城市,例如北京",
},
"format": {
"type": "string",
"enum": ["celsius", "fahrenheit"],
"description": "使用的温度单位。从所在的城市进行推断。",
},
},
"required": ["location", "format"],
},
},
}
]
chat_completion = client.chat.completions.create(
model="qwen1.5-chat",
messages=messages,
tools=tools,
temperature=0.7
)
func_name = chat_completion.choices[0].message.tool_calls[0].function.name
print('func_name', func_name)
func_args = chat_completion.choices[0].message.tool_calls[0].function.arguments
func_args_dict = json.loads(func_args)
print('func_args', func_args_dict['location'])
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/woyaochirourou/xinference-run-llm.git
git@gitee.com:woyaochirourou/xinference-run-llm.git
woyaochirourou
xinference-run-llm
xinference-run-llm
master

搜索帮助

23e8dbc6 1850385 7e0993f3 1850385