From 31e55648cb06813ee22beabf8e5c6b9d8c7ba4c2 Mon Sep 17 00:00:00 2001 From: nanhaoluo <3075912108@qq.com> Date: Mon, 26 Jan 2026 12:58:41 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E6=89=B9=E9=87=8F=E6=A3=80=E6=B5=8B?= =?UTF-8?q?=E9=9B=86=E6=88=90=E7=BB=9F=E4=B8=80=E6=8E=A5=E5=8F=A3=E5=B9=B6?= =?UTF-8?q?=E6=B7=BB=E5=8A=A0AI=E6=9F=A5=E8=AF=A2=E7=BB=9F=E8=AE=A1?= =?UTF-8?q?=E9=A1=B5=E9=9D=A2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 修改 argon_batch_detect_spam_comments() 使用统一的 argon_ai_query() 接口 - 删除旧的 argon_call_ai_api_for_batch_spam_detection() 函数 - 添加 argon_register_ai_query_stats_page() 注册统计页面 - 添加 argon_render_ai_query_stats_page() 渲染统计页面 - 统计页面显示总查询次数、成功率、平均响应时间、失败次数 - 按场景和服务商分别统计查询数据 - 显示最近30天的查询趋势 - 在 settings.php 的 AI 摘要设置中添加查看统计链接 统计页面功能: - 总览卡片:总查询次数、成功率、平均响应时间、失败次数 - 按场景统计:文章摘要、垃圾评论检测、批量检测等 - 按服务商统计:OpenAI、Claude、DeepSeek 等 - 查询趋势:最近30天每日查询数据 --- functions.php | 310 +++++++++++++++++++++++++++++++------------------- settings.php | 10 ++ 2 files changed, 202 insertions(+), 118 deletions(-) diff --git a/functions.php b/functions.php index 910680a..30d030a 100644 --- a/functions.php +++ b/functions.php @@ -6702,6 +6702,185 @@ function argon_ajax_get_ai_query_stats() { } add_action('wp_ajax_argon_get_ai_query_stats', 'argon_ajax_get_ai_query_stats'); +/** + * 注册 AI 查询统计页面 + */ +function argon_register_ai_query_stats_page() { + add_submenu_page( + null, // 不在菜单中显示,通过其他方式访问 + __('AI 查询统计', 'argon'), + __('AI 查询统计', 'argon'), + 'manage_options', + 'argon-ai-query-stats', + 'argon_render_ai_query_stats_page' + ); +} +add_action('admin_menu', 'argon_register_ai_query_stats_page'); + +/** + * 渲染 AI 查询统计页面 + */ +function argon_render_ai_query_stats_page() { + if (!current_user_can('manage_options')) { + wp_die(__('权限不足', 'argon')); + } + + global $wpdb; + $table_name = $wpdb->prefix . 'argon_ai_query_log'; + + // 获取统计数据 + $stats = argon_get_ai_query_stats(); + + // 获取最近30天的查询趋势 + $trend_data = $wpdb->get_results(" + SELECT + DATE(query_time) as date, + COUNT(*) as total, + SUM(CASE WHEN status = 'success' THEN 1 ELSE 0 END) as success, + AVG(response_time) as avg_time + FROM $table_name + WHERE query_time >= DATE_SUB(NOW(), INTERVAL 30 DAY) + GROUP BY DATE(query_time) + ORDER BY date DESC + LIMIT 30 + ", ARRAY_A); + + ?> +
+

+ +
+ +
+
+

+

+
+ +
+

+

%

+
+ +
+

+

ms

+
+ +
+

+

+
+
+ + +
+

+ + + + + + + + + + __('文章摘要', 'argon'), + 'spam_detection' => __('垃圾评论检测', 'argon'), + 'spam_detection_batch' => __('批量垃圾评论检测', 'argon'), + 'keyword_extraction' => __('关键词提取', 'argon'), + 'test' => __('测试', 'argon') + ]; + + foreach ($stats['by_scenario'] as $row): + $scenario_name = isset($scenario_names[$row['scenario']]) ? $scenario_names[$row['scenario']] : $row['scenario']; + ?> + + + + + + + +
ms
+
+ + +
+

+ + + + + + + + + + 'OpenAI', + 'anthropic' => 'Anthropic Claude', + 'deepseek' => 'DeepSeek', + 'xiaomi' => __('小米 Mimo', 'argon'), + 'qianwen' => __('通义千问', 'argon'), + 'wenxin' => __('文心一言', 'argon'), + 'doubao' => __('豆包', 'argon'), + 'kimi' => 'Kimi', + 'zhipu' => __('智谱 AI', 'argon'), + 'siliconflow' => __('硅基流动', 'argon') + ]; + + foreach ($stats['by_provider'] as $row): + $provider_name = isset($provider_names[$row['provider']]) ? $provider_names[$row['provider']] : $row['provider']; + ?> + + + + + + + +
ms
+
+ + +
+

