🚀 一个简单、可扩展的 AI SDK,支持多种 AI 提供商(OpenAI, DeepSeek, Ollama 等)。
- 多提供商支持 - OpenAI, DeepSeek, Ollama 等
- 统一接口 - 所有提供商使用相同的 API
- 可扩展 - 轻松添加新的 AI 提供商
composer require leanku/aiuse 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 文件。