Skip to content

leanku/ai

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

leanku/ai

🚀 一个简单、可扩展的 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 文件。

About

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

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages