Changeset 12629
- Timestamp:
- 06/07/2023 08:07:12 AM (2 years ago)
- Location:
- sites/trunk/wordpress.org/public_html/wp-content/plugins/gp-translation-helpers
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
sites/trunk/wordpress.org/public_html/wp-content/plugins/gp-translation-helpers/includes/class-gp-openai-review.php
r12626 r12629 25 25 26 26 if ( empty( trim( $openai_key ) ) ) { 27 return array(); 27 return array( 28 'status' => 404, 29 'error' => 'No OpenAI Key defined', 30 ); 28 31 } 29 $openai_temperature = 0;30 32 31 33 $openai_query .= 'For the english text "' . $original . '", is "' . $translation . '" a correct translation in ' . $language . '?'; … … 55 57 'n' => 1, 56 58 'messages' => $messages, 57 'temperature' => $openai_temperature,58 59 ) 59 60 ), -
sites/trunk/wordpress.org/public_html/wp-content/plugins/gp-translation-helpers/includes/class-gp-translation-helpers.php
r12626 r12629 397 397 gp_enqueue_script( 'gp-comment-feedback-js' ); 398 398 399 $gp_locale = GP_Locales::by_field( 'slug', $translation_set['locale_slug'] ); 399 400 wp_localize_script( 400 401 'gp-comment-feedback-js', … … 404 405 'nonce' => wp_create_nonce( 'gp_comment_feedback' ), 405 406 'locale_slug' => $translation_set['locale_slug'], 407 'language' => $gp_locale ? $gp_locale->english_name : 'Unknown', 408 'has_openai_key' => !! apply_filters( 'gp_get_openai_key', null ), 406 409 'comment_reasons' => Helper_Translation_Discussion::get_comment_reasons( $translation_set['locale_slug'] ), 407 410 ) … … 453 456 454 457 $openai_response = GP_OpenAI_Review::get_openai_review( $original, $translation, $language, $glossary, $is_retry ); 455 458 if ( isset( $openai_response['error'] ) ) { 459 wp_send_json_error( $openai_response ); 460 } 456 461 wp_send_json_success( $openai_response ); 457 462 } -
sites/trunk/wordpress.org/public_html/wp-content/plugins/gp-translation-helpers/js/editor.js
r12626 r12629 26 26 focusedRowId = rowId; 27 27 loadTabsAndDivs( tr ); 28 if ( $gp_ editor_options.can_approve && ( 'waiting' === translation_status || 'fuzzy' === translation_status ) ) {28 if ( $gp_comment_feedback_settings.has_openai_key && $gp_editor_options.can_approve && ( 'waiting' === translation_status || 'fuzzy' === translation_status ) ) { 29 29 fetchOpenAIReviewResponse( rowId, tr, false ); 30 } else { 31 tr.find( '.openai-review' ).hide(); 30 32 } 31 33 } ); … … 274 276 { 275 277 type: 'POST', 276 url: '/wp-content/plugins/wporg-gp-translation-suggestions/ajax-fetch-openai-review.php',278 url: typeof window.useThinFetch !== 'undefined' && window.useThinFetch ? '/wp-content/plugins/wporg-gp-translation-suggestions/ajax-fetch-openai-review.php' : $gp_comment_feedback_settings.url, 277 279 data: data, 278 280 } … … 280 282 function( response ) { 281 283 currentRow.find( '.openai-review .suggestions__loading-indicator' ).hide(); 282 if ( 200 === response.data.status ) {284 if ( response.success ) { 283 285 currentRow.find( '.openai-review .auto-review-result' ).html( '<h4>Review by ChatGPT' ).append( $( '<span/>' ).text( response.data.review + ' (' + response.data.time_taken.toFixed( 2 ) + 's)' ) ); 286 } else if ( 404 === response.data.status ) { 287 currentRow.find( '.openai-review' ).hide(); 288 return; 284 289 } else { 285 290 currentRow.find( '.openai-review .auto-review-result' ).text( 'Error ' + response.data.status + ' : ' + response.data.error ); … … 291 296 /* eslint no-console: ["error", { allow: ["error"] }] */ 292 297 console.error( data ); 293 msg = 'An error has occurred';294 if ( xhr.responseText ) {295 msg += ': ' + xhr.responseText;296 }297 msg += '. Please, take a screenshot of the output in the browser console, send it to the developers, and reload the page to see if it works.';298 $gp.notices.error( msg );299 298 } 300 299 );
Note: See TracChangeset
for help on using the changeset viewer.