400 ) ); } try { $builder = wp_ai_client_prompt() ->using_system_instruction( Ai::system_prompt() ) ->with_file( 'data:' . $image['mime'] . ';base64,' . $image['data'], $image['mime'] ) ->with_text( $context['text'] ) ->using_temperature( 0.2 ) ->using_max_tokens( 300 ) ->as_json_response( Ai::schema() ); if ( ! $builder->is_supported_for_text_generation() ) { return new \WP_Error( 'fixlight_wp_ai_unsupported', __( 'None of the AI services connected in Settings → Connectors can describe images. Connect one that can (for example Google, OpenAI or Anthropic), or choose another option in Fixlight → Settings.', 'fixlight' ), array( 'status' => 400 ) ); } $text = $builder->generate_text(); } catch ( \Throwable $error ) { /* translators: %s: error message. */ return new \WP_Error( 'fixlight_wp_ai_error', sprintf( __( 'The AI connected to WordPress returned an error: %s', 'fixlight' ), wp_strip_all_tags( substr( $error->getMessage(), 0, 300 ) ) ), array( 'status' => 502 ) ); } if ( is_wp_error( $text ) ) { return $text; } $answer = Ai::parse_answer( (string) $text ); if ( null === $answer ) { return new \WP_Error( 'fixlight_ai_parse', __( 'The AI connected to WordPress returned an answer Fixlight could not read. Try again.', 'fixlight' ), array( 'status' => 502 ) ); } $answer['model'] = 'WordPress'; return $answer; } }