hch/chatgpt-integration-bundle

A Symfony bundle to integrate ChatGPT API.

Installs: 20

Dependents: 0

Suggesters: 0

Security: 0

Stars: 2

Watchers: 1

Forks: 1

Open Issues: 0

Type:symfony-bundle

pkg:composer/hch/chatgpt-integration-bundle

v1.0.0 2024-10-25 18:46 UTC

This package is auto-updated.

Last update: 2025-09-25 20:52:34 UTC


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.