|
|
|
@@ -181,6 +181,7 @@ class Groq_AI_Product_Text_Settings_Page extends Groq_AI_Admin_Base {
|
|
|
|
'attributes' => [
|
|
|
|
'attributes' => [
|
|
|
|
'id' => 'groq-ai-model-select',
|
|
|
|
'id' => 'groq-ai-model-select',
|
|
|
|
],
|
|
|
|
],
|
|
|
|
|
|
|
|
'current_provider' => isset( $settings['provider'] ) ? $settings['provider'] : '',
|
|
|
|
]
|
|
|
|
]
|
|
|
|
);
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
|
|
@@ -569,15 +570,50 @@ class Groq_AI_Product_Text_Settings_Page extends Groq_AI_Admin_Base {
|
|
|
|
<?php
|
|
|
|
<?php
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private function render_model_select_field( $field_args ) {
|
|
|
|
public function render_model_select_field( $field_args ) {
|
|
|
|
$name = isset( $field_args['name'] ) ? $field_args['name'] : '';
|
|
|
|
$name = isset( $field_args['name'] ) ? $field_args['name'] : '';
|
|
|
|
$id = isset( $field_args['id'] ) && '' !== $field_args['id'] ? $field_args['id'] : 'groq-ai-model-select';
|
|
|
|
$id = isset( $field_args['id'] ) && '' !== $field_args['id'] ? $field_args['id'] : 'groq-ai-model-select';
|
|
|
|
$current = isset( $field_args['value'] ) ? (string) $field_args['value'] : '';
|
|
|
|
$current = isset( $field_args['value'] ) ? (string) $field_args['value'] : '';
|
|
|
|
$placeholder = __( 'Selecteer eerst een aanbieder', GROQ_AI_PRODUCT_TEXT_DOMAIN );
|
|
|
|
$placeholder = __( 'Selecteer eerst een aanbieder', GROQ_AI_PRODUCT_TEXT_DOMAIN );
|
|
|
|
|
|
|
|
$current_provider = isset( $field_args['current_provider'] ) ? sanitize_key( (string) $field_args['current_provider'] ) : '';
|
|
|
|
|
|
|
|
$provider = '' !== $current_provider ? $this->provider_manager->get_provider( $current_provider ) : null;
|
|
|
|
|
|
|
|
$models = [];
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if ( $provider ) {
|
|
|
|
|
|
|
|
$models = $this->prepare_models_list_for_provider( $current_provider, $this->plugin->get_cached_models_for_provider( $current_provider ) );
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if ( empty( $models ) ) {
|
|
|
|
|
|
|
|
$models = $this->prepare_models_list_for_provider( $current_provider, $provider->get_available_models() );
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
$placeholder = __( 'Selecteer een model', GROQ_AI_PRODUCT_TEXT_DOMAIN );
|
|
|
|
|
|
|
|
} elseif ( '' !== $current_provider ) {
|
|
|
|
|
|
|
|
$placeholder = __( 'Geen modellen gevonden. Gebruik "Live modellen ophalen".', GROQ_AI_PRODUCT_TEXT_DOMAIN );
|
|
|
|
|
|
|
|
}
|
|
|
|
?>
|
|
|
|
?>
|
|
|
|
<div class="groq-ai-model-field">
|
|
|
|
<div class="groq-ai-model-field">
|
|
|
|
<select id="<?php echo esc_attr( $id ); ?>" name="<?php echo esc_attr( $name ); ?>" data-current-model="<?php echo esc_attr( $current ); ?>">
|
|
|
|
<select id="<?php echo esc_attr( $id ); ?>" name="<?php echo esc_attr( $name ); ?>" data-current-model="<?php echo esc_attr( $current ); ?>">
|
|
|
|
<option value="" selected="selected"><?php echo esc_html( $placeholder ); ?></option>
|
|
|
|
<option value=""><?php echo esc_html( $placeholder ); ?></option>
|
|
|
|
|
|
|
|
<?php
|
|
|
|
|
|
|
|
if ( ! empty( $models ) ) :
|
|
|
|
|
|
|
|
$has_current = in_array( $current, $models, true );
|
|
|
|
|
|
|
|
foreach ( $models as $model ) :
|
|
|
|
|
|
|
|
?>
|
|
|
|
|
|
|
|
<option value="<?php echo esc_attr( $model ); ?>" <?php selected( $current, $model ); ?>><?php echo esc_html( $model ); ?></option>
|
|
|
|
|
|
|
|
<?php
|
|
|
|
|
|
|
|
endforeach;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if ( $current && ! $has_current ) :
|
|
|
|
|
|
|
|
?>
|
|
|
|
|
|
|
|
<option value="<?php echo esc_attr( $current ); ?>" selected="selected"><?php echo esc_html( $current ); ?></option>
|
|
|
|
|
|
|
|
<?php
|
|
|
|
|
|
|
|
endif;
|
|
|
|
|
|
|
|
elseif ( $current ) :
|
|
|
|
|
|
|
|
?>
|
|
|
|
|
|
|
|
<option value="<?php echo esc_attr( $current ); ?>" selected="selected"><?php echo esc_html( $current ); ?></option>
|
|
|
|
|
|
|
|
<?php
|
|
|
|
|
|
|
|
endif;
|
|
|
|
|
|
|
|
?>
|
|
|
|
</select>
|
|
|
|
</select>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
<button type="button" class="button" id="groq-ai-refresh-models"><?php esc_html_e( 'Live modellen ophalen', GROQ_AI_PRODUCT_TEXT_DOMAIN ); ?></button>
|
|
|
|
<button type="button" class="button" id="groq-ai-refresh-models"><?php esc_html_e( 'Live modellen ophalen', GROQ_AI_PRODUCT_TEXT_DOMAIN ); ?></button>
|
|
|
|
@@ -865,8 +901,11 @@ class Groq_AI_Product_Text_Settings_Page extends Groq_AI_Admin_Base {
|
|
|
|
|
|
|
|
|
|
|
|
foreach ( $this->provider_manager->get_providers() as $provider ) {
|
|
|
|
foreach ( $this->provider_manager->get_providers() as $provider ) {
|
|
|
|
$provider_key = $provider->get_key();
|
|
|
|
$provider_key = $provider->get_key();
|
|
|
|
$cached_models = $this->plugin->get_cached_models_for_provider( $provider_key );
|
|
|
|
$cached_models = $this->prepare_models_list_for_provider( $provider_key, $this->plugin->get_cached_models_for_provider( $provider_key ) );
|
|
|
|
$cached_models = Groq_AI_Model_Exclusions::filter_models( $provider_key, $cached_models );
|
|
|
|
|
|
|
|
|
|
|
|
if ( empty( $cached_models ) ) {
|
|
|
|
|
|
|
|
$cached_models = $this->prepare_models_list_for_provider( $provider_key, $provider->get_available_models() );
|
|
|
|
|
|
|
|
}
|
|
|
|
$data['providers'][ $provider_key ] = [
|
|
|
|
$data['providers'][ $provider_key ] = [
|
|
|
|
'default_label' => sprintf( __( 'Gebruik standaardmodel (%s)', GROQ_AI_PRODUCT_TEXT_DOMAIN ), $provider->get_default_model() ),
|
|
|
|
'default_label' => sprintf( __( 'Gebruik standaardmodel (%s)', GROQ_AI_PRODUCT_TEXT_DOMAIN ), $provider->get_default_model() ),
|
|
|
|
'models' => $cached_models,
|
|
|
|
'models' => $cached_models,
|
|
|
|
@@ -878,6 +917,18 @@ class Groq_AI_Product_Text_Settings_Page extends Groq_AI_Admin_Base {
|
|
|
|
wp_localize_script( 'groq-ai-settings', 'GroqAISettingsData', $data );
|
|
|
|
wp_localize_script( 'groq-ai-settings', 'GroqAISettingsData', $data );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private function prepare_models_list_for_provider( $provider_key, $models ) {
|
|
|
|
|
|
|
|
$list = Groq_AI_Model_Exclusions::filter_models( $provider_key, $models );
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if ( empty( $list ) ) {
|
|
|
|
|
|
|
|
return [];
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
sort( $list, SORT_NATURAL | SORT_FLAG_CASE );
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return $list;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public function handle_google_oauth_start() {
|
|
|
|
public function handle_google_oauth_start() {
|
|
|
|
if ( ! current_user_can( 'manage_options' ) ) {
|
|
|
|
if ( ! current_user_can( 'manage_options' ) ) {
|
|
|
|
wp_die( esc_html__( 'Je hebt geen toestemming om deze actie uit te voeren.', GROQ_AI_PRODUCT_TEXT_DOMAIN ), '', [ 'response' => 403 ] );
|
|
|
|
wp_die( esc_html__( 'Je hebt geen toestemming om deze actie uit te voeren.', GROQ_AI_PRODUCT_TEXT_DOMAIN ), '', [ 'response' => 403 ] );
|
|
|
|
|