代码拉取完成,页面将自动刷新
同步操作将从 fly-llm/xinference-run-llm 强制同步,此操作会覆盖自 Fork 仓库以来所做的任何修改,且无法恢复!!!
确定后同步将在后台操作,完成时将刷新页面,请耐心等待。
# encoding:utf-8
import openai
import json
import os
# 设置环境变量
os.environ['OPENAI_API_KEY']="123"
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="qwen2-instruct",
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'])
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。