Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix errors with the get_formatted_latest_response method #466

Merged
merged 1 commit into from
May 26, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion includes/Classifai/Providers/OpenAI/ChatGPT.php
Original file line number Diff line number Diff line change
Expand Up @@ -374,7 +374,7 @@ public function get_provider_debug_information( $settings = null, $configured =
__( 'Generate titles', 'classifai' ) => $enable_titles ? __( 'yes', 'classifai' ) : __( 'no', 'classifai' ),
__( 'Allowed roles (titles)', 'classifai' ) => implode( ', ', $settings['title_roles'] ?? [] ),
__( 'Number of titles', 'classifai' ) => absint( $settings['number_titles'] ?? 1 ),
__( 'Latest response', 'classifai' ) => $this->get_formatted_latest_response( 'classifai_openai_chatgpt_latest_response' ),
__( 'Latest response', 'classifai' ) => $this->get_formatted_latest_response( get_transient( 'classifai_openai_chatgpt_latest_response' ) ),
];
}

Expand Down
2 changes: 1 addition & 1 deletion includes/Classifai/Providers/OpenAI/DallE.php
Original file line number Diff line number Diff line change
Expand Up @@ -333,7 +333,7 @@ public function get_provider_debug_information( $settings = null, $configured =
__( 'Allowed roles', 'classifai' ) => implode( ', ', $settings['roles'] ?? [] ),
__( 'Number of images', 'classifai' ) => absint( $settings['number'] ?? 1 ),
__( 'Image size', 'classifai' ) => sanitize_text_field( $settings['size'] ?? '1024x1024' ),
__( 'Latest response', 'classifai' ) => $this->get_formatted_latest_response( 'classifai_openai_dalle_latest_response' ),
__( 'Latest response', 'classifai' ) => $this->get_formatted_latest_response( get_transient( 'classifai_openai_dalle_latest_response' ) ),
];
}

Expand Down
2 changes: 1 addition & 1 deletion includes/Classifai/Providers/OpenAI/Embeddings.php
Original file line number Diff line number Diff line change
Expand Up @@ -314,7 +314,7 @@ public function get_provider_debug_information( $settings = null, $configured =
__( 'Post statuses', 'classifai' ) => implode( ', ', $settings['post_statuses'] ?? [] ),
__( 'Taxonomies', 'classifai' ) => implode( ', ', $settings['taxonomies'] ?? [] ),
__( 'Number of terms', 'classifai' ) => $settings['number'] ?? 1,
__( 'Latest response', 'classifai' ) => $this->get_formatted_latest_response( 'classifai_openai_embeddings_latest_response' ),
__( 'Latest response', 'classifai' ) => $this->get_formatted_latest_response( get_transient( 'classifai_openai_embeddings_latest_response' ) ),
];
}

Expand Down
2 changes: 1 addition & 1 deletion includes/Classifai/Providers/OpenAI/Whisper.php
Original file line number Diff line number Diff line change
Expand Up @@ -328,7 +328,7 @@ public function get_provider_debug_information( $settings = null, $configured =
__( 'Authenticated', 'classifai' ) => $authenticated ? __( 'yes', 'classifai' ) : __( 'no', 'classifai' ),
__( 'Generate transcripts', 'classifai' ) => $enable_transcript ? __( 'yes', 'classifai' ) : __( 'no', 'classifai' ),
__( 'Allowed roles', 'classifai' ) => implode( ', ', $settings['roles'] ?? [] ),
__( 'Latest response', 'classifai' ) => $this->get_formatted_latest_response( 'classifai_openai_whisper_latest_response' ),
__( 'Latest response', 'classifai' ) => $this->get_formatted_latest_response( get_transient( 'classifai_openai_whisper_latest_response' ) ),
];
}

Expand Down
4 changes: 2 additions & 2 deletions includes/Classifai/Providers/Provider.php
Original file line number Diff line number Diff line change
Expand Up @@ -397,11 +397,11 @@ public function rest_endpoint_callback( $post_id, $route_to_call, $args = [] ) {
/**
* Format the result of most recent request.
*
* @param string $data Response data to format.
* @param array|WP_Error $data Response data to format.
*
* @return string
*/
protected function get_formatted_latest_response( string $data = '' ) {
protected function get_formatted_latest_response( $data ) {
if ( ! $data ) {
return __( 'N/A', 'classifai' );
}
Expand Down
8 changes: 3 additions & 5 deletions includes/Classifai/Providers/Watson/NLU.php
Original file line number Diff line number Diff line change
Expand Up @@ -758,20 +758,18 @@ function( $post_type ) use ( $settings_post_types ) {
__( 'API username', 'classifai' ) => $credentials['watson_username'] ?? '',
__( 'Post types', 'classifai' ) => implode( ', ', $post_types ),
__( 'Features', 'classifai' ) => preg_replace( '/,"/', ', "', wp_json_encode( $settings['features'] ?? '' ) ),
__( 'Latest response', 'classifai' ) => $this->get_formatted_latest_response(),
__( 'Latest response', 'classifai' ) => $this->get_formatted_latest_response( get_transient( 'classifai_watson_nlu_latest_response' ) ),
];
}

/**
* Format the result of most recent request.
*
* @param string $data Response data to format.
* @param array|WP_Error $data Response data to format.
*
* @return string
*/
protected function get_formatted_latest_response( string $data = '' ) {
$data = get_transient( 'classifai_watson_nlu_latest_response' );

protected function get_formatted_latest_response( $data ) {
if ( ! $data ) {
return __( 'N/A', 'classifai' );
}
Expand Down