+ + + + + + + + + + + + + + + + + + + +
ms
+
+
+ +

+ + + +

+
+ get_current_user_id() + ]); if (!$ai_response) { return false; @@ -9883,105 +10056,6 @@ function argon_batch_detect_spam_comments($comments_data) { return $result; } -/** - * 调用 AI API 进行批量垃圾评论检测 - */ -function argon_call_ai_api_for_batch_spam_detection($provider, $api_key, $model, $prompt, $content) { - $endpoint = get_option('argon_ai_summary_api_endpoint', ''); - - // 根据不同服务商设置默认端点和模型 - $default_models = [ - 'openai' => 'gpt-4o-mini', - 'anthropic' => 'claude-3-5-haiku-20241022', - 'deepseek' => 'deepseek-chat', - 'xiaomi' => 'MiMo-V2-Flash', - 'qianwen' => 'qwen-turbo', - 'wenxin' => 'ernie-4.0-turbo-8k', - 'doubao' => 'doubao-pro-32k', - 'kimi' => 'moonshot-v1-8k', - 'zhipu' => 'glm-4-flash', - 'siliconflow' => 'Qwen/Qwen2.5-7B-Instruct' - ]; - - if (empty($model) && isset($default_models[$provider])) { - $model = $default_models[$provider]; - } - - // 构建请求 - $messages = [ - ['role' => 'system', 'content' => $prompt], - ['role' => 'user', 'content' => $content] - ]; - - $body = [ - 'model' => $model, - 'messages' => $messages, - 'temperature' => 0.3, - 'max_tokens' => 4000 // 批量检测需要更多 token - ]; - - // 根据服务商设置端点 - if (empty($endpoint)) { - $endpoints = [ - 'openai' => 'https://api.openai.com/v1/chat/completions', - 'anthropic' => 'https://api.anthropic.com/v1/messages', - 'deepseek' => 'https://api.deepseek.com/v1/chat/completions', - 'xiaomi' => 'https://api.mimo.xiaomi.com/v1/chat/completions', - 'qianwen' => 'https://dashscope.aliyuncs.com/compatible-mode/v1/chat/completions', - 'wenxin' => 'https://aip.baidubce.com/rpc/2.0/ai_custom/v1/wenxinworkshop/chat/completions', - 'doubao' => 'https://ark.cn-beijing.volces.com/api/v3/chat/completions', - 'kimi' => 'https://api.moonshot.cn/v1/chat/completions', - 'zhipu' => 'https://open.bigmodel.cn/api/paas/v4/chat/completions', - 'siliconflow' => 'https://api.siliconflow.cn/v1/chat/completions' - ]; - $endpoint = isset($endpoints[$provider]) ? $endpoints[$provider] : $endpoints['openai']; - } - - // Anthropic 特殊处理 - if ($provider === 'anthropic') { - $body = [ - 'model' => $model, - 'messages' => [['role' => 'user', 'content' => $prompt . "\n\n" . $content]], - 'max_tokens' => 4000 - ]; - $headers = [ - 'x-api-key' => $api_key, - 'anthropic-version' => '2023-06-01', - 'Content-Type' => 'application/json' - ]; - } else { - $headers = [ - 'Authorization' => 'Bearer ' . $api_key, - 'Content-Type' => 'application/json' - ]; - } - - $response = wp_remote_post($endpoint, [ - 'headers' => $headers, - 'body' => json_encode($body), - 'timeout' => 60 // 批量检测需要更长超时时间 - ]); - - if (is_wp_error($response)) { - return false; - } - - $response_body = json_decode(wp_remote_retrieve_body($response), true); - - // 解析响应 - $ai_response = ''; - if ($provider === 'anthropic') { - if (isset($response_body['content'][0]['text'])) { - $ai_response = $response_body['content'][0]['text']; - } - } else { - if (isset($response_body['choices'][0]['message']['content'])) { - $ai_response = $response_body['choices'][0]['message']['content']; - } - } - - return $ai_response; -} /** * 后台处理扫描任务(已废弃,保留以兼容旧代码) diff --git a/settings.php b/settings.php index fa45cc0..bbd613b 100644 --- a/settings.php +++ b/settings.php @@ -2587,6 +2587,16 @@ function themeoptions_page(){ + + + + + + +

+ + +