goed/cerebras-php
最新稳定版本:v0.1.0
Composer 安装命令:
composer require goed/cerebras-php
包简介
A PHP adapter for the Cerebras AI API
README 文档
README
Made with ❤️ by Goed.email
Cerebras PHP Client
A PHP client library for interacting with the Cerebras AI API, providing easy access to chat completions and other endpoints.
Installation
Install the package via Composer:
composer require goed/cerebras-php
Usage
Setup
Set your API key as an environment variable:
export CEREBRAS_API_KEY=your_api_key_here
Basic Chat Completion
Create a non-streaming chat completion:
<?php require 'vendor/autoload.php'; use Goed\Cerebras\Client; $client = new Client(); $response = $client->chat()->create([ 'model' => 'llama3.1-8b', 'messages' => [ ['role' => 'user', 'content' => 'Hello, how are you?'] ] ]); echo $response['choices'][0]['message']['content'];
Streaming Chat Completion
For real-time responses, use streaming:
<?php require 'vendor/autoload.php'; use Goed\Cerebras\Client; $client = new Client(); $stream = $client->chat()->create([ 'model' => 'llama3.1-8b', 'messages' => [ ['role' => 'user', 'content' => 'Tell me a story.'] ], 'stream' => true ]); foreach ($stream as $chunk) { echo $chunk['choices'][0]['delta']['content'] ?? ''; }
For more examples, see the examples/ directory, including basic.php, chat_page.php, and chat_page_non_streaming.php.
Browser Chat Demo
Serve the example files with PHP's built-in server for quick browser chat UIs:
php -S localhost:8080 -t examples
Then open:
http://localhost:8080/chat_page.phpfor streaming responseshttp://localhost:8080/chat_page_non_streaming.phpfor non-streaming responses
Features
- API Compatibility: Endpoints and payloads match the official Cerebras AI API. Adjust model IDs and fields as needed.
- Retry Mechanism: Automatic retry with backoff for 429 (rate limit) and 5xx errors.
- Streaming Support: Server-Sent Events (SSE) for real-time chat completions.
- Helpers: Basic utility functions for common tasks.
Notes
Ensure your API key is valid and has the necessary permissions. Refer to the Cerebras AI documentation for detailed API specifications.
统计信息
- 总下载量: 67
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 1
- 点击次数: 0
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2025-10-15