ai客户端调用,DeepSeek, OpenAI, Ollama,等

Maintainers

Details

github.com/leanku/ai

Source

Issues

Installs: 0

Dependents: 0

Suggesters: 0

Security: 0

Stars: 0

Watchers: 0

Forks: 0

Open Issues: 0

pkg:composer/leanku/ai

dev-master 2025-10-19 15:23 UTC

This package is not auto-updated.

Last update: 2025-10-19 21:56:50 UTC


README

🚀 一个简单、可扩展的 AI SDK,支持多种 AI 提供商(OpenAI, DeepSeek, Ollama 等)。

PHP Version License

特性

  • 多提供商支持 - 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 文件。