PluginProbe
Auto Alt Text / 2.5.2
Auto Alt Text v2.5.2
3.0.3 2.8.2 1.3.1 1.3.2 2.0.0 2.1.0 2.1.1 2.2.0 2.3.0 2.3.1 2.3.2 2.3.3 2.3.4 2.4.0 2.4.1 2.4.2 2.5.0 2.5.1 2.5.2 2.5.3 2.6.0 2.6.1 2.7.0 2.8.0 2.8.1 All 28 releases
← All changes | src/App/AIProviders/OpenAI/OpenAIVision.php +10 -27 2.8.22.5.2 View file →
@@ -1,34 +1,24 @@
1 1 <?php
2 2
3 3 namespace AATXT\App\AIProviders\OpenAI;
4 4
5 -use AATXT\App\Configuration\AIProviderConfig;
5 +use AATXT\App\Admin\PluginOptions;
6 +use OpenAI;
7 +use OpenAI\Client;
8 +use OpenAI\Exceptions\ErrorException;
6 9 use AATXT\App\Exceptions\OpenAI\OpenAIException;
7 -use AATXT\App\Infrastructure\Http\HttpClientInterface;
8 10 use AATXT\Config\Constants;
9 11
10 -/**
11 - * OpenAI Vision provider for generating alt text using GPT models with vision capabilities.
12 - *
13 - * This class uses dependency injection to receive HTTP client and configuration,
14 - * removing static dependencies on PluginOptions.
15 - */
16 12 class OpenAIVision extends OpenAIResponse
17 13 {
18 - /**
19 - * Constructor.
20 - *
21 - * @param HttpClientInterface $httpClient HTTP client for API calls
22 - * @param AIProviderConfig $config Configuration with API key, prompt, and model
23 - */
24 - public function __construct(HttpClientInterface $httpClient, AIProviderConfig $config)
14 + public static function make(): OpenAIVision
25 15 {
26 - parent::__construct($httpClient, $config);
16 + return new self();
27 17 }
28 18
29 19 /**
30 - * Make a request to OpenAI Chat APIs to retrieve a description for the image passed
20 + * Make a request to OpenAI Chat APIs to retrieve a description for the image passed
31 21 * @param string $imageUrl
32 22 * @return string
33 23 * @throws OpenAIException
34 24 */
@@ -34,16 +24,9 @@
34 24 */
35 25 public function response(string $imageUrl): string
36 26 {
37 27 $prompt = parent::prompt();
38 - $requestBody = parent::prepareRequestBody($this->config->getModel(), $prompt, $imageUrl);
39 - $decodedBody = parent::decodedResponseBody($requestBody, Constants::AATXT_OPENAI_RESPONSES_API_ENDPOINT);
40 -
41 - foreach($decodedBody['output'] as $output) {
42 - if($output['type'] === 'message') {
43 - return $this->cleanString($output['content'][0]['text']);
44 - }
45 - }
46 -
47 - return '';
28 + $requestBody = parent::prepareRequestBody(PluginOptions::openAiModel(), $prompt, $imageUrl);
29 + $decodedBody = parent::decodedResponseBody($requestBody, Constants::AATXT_OPENAI_CHAT_COMPLETION_ENDPOINT);
30 + return $this->cleanString($decodedBody['choices'][0]['message']['content']);
48 31 }
49 32 }