HEX
Server: LiteSpeed
System: Linux my-kul-web2054.main-hosting.eu 5.14.0-611.13.1.el9_7.x86_64 #1 SMP PREEMPT_DYNAMIC Thu Dec 11 04:57:59 EST 2025 x86_64
User: u665686179 (665686179)
PHP: 8.2.30
Disabled: system, exec, shell_exec, passthru, mysql_list_dbs, ini_alter, dl, symlink, link, chgrp, leak, popen, apache_child_terminate, virtual, mb_send_mail
Upload Files
File: /home/u665686179/domains/dealkr.com/public_html/Modules/AI/AIProviders/OpenAIProvider.php
<?php

namespace Modules\AI\AIProviders;

use Modules\AI\app\Contracts\AIProviderInterface;
use OpenAI;

class OpenAIProvider implements AIProviderInterface
{
    protected string $apiKey;
    protected ?string $organization;

    public function getName(): string
    {
        return 'OpenAI';
    }

    public function setApiKey($apikey): void
    {
        $this->apiKey = $apikey;
    }

    public function setOrganization($organization): void
    {
        $this->organization = $organization;
    }

    public function generate(string $prompt, ?string $imageUrl = null, array $options = []): string
    {
        $client = OpenAI::client($this->apiKey, $this->organization);
        $content = [['type' => 'text', 'text' => $prompt]];
        if (!empty($imageUrl)) {
            $content[] = [
                'type' => 'image_url',
                'image_url' => ['url' => $imageUrl],
            ];
        }
        $response = $client->chat()->create([
            'model' => 'gpt-4o',
            'messages' => [
                [
                    'role' => 'user',
                    'content' => $content,
                ],
            ],
            'temperature' => 0.3,
        ]);
        return $response->choices[0]->message->content;
    }
}