hch / chatgpt-integration-bundle
A Symfony bundle to integrate ChatGPT API.
Installs: 16
Dependents: 0
Suggesters: 0
Security: 0
Stars: 2
Watchers: 1
Forks: 0
Open Issues: 0
Type:symfony-bundle
Requires
- php: >=7.4
- symfony/framework-bundle: ^5.4|^6.0|^7.1
- symfony/http-client: ^5.4|^6.0|^7.1
Requires (Dev)
- phpunit/phpunit: ^9.5
README
This bundle provides a simple way to integrate ChatGPT API with Symfony applications.
Installation
composer require HCH/chatgpt-integration-bundle
Configuration
In your Symfony config, add your OpenAI API key, API URL, and model:
# config/packages/chatgpt_integration.yaml chatgpt_integration: api_key: '%env(CHATGPT_API_KEY)%' api_url: 'https://api.openai.com/v1/chat/completions' model: 'gpt-3.5-turbo'
Usage
Inject the ChatGPTClient
service wherever needed:
use HCH\ChatGPTIntegrationBundle\Service\ChatGPTClient; class SomeService { private $chatGPTClient; public function __construct(ChatGPTClient $chatGPTClient) { $this->chatGPTClient = $chatGPTClient; } public function getResponseFromChatGPT(string $message): string { return $this->chatGPTClient->ask($message); } }
Testing
Run tests with PHPUnit:
php bin/phpunit
License
This bundle is released under the MIT License.