| @@ -28,8 +28,9 @@ | ||
| 28 | 28 | ]; |
| 29 | 29 | |
| 30 | 30 | $args = [ |
| 31 | 31 | 'headers' => $headers, |
| 32 | + 'timeout' => 90, | |
| 32 | 33 | 'body' => json_encode($requestBody), |
| 33 | 34 | 'method' => 'POST', |
| 34 | 35 | 'data_format' => 'body', |
| 35 | 36 | ]; |
| @@ -57,23 +58,12 @@ | ||
| 57 | 58 | * @return string |
| 58 | 59 | */ |
| 59 | 60 | protected function prompt(): string |
| 60 | 61 | { |
| 61 | - return PluginOptions::prompt() ?: Constants::AATXT_OPENAI_DEFAULT_PROMPT; | |
| 62 | + return PluginOptions::openAiPrompt() ?: Constants::AATXT_OPENAI_DEFAULT_PROMPT; | |
| 62 | 63 | } |
| 63 | 64 | |
| 64 | 65 | /** |
| 65 | - * Compute the fallback prompt based on the template saved in the options and the imageUrl passed | |
| 66 | - * @param string $imageUrl | |
| 67 | - * @return string | |
| 68 | - */ | |
| 69 | - protected function fallbackPrompt(string $imageUrl): string | |
| 70 | - { | |
| 71 | - $prompt = PluginOptions::fallbackPrompt() ?: Constants::AATXT_OPENAI_DEFAULT_FALLBACK_PROMPT; | |
| 72 | - return str_replace(Constants::AATXT_IMAGE_URL_TAG, $imageUrl, $prompt); | |
| 73 | - } | |
| 74 | - | |
| 75 | - /** | |
| 76 | 66 | * @param string $text |
| 77 | 67 | * @return string |
| 78 | 68 | */ |
| 79 | 69 | protected function cleanString(string $text): string |
| @@ -84,6 +74,31 @@ | ||
| 84 | 74 | '/"/' // HTML sequence for double quotes |
| 85 | 75 | ); |
| 86 | 76 | |
| 87 | 77 | return trim(preg_replace($patterns, '', $text)); |
| 78 | + } | |
| 79 | + | |
| 80 | + protected function prepareRequestBody(string $model, string $prompt, string $imageUrl): array | |
| 81 | + { | |
| 82 | + return [ | |
| 83 | + 'model' => Constants::AATXT_OPENAI_VISION_MODEL, | |
| 84 | + 'messages' => [ | |
| 85 | + [ | |
| 86 | + 'role' => 'user', | |
| 87 | + 'content' => [ | |
| 88 | + [ | |
| 89 | + "type" => "text", | |
| 90 | + "text" => $prompt | |
| 91 | + ], | |
| 92 | + [ | |
| 93 | + "type" => "image_url", | |
| 94 | + "image_url" => [ | |
| 95 | + "url" => $imageUrl | |
| 96 | + ] | |
| 97 | + ] | |
| 98 | + ] | |
| 99 | + ], | |
| 100 | + ], | |
| 101 | + 'max_tokens' => Constants::AATXT_OPENAI_MAX_TOKENS, | |
| 102 | + ]; | |
| 88 | 103 | } |
| 89 | 104 | } |