Ollama stream() fails with default GuzzleHttpClient, but works with AmpHttpClient
**Describe the bug**
When using `NeuronAI\Providers\Ollama\Ollama` with `stream()`, the default `GuzzleHttpClient` path fails in my environment, while `AmpHttpClient` works correctly with the same Ollama server, model, prompt, and agent logic.
In my test:
- `GuzzleHttpClient` + `Ollama->stream()` => fails
- `AmpHttpClient` + `Ollama->stream()` => works
- same Ollama endpoint
- same model
- same prompt
- same Neuron agent setup
This looks like a transport-layer issue in the default streaming HTTP client path, not a message-mapping issue.
**To Reproduce**
Steps to reproduce the behavior:
1. Start a local Ollama server at `http://127.0.0.1:11434/api`
2. Make sure a model like `qwen3.5:4b` is available
3. Run this code with the default HTTP client:
```php
<?php
require 'vendor/autoload.php';
use NeuronAI\Agent\Agent;
use NeuronAI\Chat\Messages\UserMessage;
use NeuronAI\Providers\Ollama\Ollama;
$provider = new Ollama(
url: 'http://127.0.0.1:11434/api',
model: 'qwen3.5:4b',
);
$agent = Agent::make()
->setAiProvider($provider)
->setInstructions('你是一个用于测试流式输出的助手。回答简洁,优先使用中文。');
$handler = $agent->stream(
new UserMessage('请用中文做一个简短自我介绍,然后用一句话说明这是一次 Neuron AI 的流式输出测试。')
);
foreach ($handler->events() as $event) {
// consume stream
}
```
4. See error:
```text
NeuronAI\Exceptions\HttpException
Network error during POST chat:
```
5. Replace the provider with `AmpHttpClient`:
```php
<?php
require 'vendor/autoload.php';
use NeuronAI\Agent\Agent;
use NeuronAI\Chat\Messages\UserMessage;
use NeuronAI\HttpClient\AmpHttpClient;
use NeuronAI\Providers\Ollama\Ollama;
$provider = new Ollama(
url: 'http://127.0.0.1:11434/api',
model: 'qwen3.5:4b',
httpClient: new AmpHttpClient(),
);
$agent = Agent::make()
->setAiProvider($provider)
->setInstructions('你是一个用于测试流式输出的助手。回答简洁,优先使用中文。');
$handler = $agent->stream(
new UserMessage('请用中文做一个简短自我介绍,然后用一句话说明这是一次 Neuron AI 的流式输出测试。')
);
foreach ($handler->events() as $event) {
// consume stream
}
```
6. This works correctly and streams text as expected
**Expected behavior**
`Ollama->stream()` should work with the default HTTP client implementation as well, not only with `AmpHttpClient`.
**Screenshots**
Not applicable.
**The Neuron AI version you are using:**
- Version: `3.3.3`
**Additional context**
Environment:
- OS: Windows
- PHP: `8.3.16`
- `guzzlehttp/guzzle`: `7.10.0`
- `amphp/http-client`: `5.3.4`
- Ollama server: `http://127.0.0.1:11434/api`
- Model: `qwen3.5:4b`
Additional notes from debugging:
- The same Ollama endpoint works outside the framework
- The same prompt works with `AmpHttpClient`
- The same payload works when not using the default Guzzle streaming path
- This strongly suggests the issue is in the default streaming transport/client path rather than in Ollama message formatting
5 条评论