feat: 实现多 API 管理系统
- 为每个 AI 提供商添加独立的配置(API 密钥、端点、模型) - 新增 argon_get_ai_provider_config() 辅助函数获取提供商配置 - 更新设置页,为 10 个提供商分别显示配置表单 - 添加密码显示/隐藏切换按钮 - 每个提供商独立的模型刷新按钮 - 切换服务商时自动显示对应配置 - 更新所有 API 调用函数使用新配置结构 - 更新设置保存逻辑,保存所有提供商配置 - 支持同时配置多个 AI 服务,灵活切换使用
This commit is contained in:
153
functions.php
153
functions.php
@@ -6459,6 +6459,23 @@ function argon_get_ai_summary($post_id) {
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取指定 AI 提供商的配置
|
||||
* @param string $provider 提供商名称
|
||||
* @return array ['api_key' => string, 'api_endpoint' => string, 'model' => string]
|
||||
*/
|
||||
function argon_get_ai_provider_config($provider = '') {
|
||||
if (empty($provider)) {
|
||||
$provider = get_option('argon_ai_summary_provider', 'openai');
|
||||
}
|
||||
|
||||
return [
|
||||
'api_key' => get_option("argon_ai_{$provider}_api_key", ''),
|
||||
'api_endpoint' => get_option("argon_ai_{$provider}_api_endpoint", ''),
|
||||
'model' => get_option("argon_ai_{$provider}_model", '')
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* 生成 AI 摘要
|
||||
* @param WP_Post $post 文章对象
|
||||
@@ -6466,7 +6483,8 @@ function argon_get_ai_summary($post_id) {
|
||||
*/
|
||||
function argon_generate_ai_summary($post) {
|
||||
$provider = get_option('argon_ai_summary_provider', 'openai');
|
||||
$api_key = get_option('argon_ai_summary_api_key', '');
|
||||
$config = argon_get_ai_provider_config($provider);
|
||||
$api_key = $config['api_key'];
|
||||
|
||||
if (empty($api_key)) {
|
||||
return false;
|
||||
@@ -6510,15 +6528,11 @@ function argon_generate_ai_summary($post) {
|
||||
* 调用 OpenAI API
|
||||
*/
|
||||
function argon_call_openai_api($api_key, $prompt, $content) {
|
||||
$endpoint = get_option('argon_ai_summary_api_endpoint', '');
|
||||
if (empty($endpoint)) {
|
||||
$endpoint = 'https://api.openai.com/v1/chat/completions';
|
||||
}
|
||||
$provider = 'openai';
|
||||
$config = argon_get_ai_provider_config($provider);
|
||||
|
||||
$model = get_option('argon_ai_summary_model', '');
|
||||
if (empty($model)) {
|
||||
$model = 'gpt-4o-mini';
|
||||
}
|
||||
$endpoint = !empty($config['api_endpoint']) ? $config['api_endpoint'] : 'https://api.openai.com/v1/chat/completions';
|
||||
$model = !empty($config['model']) ? $config['model'] : 'gpt-4o-mini';
|
||||
|
||||
$data = [
|
||||
'model' => $model,
|
||||
@@ -6556,15 +6570,11 @@ function argon_call_openai_api($api_key, $prompt, $content) {
|
||||
* 调用 Anthropic Claude API
|
||||
*/
|
||||
function argon_call_anthropic_api($api_key, $prompt, $content) {
|
||||
$endpoint = get_option('argon_ai_summary_api_endpoint', '');
|
||||
if (empty($endpoint)) {
|
||||
$endpoint = 'https://api.anthropic.com/v1/messages';
|
||||
}
|
||||
$provider = 'anthropic';
|
||||
$config = argon_get_ai_provider_config($provider);
|
||||
|
||||
$model = get_option('argon_ai_summary_model', '');
|
||||
if (empty($model)) {
|
||||
$model = 'claude-3-5-haiku-20241022';
|
||||
}
|
||||
$endpoint = !empty($config['api_endpoint']) ? $config['api_endpoint'] : 'https://api.anthropic.com/v1/messages';
|
||||
$model = !empty($config['model']) ? $config['model'] : 'claude-3-5-haiku-20241022';
|
||||
|
||||
$data = [
|
||||
'model' => $model,
|
||||
@@ -6602,15 +6612,11 @@ function argon_call_anthropic_api($api_key, $prompt, $content) {
|
||||
* 调用通义千问 API
|
||||
*/
|
||||
function argon_call_qianwen_api($api_key, $prompt, $content) {
|
||||
$endpoint = get_option('argon_ai_summary_api_endpoint', '');
|
||||
if (empty($endpoint)) {
|
||||
$endpoint = 'https://dashscope.aliyuncs.com/api/v1/services/aigc/text-generation/generation';
|
||||
}
|
||||
$provider = \'qianwen\';
|
||||
$config = argon_get_ai_provider_config($provider);
|
||||
|
||||
$model = get_option('argon_ai_summary_model', '');
|
||||
if (empty($model)) {
|
||||
$model = 'qwen-turbo';
|
||||
}
|
||||
$endpoint = !empty($config[\'api_endpoint\']) ? $config[\'api_endpoint\'] : \'https://dashscope.aliyuncs.com/api/v1/services/aigc/text-generation/generation\';
|
||||
$model = !empty($config[\'model\']) ? $config[\'model\'] : \'qwen-turbo\';
|
||||
|
||||
$data = [
|
||||
'model' => $model,
|
||||
@@ -6652,11 +6658,11 @@ function argon_call_qianwen_api($api_key, $prompt, $content) {
|
||||
* 调用文心一言 API
|
||||
*/
|
||||
function argon_call_wenxin_api($api_key, $prompt, $content) {
|
||||
$endpoint = get_option('argon_ai_summary_api_endpoint', '');
|
||||
$model = get_option('argon_ai_summary_model', '');
|
||||
if (empty($model)) {
|
||||
$model = 'ernie-4.0-turbo-8k';
|
||||
}
|
||||
$provider = 'wenxin';
|
||||
$config = argon_get_ai_provider_config($provider);
|
||||
|
||||
$model = !empty($config['model']) ? $config['model'] : 'ernie-4.0-turbo-8k';
|
||||
$endpoint = !empty($config['api_endpoint']) ? $config['api_endpoint'] : '';
|
||||
|
||||
if (empty($endpoint)) {
|
||||
// 文心一言需要先获取 access_token
|
||||
@@ -6695,15 +6701,11 @@ function argon_call_wenxin_api($api_key, $prompt, $content) {
|
||||
* 调用 Kimi (Moonshot) API
|
||||
*/
|
||||
function argon_call_kimi_api($api_key, $prompt, $content) {
|
||||
$endpoint = get_option('argon_ai_summary_api_endpoint', '');
|
||||
if (empty($endpoint)) {
|
||||
$endpoint = 'https://api.moonshot.cn/v1/chat/completions';
|
||||
}
|
||||
$provider = \'kimi\';
|
||||
$config = argon_get_ai_provider_config($provider);
|
||||
|
||||
$model = get_option('argon_ai_summary_model', '');
|
||||
if (empty($model)) {
|
||||
$model = 'moonshot-v1-8k';
|
||||
}
|
||||
$endpoint = !empty($config[\'api_endpoint\']) ? $config[\'api_endpoint\'] : \'https://api.moonshot.cn/v1/chat/completions\';
|
||||
$model = !empty($config[\'model\']) ? $config[\'model\'] : \'moonshot-v1-8k\';
|
||||
|
||||
$data = [
|
||||
'model' => $model,
|
||||
@@ -6741,15 +6743,11 @@ function argon_call_kimi_api($api_key, $prompt, $content) {
|
||||
* 调用智谱 AI API
|
||||
*/
|
||||
function argon_call_zhipu_api($api_key, $prompt, $content) {
|
||||
$endpoint = get_option('argon_ai_summary_api_endpoint', '');
|
||||
if (empty($endpoint)) {
|
||||
$endpoint = 'https://open.bigmodel.cn/api/paas/v4/chat/completions';
|
||||
}
|
||||
$provider = \'zhipu\';
|
||||
$config = argon_get_ai_provider_config($provider);
|
||||
|
||||
$model = get_option('argon_ai_summary_model', '');
|
||||
if (empty($model)) {
|
||||
$model = 'glm-4-flash';
|
||||
}
|
||||
$endpoint = !empty($config[\'api_endpoint\']) ? $config[\'api_endpoint\'] : \'https://open.bigmodel.cn/api/paas/v4/chat/completions\';
|
||||
$model = !empty($config[\'model\']) ? $config[\'model\'] : \'glm-4-flash\';
|
||||
|
||||
$data = [
|
||||
'model' => $model,
|
||||
@@ -6907,15 +6905,11 @@ add_action('wp_ajax_nopriv_argon_check_ai_summary', 'argon_check_ai_summary');
|
||||
* 调用 DeepSeek API
|
||||
*/
|
||||
function argon_call_deepseek_api($api_key, $prompt, $content) {
|
||||
$endpoint = get_option('argon_ai_summary_api_endpoint', '');
|
||||
if (empty($endpoint)) {
|
||||
$endpoint = 'https://api.deepseek.com/v1/chat/completions';
|
||||
}
|
||||
$provider = \'deepseek\';
|
||||
$config = argon_get_ai_provider_config($provider);
|
||||
|
||||
$model = get_option('argon_ai_summary_model', '');
|
||||
if (empty($model)) {
|
||||
$model = 'deepseek-chat';
|
||||
}
|
||||
$endpoint = !empty($config[\'api_endpoint\']) ? $config[\'api_endpoint\'] : \'https://api.deepseek.com/v1/chat/completions\';
|
||||
$model = !empty($config[\'model\']) ? $config[\'model\'] : \'deepseek-chat\';
|
||||
|
||||
$data = [
|
||||
'model' => $model,
|
||||
@@ -6954,15 +6948,11 @@ function argon_call_deepseek_api($api_key, $prompt, $content) {
|
||||
* 调用小米 Mimo API
|
||||
*/
|
||||
function argon_call_xiaomi_api($api_key, $prompt, $content) {
|
||||
$endpoint = get_option('argon_ai_summary_api_endpoint', '');
|
||||
if (empty($endpoint)) {
|
||||
$endpoint = 'https://api.mimo.xiaomi.com/v1/chat/completions';
|
||||
}
|
||||
$provider = \'xiaomi\';
|
||||
$config = argon_get_ai_provider_config($provider);
|
||||
|
||||
$model = get_option('argon_ai_summary_model', '');
|
||||
if (empty($model)) {
|
||||
$model = 'MiMo-V2-Flash';
|
||||
}
|
||||
$endpoint = !empty($config[\'api_endpoint\']) ? $config[\'api_endpoint\'] : \'https://api.mimo.xiaomi.com/v1/chat/completions\';
|
||||
$model = !empty($config[\'model\']) ? $config[\'model\'] : \'MiMo-V2-Flash\';
|
||||
|
||||
$data = [
|
||||
'model' => $model,
|
||||
@@ -7001,15 +6991,11 @@ function argon_call_xiaomi_api($api_key, $prompt, $content) {
|
||||
* 调用豆包 (火山引擎) API
|
||||
*/
|
||||
function argon_call_doubao_api($api_key, $prompt, $content) {
|
||||
$endpoint = get_option('argon_ai_summary_api_endpoint', '');
|
||||
if (empty($endpoint)) {
|
||||
$endpoint = 'https://ark.cn-beijing.volces.com/api/v3/chat/completions';
|
||||
}
|
||||
$provider = \'doubao\';
|
||||
$config = argon_get_ai_provider_config($provider);
|
||||
|
||||
$model = get_option('argon_ai_summary_model', '');
|
||||
if (empty($model)) {
|
||||
$model = 'doubao-pro-32k';
|
||||
}
|
||||
$endpoint = !empty($config[\'api_endpoint\']) ? $config[\'api_endpoint\'] : \'https://ark.cn-beijing.volces.com/api/v3/chat/completions\';
|
||||
$model = !empty($config[\'model\']) ? $config[\'model\'] : \'doubao-pro-32k\';
|
||||
|
||||
$data = [
|
||||
'model' => $model,
|
||||
@@ -7048,15 +7034,11 @@ function argon_call_doubao_api($api_key, $prompt, $content) {
|
||||
* 调用硅基流动 (SiliconFlow) API
|
||||
*/
|
||||
function argon_call_siliconflow_api($api_key, $prompt, $content) {
|
||||
$endpoint = get_option('argon_ai_summary_api_endpoint', '');
|
||||
if (empty($endpoint)) {
|
||||
$endpoint = 'https://api.siliconflow.cn/v1/chat/completions';
|
||||
}
|
||||
$provider = \'siliconflow\';
|
||||
$config = argon_get_ai_provider_config($provider);
|
||||
|
||||
$model = get_option('argon_ai_summary_model', '');
|
||||
if (empty($model)) {
|
||||
$model = 'Qwen/Qwen2.5-7B-Instruct';
|
||||
}
|
||||
$endpoint = !empty($config[\'api_endpoint\']) ? $config[\'api_endpoint\'] : \'https://api.siliconflow.cn/v1/chat/completions\';
|
||||
$model = !empty($config[\'model\']) ? $config[\'model\'] : \'Qwen/Qwen2.5-7B-Instruct\';
|
||||
|
||||
$data = [
|
||||
'model' => $model,
|
||||
@@ -7798,8 +7780,9 @@ function argon_detect_spam_comment_sync($comment) {
|
||||
|
||||
// 获取 AI 配置
|
||||
$provider = get_option('argon_ai_summary_provider', 'openai');
|
||||
$api_key = get_option('argon_ai_summary_api_key', '');
|
||||
$model = get_option('argon_ai_summary_model', '');
|
||||
$config = argon_get_ai_provider_config($provider);
|
||||
$api_key = $config['api_key'];
|
||||
$model = $config['model'];
|
||||
$prompt_mode = get_option('argon_comment_spam_detection_prompt_mode', 'standard');
|
||||
$custom_prompt = get_option('argon_comment_spam_detection_prompt', '');
|
||||
|
||||
@@ -8067,8 +8050,9 @@ function argon_ai_learn_keywords($comment_id, $admin_decision) {
|
||||
function argon_extract_keywords_from_comment($comment, $is_spam) {
|
||||
// 获取 AI 配置
|
||||
$provider = get_option('argon_ai_summary_provider', 'openai');
|
||||
$api_key = get_option('argon_ai_summary_api_key', '');
|
||||
$model = get_option('argon_ai_summary_model', '');
|
||||
$config = argon_get_ai_provider_config($provider);
|
||||
$api_key = $config['api_key'];
|
||||
$model = $config['model'];
|
||||
|
||||
if (empty($api_key)) {
|
||||
return [];
|
||||
@@ -8811,8 +8795,9 @@ add_action('wp_ajax_argon_spam_detection_scan', 'argon_spam_detection_scan');
|
||||
function argon_batch_detect_spam_comments($comments_data) {
|
||||
// 获取 AI 配置
|
||||
$provider = get_option('argon_ai_summary_provider', 'openai');
|
||||
$api_key = get_option('argon_ai_summary_api_key', '');
|
||||
$model = get_option('argon_ai_summary_model', '');
|
||||
$config = argon_get_ai_provider_config($provider);
|
||||
$api_key = $config['api_key'];
|
||||
$model = $config['model'];
|
||||
$prompt = get_option('argon_comment_spam_detection_prompt', '');
|
||||
|
||||
if (empty($api_key)) {
|
||||
|
||||
150
settings.php
150
settings.php
@@ -2002,7 +2002,7 @@ function themeoptions_page(){
|
||||
<tr>
|
||||
<th><label><?php _e('AI 服务商', 'argon');?></label></th>
|
||||
<td>
|
||||
<select name="argon_ai_summary_provider">
|
||||
<select name="argon_ai_summary_provider" id="argon_ai_summary_provider">
|
||||
<?php $argon_ai_summary_provider = get_option('argon_ai_summary_provider', 'openai'); ?>
|
||||
<option value="openai" <?php if ($argon_ai_summary_provider=='openai'){echo 'selected';} ?>>OpenAI (ChatGPT)</option>
|
||||
<option value="anthropic" <?php if ($argon_ai_summary_provider=='anthropic'){echo 'selected';} ?>>Anthropic (Claude)</option>
|
||||
@@ -2015,49 +2015,83 @@ function themeoptions_page(){
|
||||
<option value="zhipu" <?php if ($argon_ai_summary_provider=='zhipu'){echo 'selected';} ?>><?php _e('智谱 AI (GLM)', 'argon');?></option>
|
||||
<option value="siliconflow" <?php if ($argon_ai_summary_provider=='siliconflow'){echo 'selected';} ?>><?php _e('硅基流动 (SiliconFlow)', 'argon');?></option>
|
||||
</select>
|
||||
<p class="description"><?php _e('选择 AI 服务提供商', 'argon');?></p>
|
||||
<p class="description"><?php _e('选择当前使用的 AI 服务提供商', 'argon');?></p>
|
||||
</td>
|
||||
</tr>
|
||||
|
||||
<tr>
|
||||
<th><label><?php _e('API 密钥', 'argon');?></label></th>
|
||||
<td>
|
||||
<input type="password" class="regular-text" name="argon_ai_summary_api_key" value="<?php echo get_option('argon_ai_summary_api_key', ''); ?>" placeholder="sk-..."/>
|
||||
<p class="description"><?php _e('填写对应服务商的 API Key', 'argon');?></p>
|
||||
</td>
|
||||
</tr>
|
||||
<?php
|
||||
// 获取所有提供商的配置
|
||||
$providers = [
|
||||
'openai' => 'OpenAI (ChatGPT)',
|
||||
'anthropic' => 'Anthropic (Claude)',
|
||||
'deepseek' => 'DeepSeek',
|
||||
'xiaomi' => __('小米 Mimo', 'argon'),
|
||||
'qianwen' => __('通义千问', 'argon'),
|
||||
'wenxin' => __('文心一言', 'argon'),
|
||||
'doubao' => __('豆包 (火山引擎)', 'argon'),
|
||||
'kimi' => 'Kimi (Moonshot)',
|
||||
'zhipu' => __('智谱 AI (GLM)', 'argon'),
|
||||
'siliconflow' => __('硅基流动 (SiliconFlow)', 'argon')
|
||||
];
|
||||
|
||||
<tr>
|
||||
<th><label><?php _e('API 端点 (可选)', 'argon');?></label></th>
|
||||
<td>
|
||||
<input type="text" class="regular-text" name="argon_ai_summary_api_endpoint" value="<?php echo get_option('argon_ai_summary_api_endpoint', ''); ?>" placeholder="<?php _e('留空使用默认端点', 'argon');?>"/>
|
||||
<p class="description"><?php _e('自定义 API 端点地址,留空则使用官方默认地址。适用于使用代理或第三方兼容接口。', 'argon');?></p>
|
||||
</td>
|
||||
</tr>
|
||||
$current_provider = get_option('argon_ai_summary_provider', 'openai');
|
||||
|
||||
<tr>
|
||||
<th><label><?php _e('AI 模型', 'argon');?></label></th>
|
||||
foreach ($providers as $provider_key => $provider_name) {
|
||||
$is_current = ($provider_key === $current_provider);
|
||||
$display_style = $is_current ? '' : 'display:none;';
|
||||
|
||||
// 获取该提供商的配置
|
||||
$api_key = get_option("argon_ai_{$provider_key}_api_key", '');
|
||||
$api_endpoint = get_option("argon_ai_{$provider_key}_api_endpoint", '');
|
||||
$model = get_option("argon_ai_{$provider_key}_model", '');
|
||||
?>
|
||||
|
||||
<tr class="argon-provider-config" data-provider="<?php echo esc_attr($provider_key); ?>" style="<?php echo $display_style; ?>">
|
||||
<th><label><?php echo esc_html($provider_name); ?> - <?php _e('API 密钥', 'argon');?></label></th>
|
||||
<td>
|
||||
<select name="argon_ai_summary_model" id="argon_ai_summary_model" class="regular-text">
|
||||
<option value=""><?php _e('使用默认模型', 'argon');?></option>
|
||||
<?php
|
||||
$current_model = get_option('argon_ai_summary_model', '');
|
||||
if (!empty($current_model)) {
|
||||
echo '<option value="' . esc_attr($current_model) . '" selected>' . esc_html($current_model) . '</option>';
|
||||
}
|
||||
?>
|
||||
</select>
|
||||
<button type="button" class="button" id="argon_refresh_models" style="margin-left: 10px;">
|
||||
<span class="dashicons dashicons-update" style="margin-top: 3px;"></span> <?php _e('刷新模型列表', 'argon');?>
|
||||
<input type="password" class="regular-text" name="argon_ai_<?php echo esc_attr($provider_key); ?>_api_key" value="<?php echo esc_attr($api_key); ?>" placeholder="sk-..."/>
|
||||
<button type="button" class="button argon-toggle-password" style="margin-left: 5px;">
|
||||
<span class="dashicons dashicons-visibility"></span>
|
||||
</button>
|
||||
<span id="argon_model_loading" style="display:none;margin-left:10px;color:#666;">
|
||||
<p class="description"><?php printf(__('填写 %s 的 API Key', 'argon'), $provider_name); ?></p>
|
||||
</td>
|
||||
</tr>
|
||||
|
||||
<tr class="argon-provider-config" data-provider="<?php echo esc_attr($provider_key); ?>" style="<?php echo $display_style; ?>">
|
||||
<th><label><?php echo esc_html($provider_name); ?> - <?php _e('API 端点', 'argon');?></label></th>
|
||||
<td>
|
||||
<input type="text" class="regular-text" name="argon_ai_<?php echo esc_attr($provider_key); ?>_api_endpoint" value="<?php echo esc_attr($api_endpoint); ?>" placeholder="<?php _e('留空使用默认端点', 'argon');?>"/>
|
||||
<p class="description"><?php _e('自定义 API 端点地址,留空则使用官方默认地址', 'argon');?></p>
|
||||
</td>
|
||||
</tr>
|
||||
|
||||
<tr class="argon-provider-config" data-provider="<?php echo esc_attr($provider_key); ?>" style="<?php echo $display_style; ?>">
|
||||
<th><label><?php echo esc_html($provider_name); ?> - <?php _e('模型', 'argon');?></label></th>
|
||||
<td>
|
||||
<select name="argon_ai_<?php echo esc_attr($provider_key); ?>_model" class="regular-text argon-model-select" data-provider="<?php echo esc_attr($provider_key); ?>">
|
||||
<option value=""><?php _e('使用默认模型', 'argon');?></option>
|
||||
<?php if (!empty($model)): ?>
|
||||
<option value="<?php echo esc_attr($model); ?>" selected><?php echo esc_html($model); ?></option>
|
||||
<?php endif; ?>
|
||||
</select>
|
||||
<button type="button" class="button argon-refresh-models" data-provider="<?php echo esc_attr($provider_key); ?>" style="margin-left: 10px;">
|
||||
<span class="dashicons dashicons-update" style="margin-top: 3px;"></span> <?php _e('刷新', 'argon');?>
|
||||
</button>
|
||||
<span class="argon-model-loading" data-provider="<?php echo esc_attr($provider_key); ?>" style="display:none;margin-left:10px;color:#666;">
|
||||
<span class="dashicons dashicons-update spin" style="margin-top:3px;"></span> <?php _e('加载中...', 'argon');?>
|
||||
</span>
|
||||
<p class="description">
|
||||
<?php _e('选择要使用的模型。点击"刷新模型列表"可从服务商获取最新可用模型。', 'argon');?><br/>
|
||||
<?php _e('默认模型: OpenAI (gpt-4o-mini) | Claude (claude-3-5-haiku-20241022) | DeepSeek (deepseek-chat)', 'argon');?><br/>
|
||||
<?php _e('通义千问 (qwen-turbo) | 文心一言 (ernie-4.0-turbo-8k) | 豆包 (doubao-pro-32k)', 'argon');?><br/>
|
||||
<?php _e('Kimi (moonshot-v1-8k) | 智谱 (glm-4-flash) | 硅基流动 (Qwen/Qwen2.5-7B-Instruct)', 'argon');?>
|
||||
<p class="description"><?php _e('选择要使用的模型,留空使用默认模型', 'argon');?></p>
|
||||
</td>
|
||||
</tr>
|
||||
|
||||
<?php } ?>
|
||||
|
||||
<tr>
|
||||
<th></th>
|
||||
<td>
|
||||
<p class="description" style="color: #2271b1; font-weight: 500;">
|
||||
<span class="dashicons dashicons-info" style="margin-top: 3px;"></span>
|
||||
<?php _e('提示:每个 AI 服务商都有独立的配置,切换服务商时会自动使用对应的 API 密钥和模型', 'argon');?>
|
||||
</p>
|
||||
<style>
|
||||
@keyframes spin {
|
||||
@@ -2070,21 +2104,34 @@ function themeoptions_page(){
|
||||
</style>
|
||||
<script>
|
||||
jQuery(document).ready(function($) {
|
||||
var currentProvider = $('select[name="argon_ai_summary_provider"]').val();
|
||||
// 切换服务商时显示/隐藏对应配置
|
||||
$('#argon_ai_summary_provider').on('change', function() {
|
||||
var selectedProvider = $(this).val();
|
||||
$('.argon-provider-config').hide();
|
||||
$('.argon-provider-config[data-provider="' + selectedProvider + '"]').show();
|
||||
});
|
||||
|
||||
// 监听服务商变化
|
||||
$('select[name="argon_ai_summary_provider"]').on('change', function() {
|
||||
currentProvider = $(this).val();
|
||||
$('#argon_ai_summary_model').html('<option value=""><?php _e('使用默认模型', 'argon');?></option>');
|
||||
// 显示/隐藏密码
|
||||
$('.argon-toggle-password').on('click', function() {
|
||||
var input = $(this).prev('input');
|
||||
var icon = $(this).find('.dashicons');
|
||||
if (input.attr('type') === 'password') {
|
||||
input.attr('type', 'text');
|
||||
icon.removeClass('dashicons-visibility').addClass('dashicons-hidden');
|
||||
} else {
|
||||
input.attr('type', 'password');
|
||||
icon.removeClass('dashicons-hidden').addClass('dashicons-visibility');
|
||||
}
|
||||
});
|
||||
|
||||
// 刷新模型列表
|
||||
$('#argon_refresh_models').on('click', function() {
|
||||
$('.argon-refresh-models').on('click', function() {
|
||||
var btn = $(this);
|
||||
var loading = $('#argon_model_loading');
|
||||
var select = $('#argon_ai_summary_model');
|
||||
var apiKey = $('input[name="argon_ai_summary_api_key"]').val();
|
||||
var apiEndpoint = $('input[name="argon_ai_summary_api_endpoint"]').val();
|
||||
var provider = btn.data('provider');
|
||||
var loading = $('.argon-model-loading[data-provider="' + provider + '"]');
|
||||
var select = $('.argon-model-select[data-provider="' + provider + '"]');
|
||||
var apiKey = $('input[name="argon_ai_' + provider + '_api_key"]').val();
|
||||
var apiEndpoint = $('input[name="argon_ai_' + provider + '_api_endpoint"]').val();
|
||||
|
||||
if (!apiKey) {
|
||||
alert('<?php _e('请先填写 API 密钥', 'argon');?>');
|
||||
@@ -2097,7 +2144,7 @@ function themeoptions_page(){
|
||||
$.post(ajaxurl, {
|
||||
action: 'argon_get_ai_models',
|
||||
nonce: '<?php echo wp_create_nonce('argon_get_ai_models'); ?>',
|
||||
provider: currentProvider,
|
||||
provider: provider,
|
||||
api_key: apiKey,
|
||||
api_endpoint: apiEndpoint
|
||||
}, function(response) {
|
||||
@@ -7345,12 +7392,17 @@ function argon_update_themeoptions(){
|
||||
//AI 摘要
|
||||
argon_update_option_checkbox('argon_ai_summary_enable');
|
||||
argon_update_option('argon_ai_summary_provider');
|
||||
argon_update_option('argon_ai_summary_api_key');
|
||||
argon_update_option('argon_ai_summary_api_endpoint');
|
||||
argon_update_option('argon_ai_summary_model');
|
||||
argon_update_option('argon_ai_summary_prompt');
|
||||
argon_update_option('argon_ai_summary_exclude_ids');
|
||||
|
||||
// 保存所有提供商的配置
|
||||
$providers = ['openai', 'anthropic', 'deepseek', 'xiaomi', 'qianwen', 'wenxin', 'doubao', 'kimi', 'zhipu', 'siliconflow'];
|
||||
foreach ($providers as $provider) {
|
||||
argon_update_option("argon_ai_{$provider}_api_key");
|
||||
argon_update_option("argon_ai_{$provider}_api_endpoint");
|
||||
argon_update_option("argon_ai_{$provider}_model");
|
||||
}
|
||||
|
||||
//AI 垃圾评论识别
|
||||
argon_update_option_checkbox('argon_comment_spam_detection_enable');
|
||||
argon_update_option('argon_comment_spam_detection_prompt_mode');
|
||||
|
||||
Reference in New Issue
Block a user