微信扫码
添加专属顾问
 
                        我要投稿
Ollama v0.8更新,带来流式响应与工具调用的革新体验。 核心内容: 1. 流式响应与即时工具调用的结合,提升AI应用流畅性 2. 新智能增量解析器,增强工具调用的准确性与兼容性 3. 开发者友好集成,支持多种语言和模型,简化技术实现
 
                                实时交互和即时响应是AI应用体验的关键,但阻塞式的工具调用往往会打断内容的流畅性,导致用户在模型与外部工具交互时经历不必要的等待。Ollama 近日推出v0.8更新,带来了带工具调用的流式响应 (Streaming responses with tool calling) 功能,让开发者构建的聊天应用从此能够像流式输出普通文本一样,实时地调用工具并展示结果。
这一更新使得所有聊天应用都能够在模型生成内容的同时,实时地调用外部工具,并将整个过程(包括模型的思考、工具的调用指令、以及最终的文本回复)流畅地展示给用户。该功能已在 Ollama 的 Python 和 JavaScript 库以及 cURL API 中得到全面支持。
本次更新的核心亮点包括:
在技术实现层面,开发者可以通过以下方式启用该功能:
/api/chat 请求中设置 "stream": true 并通过 tools 数组定义可用的工具。ollama.chat() 时,设置 stream=True 并将工具定义(可以是函数对象)传递给 tools 参数。ollama.chat() 时,设置 stream: true 并将工具schema对象传递给 tools 参数。下面是 Python 的示例 (调用自定义的数学函数):
# Define the python function
def add_two_numbers(a: int, b: int) -> int:
"""
  Add two numbers
  Args:
    a (set): The first number as an int
    b (set): The second number as an int
  Returns:
    int: The sum of the two numbers
  """
return a + b
from ollama import chat
messages = [{'role': 'user', 'content': 'what is three minus one?'}]
response: ChatResponse = chat(
  model='qwen3',
  messages=messages,
  tools=[add_two_numbers], # Python SDK supports passing tools as functions
  stream=True
)
for chunk in response:
# Print model content
  print(chunk.message.content, end='', flush=True)
# Print the tool call
if chunk.message.tool_calls:
    print(chunk.message.tool_calls)
预期输出 (示例,取决于模型行为和用户问题是否匹配工具):
<think>
Okay, the user is asking ...
</think>
[ToolCall(function=Function(name='subtract_two_numbers', arguments={'a': 3, 'b': 1}))]
cURL 示例 (查询天气):
curl http://localhost:11434/api/chat -d '{
  "model": "qwen3",
  "messages": [
    {
      "role": "user",
      "content": "What is the weather today in Toronto?"
    }
  ],
  "stream": true,
  "tools": [
    {
      "type": "function",
      "function": {
        "name": "get_current_weather",
        "description": "Get the current weather for a location",
        "parameters": {
          "type": "object",
          "properties": {
            "location": {
              "type": "string",
              "description": "The location to get the weather for, e.g. San Francisco, CA"
            },
            "format": {
              "type": "string",
              "description": "The format to return the weather in, e.g. 'celsius' or 'fahrenheit'",
              "enum": ["celsius", "fahrenheit"]
            }
          },
          "required": ["location", "format"]
        }
      }
    }
  ]
}'
流式输出:
...
{
"model": "qwen3",
"created_at": "2025-05-27T22:54:57.641643Z",
"message": {
    "role": "assistant",
    "content": "celsius"
  },
"done": false
}
 {
"model": "qwen3",
"created_at": "2025-05-27T22:54:57.673559Z",
"message": {
    "role": "assistant",
    "content": "</think>"
  },
"done": false
}
{
"model": "qwen3",
"created_at": "2025-05-27T22:54:58.100509Z",
"message": {
    "role": "assistant",
    "content": "",
    "tool_calls": [
      {
        "function": {
          "name": "get_current_weather",
          "arguments": {
            "format": "celsius",
            "location": "Toronto"
          }
        }
      }
    ]
  },
"done": false
}
...
官方同时指出,为了获得最佳工具调用效果,对于需要高精度工具调用或复杂交互的场景,如下所示,可以尝试通过 options 中的 num_ctx 增加模型的上下文窗口(例如设置为 32000),但这会增加内存使用。
curl -X POST "http://localhost:11434/api/chat" -d '{
  "model": "llama3.2",
  "messages": [
    {
      "role": "user",
      "content": "why is the sky blue?"
    }
  ],
  "options": {
    "num_ctx": 32000 # Update context window here
  }
}'53AI,企业落地大模型首选服务商
产品:场景落地咨询+大模型应用平台+行业解决方案
承诺:免费POC验证,效果达标后再合作。零风险落地应用大模型,已交付160+中大型企业
2025-10-31
Palantir 本体论模式:重塑企业 AI 应用的 “语义根基” 与产业启示
2025-10-31
树莓派这种“玩具级”设备,真能跑大模型吗?
2025-10-30
Cursor 2.0的一些有趣的新特性
2025-10-30
Anthropic 发布最新研究:LLM 展现初步自省迹象
2025-10-30
让Agent系统更聪明之前,先让它能被信任
2025-10-30
Rag不行?谷歌DeepMind同款,文档阅读新助手:ReadAgent
2025-10-29
4大阶段,10个步骤,助你高效构建企业级智能体(Agent)
2025-10-29
DocReward:让智能体“写得更专业”的文档奖励模型
 
            2025-08-21
2025-08-21
2025-08-19
2025-09-16
2025-10-02
2025-09-08
2025-09-17
2025-08-19
2025-09-29
2025-08-20