77
88namespace WordPress \AI ;
99
10+ use Throwable ;
11+ use WP_Error ;
1012use WordPress \AiClient \AiClient ;
1113use WordPress \AiClient \Providers \Models \DTO \ModelConfig ;
12- use WP_Error ;
1314
1415/**
1516 * Handles API requests to various AI services.
@@ -59,7 +60,7 @@ public function __construct( string $provider = '', string $model = '' ) {
5960 * @param array $options The options to send.
6061 * @return array|\WP_Error The result of the request.
6162 */
62- public function generate_text ( $ prompt = null , $ system_instruction = null , array $ options = [] ) {
63+ public function generate_text ( $ prompt = null , $ system_instruction = null , array $ options = array () ) {
6364 if ( ! $ this ->is_client_available () ) {
6465 return new WP_Error ( 'ai_client_not_available ' , __ ( 'AI Client is not available ' , 'ai ' ) );
6566 }
@@ -83,7 +84,7 @@ public function generate_text( $prompt = null, $system_instruction = null, array
8384 * @param array $options The options to send.
8485 * @return \WordPress\AiClient\PromptBuilder|\WP_Error The prompt builder or a WP_Error.
8586 */
86- protected function prompt_builder ( $ prompt = null , $ system_instruction = null , array $ options = [] ) {
87+ protected function prompt_builder ( $ prompt = null , $ system_instruction = null , array $ options = array () ) {
8788 try {
8889 $ model_config = $ this ->process_model_config ( $ options );
8990 $ prompt_builder = AiClient::prompt ( $ prompt );
@@ -105,8 +106,8 @@ protected function prompt_builder( $prompt = null, $system_instruction = null, a
105106 }
106107
107108 return $ prompt_builder ;
108- } catch ( \ Exception $ e ) {
109- return new WP_Error ( 'ai_client_error ' , $ e ->getMessage () );
109+ } catch ( Throwable $ t ) {
110+ return new WP_Error ( 'ai_client_error ' , $ t ->getMessage () );
110111 }
111112 }
112113
@@ -123,7 +124,7 @@ protected function get_result( array $response ) {
123124 return new WP_Error ( 'no_choices ' , __ ( 'No choices were returned from the AI provider ' , 'ai ' ) );
124125 }
125126
126- $ results = [] ;
127+ $ results = array () ;
127128 foreach ( $ response as $ choice ) {
128129 $ results [] = $ this ->sanitize_choice ( $ choice );
129130 }
@@ -149,11 +150,11 @@ protected function sanitize_choice( string $choice ): string {
149150 * @since 0.1.0
150151 *
151152 * @param array $options The options to add to the model config.
152- * @return ModelConfig
153+ * @return \WordPress\AiClient\Providers\Models\DTO\ ModelConfig
153154 */
154155 protected function process_model_config ( array $ options ): ModelConfig {
155156 $ schema = ModelConfig::getJsonSchema ()['properties ' ];
156- $ model_config = [] ;
157+ $ model_config = array () ;
157158
158159 foreach ( $ options as $ key => $ value ) {
159160 if ( ! isset ( $ schema [ $ key ] ) ) {
0 commit comments