| @@ -1,8 +1,9 @@ | ||
| 1 | 1 | <?php |
| 2 | 2 | |
| 3 | 3 | namespace AATXT\App\AIProviders\OpenAI; |
| 4 | 4 | |
| 5 | +use AATXT\App\Admin\PluginOptions; | |
| 5 | 6 | use OpenAI; |
| 6 | 7 | use OpenAI\Client; |
| 7 | 8 | use OpenAI\Exceptions\ErrorException; |
| 8 | 9 | use AATXT\App\Exceptions\OpenAI\OpenAIException; |
| @@ -23,32 +24,9 @@ | ||
| 23 | 24 | */ |
| 24 | 25 | public function response(string $imageUrl): string |
| 25 | 26 | { |
| 26 | 27 | $prompt = parent::prompt(); |
| 27 | - | |
| 28 | - $requestBody = [ | |
| 29 | - 'model' => Constants::AATXT_OPENAI_VISION_MODEL, | |
| 30 | - 'messages' => [ | |
| 31 | - [ | |
| 32 | - 'role' => 'user', | |
| 33 | - 'content' => [ | |
| 34 | - [ | |
| 35 | - "type" => "text", | |
| 36 | - "text" => $prompt | |
| 37 | - ], | |
| 38 | - [ | |
| 39 | - "type" => "image_url", | |
| 40 | - "image_url" => [ | |
| 41 | - "url" => $imageUrl | |
| 42 | - ] | |
| 43 | - ] | |
| 44 | - ] | |
| 45 | - ], | |
| 46 | - ], | |
| 47 | - 'max_tokens' => Constants::AATXT_OPENAI_MAX_TOKENS, | |
| 48 | - ]; | |
| 49 | - | |
| 28 | + $requestBody = parent::prepareRequestBody(PluginOptions::openAiModel(), $prompt, $imageUrl); | |
| 50 | 29 | $decodedBody = parent::decodedResponseBody($requestBody, Constants::AATXT_OPENAI_CHAT_COMPLETION_ENDPOINT); |
| 51 | - | |
| 52 | 30 | return $this->cleanString($decodedBody['choices'][0]['message']['content']); |
| 53 | 31 | } |
| 54 | 32 | } |