massrimcp/openai-sdk
最新稳定版本:0.1.1
Composer 安装命令:
composer require massrimcp/openai-sdk
包简介
Open Ai SDK
README 文档
README
A modern PHP SDK for interacting with the OpenAI API, including support for Chat, Completions, and more. Built for PHP 8+ with a focus on developer experience, type safety, and extensibility.
Features
- Simple and intuitive API for OpenAI endpoints
- Support for Chat, Completions, and other OpenAI features
- DTOs for request/response payloads
- Extensible and testable client architecture
- PSR-7/PSR-18 compatible HTTP client support
Installation
Install via Composer:
composer require your-vendor/php-sdk
Usage
use YourVendor\OpenAiSdk\OpenAiSdk; $client = new OpenAiClient('your-api-key'); $response = $client->chat()->create([ 'model' => 'gpt-4', 'messages' => [ ['role' => 'user', 'content' => 'Hello!'], ], ]); print_r($response);
Chat API Example
$chatClient = $client->chat(); $result = $chatClient->create([ 'model' => 'gpt-4', 'messages' => [ ['role' => 'user', 'content' => 'Tell me a joke.'], ], ]); echo $result['choices'][0]['message']['content'];
Testing
Run tests with PHPUnit:
vendor/bin/phpunit
Requirements
- PHP 8.0 or higher
- Composer
- PSR-7/PSR-18 compatible HTTP client (e.g., Guzzle)
Contributing
Contributions are welcome! Please open issues or submit pull requests.
License
This project is licensed under the MIT License.
统计信息
- 总下载量: 3
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 2
- 点击次数: 3
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2026-01-30