one-api是否支持MCP
·
本地环境
Ollama(qwen2.5:0.5b)
虚拟机docker运行one-api(justsong/one-api:lastest, One API v0.6.11-preview.7), 其上配置了Ollama的渠道
直接调用Ollama
输入:
{
"model": "qwen2.5:0.5b",
"stream": false,
"options": {},
"messages": [
{
"role": "user",
"content": "what is the weather in California?"
}
],
"tools": [
{
"type": "function",
"function": {
"name": "add",
"description": "_summary_\n Add to numbers\n ",
"parameters": {
"type": "object",
"required": [
"a",
"b"
],
"properties": {
"a": {
"type": "integer"
},
"b": {
"type": "integer"
}
}
}
}
},
{
"type": "function",
"function": {
"name": "multiple",
"description": "Multiply two numbers",
"parameters": {
"type": "object",
"required": [
"a",
"b"
],
"properties": {
"a": {
"type": "integer"
},
"b": {
"type": "integer"
}
}
}
}
},
{
"type": "function",
"function": {
"name": "get_weather",
"description": "Get the weather location.",
"parameters": {
"type": "object",
"required": [
"location"
],
"properties": {
"location": {
"type": "string"
}
}
}
}
}
]
}
输出:
{
"id": "chatcmpl-264",
"object": "chat.completion",
"created": 1752653490,
"model": "qwen2.5:0.5b",
"system_fingerprint": "fp_ollama",
"choices": [
{
"index": 0,
"message": {
"role": "assistant",
"content": "",
"tool_calls": [
{
"id": "call_7ky45agp",
"index": 0,
"type": "function",
"function": {
"name": "get_weather",
"arguments": "{\"location\":\"California\"}"
}
}
]
},
"finish_reason": "tool_calls"
}
],
"usage": {
"prompt_tokens": 273,
"completion_tokens": 20,
"total_tokens": 293
}
}
调用one-api
输入同上
输出:
{
"id": "chatcmpl-663e4ac598314f5593f2aca38d8c7457",
"model": "qwen2.5:0.5b",
"object": "chat.completion",
"created": 1752653578,
"choices": [
{
"index": 0,
"message": {
"role": "assistant",
"content": "I'm sorry, but I don't have access to real-time information about current conditions or forecasts for specific locations like California. The best way to find out what the current weather is in California is by checking with local news sources, online weather services, or apps designed for your region.\n\nHowever, I can offer some general information based on typical seasonal patterns:\n\n1. **Summer (June-August)**: During this season, temperatures tend to be warm but not too hot. Days are shorter and nights longer than in other parts of the United States.\n\n2. **Autumn (September-December)**: Autumn typically brings cooler days with shorter nights.\n\n3. **Winter (January-March)**: Weather in California tends to be colder months when compared to more northern climates like those in Europe or Asia, but temperatures can vary greatly from year to year due to weather patterns and climate change impacts.\n\n4. **Spring (April-May)**: This is typically a warm season followed by some precipitation. It's often the time of year for outdoor activities and events, but it doesn't get very cold like fall might.\n\n5. **Summer (June-August)**: Similar conditions as mentioned in summer, with longer days and cooler nights.\n\nIf you're looking for specific weather details or current conditions in California, I'd suggest checking local weather updates from reliable news sources or apps that are known to cover California."
},
"finish_reason": "stop"
}
],
"usage": {
"prompt_tokens": 36,
"completion_tokens": 282,
"total_tokens": 318
}
}
排查
发现调用one-api时, one-api并没有识别输入中的 tools 参数, 将该参数去掉了再调用的ollama
{
"model": "qwen2.5:0.5b",
"messages": [
{
"role": "user",
"content": "what is the weather in California?"
}
],
"stream": false,
"options": {
}
}
使用Wireshark抓包获取,由于one-api部署在虚拟机,Wireshark的捕获选项里要选择 VMware Network Adapter VMnet8
结论
one-api 不支持工具调用???
更多推荐



所有评论(0)