Chat, Completion, Embedding) aligns with Laravel’s preference for single-responsibility components, facilitating incremental adoption.OPENAI_API_KEY) and custom configurations, aligning with Laravel’s .env conventions. Can be extended via service providers or package config publishing.HttpTests, Mockery) may need adaptation for CI/CD pipelines.guzzlehttp/guzzle (v7+) and PHP 8.0+. Potential risks include:
OpenAIException) must be mapped to Laravel’s error-handling stack (e.g., App\Exceptions\Handler) to ensure consistent logging/alerts.throttle) or custom logic to avoid throttling in high-traffic apps..env?Http facade or standalone Guzzle.HttpClient if preferred over Guzzle.require installation with autoloading.config/services.php to publish package config and bind the client to the container:
$app->singleton(OpenAI::class, fn() => new \AgenceGW\OpenAI\OpenAI(config('services.openai.key')));
OpenAI::chat()->create()) for consistency.Mockery or Laravel’s Http test helpers.OpenAIException.text-davinci-003 → gpt-3.5-turbo) and update the package or fork if needed.dispatch(new ProcessEmbeddingJob($input))).Cache::remember('embeddings:'.$id, ...)).Log facade.composer require agence-gw/openai-php-client.php artisan vendor:publish --provider="AgenceGW\OpenAI\OpenAIServiceProvider"..env with OPENAI_API_KEY.app/Services/OpenAIService.php) to wrap package methods and add Laravel-specific logic.composer why-not agence-gw/openai-php-client to check for conflicts.composer.json to avoid surprises:
"require": {
"agence-gw/openai-php-client": "^1.0",
"guzzlehttp/guzzle": "^7.4"
}
Log::debug() to inspect package logs.config(['http.client.default.options' => ['debug' => env('APP_DEBUG')]]).spatie/laravel-queue-short-circuit).sync:work or Horizon for queue-based scaling of async calls.gpt-3.5-turbo vs. gpt-4) where acceptable.// app/Services/OpenAIService.php
public function generateChatResponse(string $prompt): string {
return OpenAI::chat()
->create([
'model' => 'gpt-3.5-turbo',
'messages' => [['role' => 'user', 'content' => $prompt]],
])->choices[0]->message->content;
}
Embedding for semantic search in Scout").How can I help you explore Laravel packages today?