| @@ -76,9 +76,9 @@ | ||
| 76 | 76 | public static function capable_providers(): array { |
| 77 | 77 | return [ |
| 78 | 78 | 'openai' => 'gpt-5-mini', |
| 79 | 79 | 'claude' => 'claude-sonnet-5', |
| 80 | - 'gemini' => 'gemini-2.5-flash', | |
| 80 | + 'gemini' => Settings::DEFAULT_GEMINI_MODEL, | |
| 81 | 81 | ]; |
| 82 | 82 | } |
| 83 | 83 | |
| 84 | 84 | /** |
| @@ -86,9 +86,9 @@ | ||
| 86 | 86 | * |
| 87 | 87 | * @return bool |
| 88 | 88 | */ |
| 89 | 89 | public function is_available(): bool { |
| 90 | - $provider = (string) $this->settings->get('ai_provider', 'openai'); | |
| 90 | + $provider = (string) $this->settings->get('ai_provider', Settings::AI_PROVIDER_NONE); | |
| 91 | 91 | |
| 92 | 92 | return isset(self::capable_providers()[$provider]) |
| 93 | 93 | && '' !== $this->api_key_for($provider); |
| 94 | 94 | } |
| @@ -117,15 +117,24 @@ | ||
| 117 | 117 | * @return string Alt text, or '' when it could not be produced. |
| 118 | 118 | * @throws \Exception When the provider is unusable or the call fails. |
| 119 | 119 | */ |
| 120 | 120 | public function describe_attachment(int $attachment_id, string $context = ''): string { |
| 121 | - $provider = (string) $this->settings->get('ai_provider', 'openai'); | |
| 121 | + $provider = (string) $this->settings->get('ai_provider', Settings::AI_PROVIDER_NONE); | |
| 122 | 122 | $models = self::capable_providers(); |
| 123 | 123 | |
| 124 | + // Distinguish "no provider chosen" from "this provider can't do vision": | |
| 125 | + // interpolating an empty provider name reads as a broken string (#572). | |
| 126 | + if (Settings::AI_PROVIDER_NONE === $provider) { | |
| 127 | + throw new \Exception(esc_html__( | |
| 128 | + 'No AI provider is selected. Choose OpenAI, Anthropic or Gemini in Settings → AI Provider.', | |
| 129 | + 'thinkrank' | |
| 130 | + )); | |
| 131 | + } | |
| 132 | + | |
| 124 | 133 | if (!isset($models[$provider])) { |
| 125 | 134 | throw new \Exception(sprintf( |
| 126 | 135 | /* translators: %s: AI provider name. */ |
| 127 | - esc_html__('The %s provider cannot describe images. Switch to OpenAI, Claude or Gemini in Settings → AI Provider.', 'thinkrank'), | |
| 136 | + esc_html__('The %s provider cannot describe images. Switch to OpenAI, Anthropic or Gemini in Settings → AI Provider.', 'thinkrank'), | |
| 128 | 137 | esc_html($provider) |
| 129 | 138 | )); |
| 130 | 139 | } |
| 131 | 140 | |
| @@ -379,9 +388,9 @@ | ||
| 379 | 388 | $data = json_decode($raw, true); |
| 380 | 389 | |
| 381 | 390 | if ($status >= 400) { |
| 382 | 391 | $message = $data['error']['message'] ?? ($data['error']['status'] ?? 'Unknown API error'); |
| 383 | - throw new \Exception(sprintf('Vision API error (%d): %s', $status, esc_html((string) $message))); | |
| 392 | + throw new \Exception(esc_html(sprintf('Vision API error (%d): %s', $status, (string) $message))); | |
| 384 | 393 | } |
| 385 | 394 | |
| 386 | 395 | return is_array($data) ? $data : []; |
| 387 | 396 | } |