Skip to content

Commit af113d0

Browse files
feat: user can select open ai model per import (#1134)
1 parent 1f2d913 commit af113d0

File tree

4 files changed

+997
-244
lines changed

4 files changed

+997
-244
lines changed

includes/admin/feedzy-rss-feeds-actions.php

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -493,13 +493,25 @@ private function chat_gpt_rewrite() {
493493
$content = wp_strip_all_tags( $content );
494494
$content = substr( $content, 0, apply_filters( 'feedzy_chat_gpt_content_limit', 3000 ) );
495495
$prompt_content = $this->current_job->data->ChatGPT;
496-
$ai_provider = 'openai';
496+
497+
$additional_data = array(
498+
'ai_provider' => 'openai',
499+
);
500+
497501
if ( isset( $this->current_job->data ) && isset( $this->current_job->data->aiProvider ) ) {
498-
$ai_provider = $this->current_job->data->aiProvider;
502+
$additional_data['ai_provider'] = $this->current_job->data->aiProvider;
499503
}
504+
505+
if (
506+
'openai' === $additional_data['ai_provider'] &&
507+
isset( $this->current_job->data ) && isset( $this->current_job->data->aiModel )
508+
) {
509+
$additional_data['ai_model'] = $this->current_job->data->aiModel;
510+
}
511+
500512
$content = str_replace( array( '{content}' ), array( $content ), $prompt_content );
501513
$openai = new \Feedzy_Rss_Feeds_Pro_Openai();
502-
$rewrite_content = $openai->call_api( $this->settings, $content, '', array( 'ai_provider' => $ai_provider ) );
514+
$rewrite_content = $openai->call_api( $this->settings, $content, '', $additional_data );
503515
// Replace prompt content string for specific cases.
504516
$rewrite_content = str_replace( explode( '{content}', $prompt_content ), '', trim( $rewrite_content, '"' ) );
505517
return $rewrite_content;

includes/admin/feedzy-rss-feeds-admin.php

Lines changed: 29 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -244,16 +244,39 @@ public function enqueue_styles_admin() {
244244
$asset_file = include FEEDZY_ABSPATH . '/build/action-popup/index.asset.php';
245245
wp_enqueue_script( $this->plugin_name . '_action_popup', FEEDZY_ABSURL . 'build/action-popup/index.js', array_merge( $asset_file['dependencies'], array( 'wp-editor', 'wp-api' ) ), $asset_file['version'], true );
246246

247+
$openai_model = '';
248+
$open_router_model = '';
249+
$integration_settings = get_option( 'feedzy-rss-feeds-settings', array() );
250+
251+
$all_open_ai_models = apply_filters( 'feedzy_openai_models', array() );
252+
$deprecated_open_ai_models = apply_filters( 'feedzy_openai_deprecated_models', array() );
253+
$active_open_ai_models = array_values( array_diff( $all_open_ai_models, $deprecated_open_ai_models ) );
254+
255+
if ( ! empty( $integration_settings['openai_api_model'] ) ) {
256+
$openai_model = $integration_settings['openai_api_model'];
257+
}
258+
259+
if ( ! empty( $integration_settings['openrouter_api_model'] ) ) {
260+
$open_router_model = $integration_settings['openrouter_api_model'];
261+
}
262+
247263
wp_localize_script(
248264
$this->plugin_name . '_action_popup',
249265
'feedzyData',
250266
array(
251-
'isPro' => feedzy_is_pro(),
252-
'isBusinessPlan' => apply_filters( 'feedzy_is_license_of_type', false, 'business' ),
253-
'isAgencyPlan' => apply_filters( 'feedzy_is_license_of_type', false, 'agency' ),
254-
'apiLicenseStatus' => $this->api_license_status(),
255-
'isHighPrivileges' => current_user_can( 'manage_options' ),
256-
'languageList' => $this->get_lang_list(),
267+
'isPro' => feedzy_is_pro(),
268+
'isBusinessPlan' => apply_filters( 'feedzy_is_license_of_type', false, 'business' ),
269+
'isAgencyPlan' => apply_filters( 'feedzy_is_license_of_type', false, 'agency' ),
270+
'apiLicenseStatus' => $this->api_license_status(),
271+
'isHighPrivileges' => current_user_can( 'manage_options' ),
272+
'languageList' => $this->get_lang_list(),
273+
'integrationSettings' => get_option( 'feedzy-rss-feeds-settings' ),
274+
'integrations' => array(
275+
'openAIModel' => $openai_model,
276+
'openRouterModel' => $open_router_model,
277+
),
278+
'activeOpenAIModels' => $active_open_ai_models,
279+
'deprecatedOpenAIModels' => $deprecated_open_ai_models,
257280
)
258281
);
259282

0 commit comments

Comments
 (0)