PluginProbe
Auto Alt Text / 2.4.1
Auto Alt Text v2.4.1
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
auto-alt-text / src / App / AIProviders / OpenAI / OpenAIVision.php

OpenAIVision.php in Auto Alt Text 2.4.1, at src/App/AIProviders/OpenAI/OpenAIVision.php

32 lines 958 B
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace AATXT\App\AIProviders\OpenAI;
4
5 use AATXT\App\Admin\PluginOptions;
6 use OpenAI;
7 use OpenAI\Client;
8 use OpenAI\Exceptions\ErrorException;
9 use AATXT\App\Exceptions\OpenAI\OpenAIException;
10 use AATXT\Config\Constants;
11
12 class OpenAIVision extends OpenAIResponse
13 {
14 public static function make(): OpenAIVision
15 {
16 return new self();
17 }
18
19 /**
20 * Make a request to OpenAI Chat APIs to retrieve a description for the image passed
21 * @param string $imageUrl
22 * @return string
23 * @throws OpenAIException
24 */
25 public function response(string $imageUrl): string
26 {
27 $prompt = parent::prompt();
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']);
31 }
32 }