leanku/ai
Composer 安装命令:
composer require leanku/ai
包简介
ai客户端调用,DeepSeek, OpenAI, Ollama,等
README 文档
README
🚀 一个简单、可扩展的 AI SDK,支持多种 AI 提供商(OpenAI, DeepSeek, Ollama 等)。
特性
- 多提供商支持 - OpenAI, DeepSeek, Ollama 等
- 统一接口 - 所有提供商使用相同的 API
- 可扩展 - 轻松添加新的 AI 提供商
安装
composer require leanku/ai
快速开始
基础使用
use Leanku\Ai\AIClient; $client = new AIClient([ 'default' => 'openai', 'providers' => [ 'openai' => [ 'api_key' => 'your-openai-api-key', ], ], ]); $response = $client->chat([ ['role' => 'user', 'content' => 'Hello, how are you?'] ]); echo $response->getContent(); // "Hello! I'm doing well, thank you for asking!"
使用建造者模式(推荐)
$response = $client->ask('What is PHP?') ->fromSystem('You are a helpful programming assistant.') ->andThen('Can you give me an example?') ->get(); echo $response->getContent();
流式响应
$stream = $client->chatStream([ ['role' => 'user', 'content' => 'Tell me a long story...'] ]); foreach ($stream as $chunk) { echo $chunk->getContent(); ob_flush(); flush(); }
文档
贡献
许可证
本项目基于 MIT 许可证开源。详见 LICENSE 文件。
统计信息
- 总下载量: 0
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 0
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2025-10-19