@@ -341,14 +341,14 @@ static function ( $key, $value ) {
341341 */
342342 $ prompt = (string ) apply_filters ( 'wpai_content_classification_prompt ' , $ prompt , $ context , $ taxonomy , $ assigned_terms , $ available_terms );
343343
344- $ builder = $ this ->get_prompt_builder ( $ prompt );
344+ $ prompt_builder = $ this ->get_prompt_builder ( $ prompt );
345345
346- if ( is_wp_error ( $ builder ) ) {
347- return $ builder ;
346+ if ( is_wp_error ( $ prompt_builder ) ) {
347+ return $ prompt_builder ;
348348 }
349349
350350 // Generate the suggestions using the AI client with structured output.
351- $ result = $ builder -> as_json_response ( $ this -> suggestions_schema () ) ->generate_text ();
351+ $ result = $ prompt_builder ->generate_text ();
352352
353353 if ( is_wp_error ( $ result ) ) {
354354 return $ result ;
@@ -391,20 +391,16 @@ static function ( $key, $value ) {
391391 * @return \WP_AI_Client_Prompt_Builder|\WP_Error The prompt builder, or a WP_Error on failure.
392392 */
393393 private function get_prompt_builder ( string $ prompt ) {
394- $ builder = wp_ai_client_prompt ( $ prompt )
394+ $ prompt_builder = wp_ai_client_prompt ( $ prompt )
395395 ->using_system_instruction ( $ this ->get_system_instruction () )
396396 ->using_temperature ( 0.5 )
397- ->using_model_preference ( ...get_preferred_models_for_text_generation () );
397+ ->using_model_preference ( ...get_preferred_models_for_text_generation () )
398+ ->as_json_response ( $ this ->suggestions_schema () );
398399
399- // Return a more specific error if there isn't a model that supports text generation.
400- if ( ! $ builder ->is_supported_for_text_generation () ) {
401- return new WP_Error (
402- 'unsupported_model ' ,
403- esc_html__ ( 'Term generation failed. Please ensure you have a connected provider that supports text generation. ' , 'ai ' )
404- );
405- }
406-
407- return $ builder ;
400+ return $ this ->ensure_text_generation_supported (
401+ $ prompt_builder ,
402+ esc_html__ ( 'Term generation failed. Please ensure you have a connected provider that supports text generation. ' , 'ai ' )
403+ );
408404 }
409405
410406 /**
0 commit comments