PHPackages                             leanku/ai - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. leanku/ai

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

leanku/ai
=========

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

00PHP

Since Oct 19Pushed 8mo agoCompare

[ Source](https://github.com/leanku/ai)[ Packagist](https://packagist.org/packages/leanku/ai)[ RSS](/packages/leanku-ai/feed)WikiDiscussions master Synced today

READMEChangelogDependenciesVersions (1)Used By (0)

leanku/ai
=========

[](#leankuai)

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

[![PHP Version](https://camo.githubusercontent.com/04744bae0a61d2ffe29c26f07a9612eae20445fc6feaeb77b3af1f0e9be6447c/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f7068702d253345253344382e312d3838393242462e737667)](https://www.php.net/)[![License](https://camo.githubusercontent.com/7013272bd27ece47364536a221edb554cd69683b68a46fc0ee96881174c4214c/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6c6963656e73652d4d49542d626c75652e737667)](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();
}
```

文档
--

[](#文档)

- [完整使用指南](docs/usage.md)
- [配置说明](docs/configuration.md)
- [示例代码](docs/examples/)

贡献
--

[](#贡献)

许可证
---

[](#许可证)

本项目基于 MIT 许可证开源。详见 [LICENSE](LICENSE) 文件。

###  Health Score

15

—

LowBetter than 3% of packages

Maintenance42

Moderate activity, may be stable

Popularity0

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity13

Early-stage or recently created project

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/81899539?v=4)[Leanku](/maintainers/leanku)[@leanku](https://github.com/leanku)

---

Top Contributors

[![leanku](https://avatars.githubusercontent.com/u/81899539?v=4)](https://github.com/leanku "leanku (3 commits)")

### Embed Badge

![Health badge](/badges/leanku-ai/health.svg)

```
[![Health](https://phpackages.com/badges/leanku-ai/health.svg)](https://phpackages.com/packages/leanku-ai)
```

###  Alternatives

[wordpress/phpdoc-parser

Static code parser for WordPress source.

23920.0k](/packages/wordpress-phpdoc-parser)[adrhumphreys/silverstripe-textdropdownfield

A text field combined with a dropdown field.

106.4k](/packages/adrhumphreys-silverstripe-textdropdownfield)[webdevstudios/cmb2-user-select

Special CMB2 Field that allows users to define an autocomplete text field for users

211.3k1](/packages/webdevstudios-cmb2-user-select)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
