Views
No views yet
import requests,json
# 定义工具函数,Json列表格式,支持MCP协议规格
tools = [
{
"type": "function",
"function": {
"name": "get_current_weather",
"description": "获取指定城市的当前天气信息,包括温度、湿度、风速等数据。",
"parameters": {
"type": "object",
"properties": {
"location": {
"type": "string",
"description": "城市名称,例如:'北京'、'深圳'。支持中文或拼音输入。"
},
"date": {
"type": "string",
"description": "查询日期,格式为 YYYY-MM-DD(遵循 ISO 8601 标准)。例如:'2023-10-01'。"
}
},
"required": ["location", "date"],
"additionalProperties": False
}
}
}
]
messages = [
{"role": "system", "content": "你是华为公司开发的盘古模型。\n现在是2025年10月13日"}, # 自定义system prompt,不需要使用时置空
{"role": "user", "content": "深圳后天的天气如何?"}
]
headers = {'Content-Type': 'application/json'}
api_url = "xxxxxxxx"
payload = {
"model": "pangu_ultra_moe",
"messages": messages,
"tools": tools,
"chat_template_kwargs":{
"think": False, # 控制快慢思考,False快思考,默认True(慢思考)
"mcp_prompt": True # 控制是否使用默认的工具调用system prompt。默认True(使用)
}
}
api_response = requests.post(api_url, headers=headers, json=payload)
# 处理模型响应返回值
choice = api_response.json()["choices"][0]
reasoning_response = choice['message']['reasoning_content']
response = choice['message']['content']
tool_calls = choice['message']['tool_calls']