PluginProbe
Auto Alt Text / 2.0.0
Auto Alt Text v2.0.0
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.0.0, at src/App/AIProviders/OpenAI/OpenAIVision.php

31 lines 931 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 OpenAI;
6 use OpenAI\Client;
7 use OpenAI\Exceptions\ErrorException;
8 use AATXT\App\Exceptions\OpenAI\OpenAIException;
9 use AATXT\Config\Constants;
10
11 class OpenAIVision extends OpenAIResponse
12 {
13 public static function make(): OpenAIVision
14 {
15 return new self();
16 }
17
18 /**
19 * Make a request to OpenAI Chat APIs to retrieve a description for the image passed
20 * @param string $imageUrl
21 * @return string
22 * @throws OpenAIException
23 */
24 public function response(string $imageUrl): string
25 {
26 $prompt = parent::prompt();
27 $requestBody = parent::prepareRequestBody(Constants::AATXT_OPENAI_VISION_MODEL, $prompt, $imageUrl);
28 $decodedBody = parent::decodedResponseBody($requestBody, Constants::AATXT_OPENAI_CHAT_COMPLETION_ENDPOINT);
29 return $this->cleanString($decodedBody['choices'][0]['message']['content']);
30 }
31 }