- 增加流式事件流支持,Provider 输出 `message.delta` 等事件 - 实现 OpenAI 兼容适配器,包括 RequestBuilder、ApiClient 等模块 - 更新 Agent Run 逻辑,支持流式增量写入与模型完成状态管理 - 扩展配置项 `agent.openai.*`,支持模型、密钥等配置 - 优化文档,完善流式事件与消息类型说明 - 增加单元测试,覆盖 Provider 和 OpenAI 适配相关逻辑 - 更新环境变量与配置示例,支持新功能
30 lines
831 B
PHP
30 lines
831 B
PHP
<?php
|
|
|
|
namespace App\Services\Agent;
|
|
|
|
use App\Services\Agent\OpenAi\OpenAiChatCompletionsAdapter;
|
|
|
|
class HttpAgentProvider implements AgentProviderInterface
|
|
{
|
|
private readonly bool $enabled;
|
|
|
|
public function __construct(private readonly OpenAiChatCompletionsAdapter $adapter)
|
|
{
|
|
$baseUrl = (string) config('agent.openai.base_url', '');
|
|
$apiKey = (string) config('agent.openai.api_key', '');
|
|
$this->enabled = trim($baseUrl) !== '' && trim($apiKey) !== '';
|
|
}
|
|
|
|
/**
|
|
* @param array<string, mixed> $options
|
|
*/
|
|
public function stream(AgentContext $context, array $options = []): \Generator
|
|
{
|
|
if (! $this->enabled) {
|
|
return (new DummyAgentProvider())->stream($context, $options);
|
|
}
|
|
|
|
return $this->adapter->stream($context, $options);
|
|
}
|
|
}
|