Skip to content

Commit

Permalink
✨ 增加智能助手多平台选择
Browse files Browse the repository at this point in the history
  • Loading branch information
Licoy committed May 9, 2024
1 parent 3caff8d commit df703c4
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 5 deletions.
7 changes: 6 additions & 1 deletion inc/ajax/ai.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,12 @@ function pk_ajax_ai_ask()
if (empty($text)) {
wp_die('<code>请输入描述</code>');
}
$openai_url = pk_get_option('ai_chat_agent', 'https://api.openai.com');
$ai_platform = pk_get_option('ai_chat_platform','gptnb');
switch ($ai_platform){
case 'gptnb': $openai_url='https://goapi.gptnb.me';break;
case 'openai': $openai_url='https://api.openai.com';break;
default:$openai_url=pk_get_option('ai_chat_agent', 'https://api.openai.com');
}
$openai_api_key = pk_get_option('ai_chat_key');
if (empty($openai_api_key)) {
wp_die('<code>请先配置OpenAI API Key</code>');
Expand Down
30 changes: 26 additions & 4 deletions inc/setting/options/OptionAi.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,19 +17,41 @@ function get_fields(): array
'type' => 'switch',
'tips' => __('启用后去<a href="/wp-admin/post-new.php?post_type=page">创建页面</a>选择<code>AI助手</code>模板即可使用', PUOCK)
],
[
'id' => 'ai_chat_platform',
'label' => __('API 提供商', PUOCK),
'type' => 'radio',
'sdt' => 'gptnb',
'options' => [
[
'value' => 'gptnb',
'label' => __('GPTNB', PUOCK),
],
[
'value' => 'openai',
'label' => __('OpenAI', PUOCK),
],
[
'value' => 'custom',
'label' => __('自定义', PUOCK),
],
],
'tips' => __('<a href="https://goapi.gptnb.me" target="_blank"><code>GPTNB(第三方中转)<i class="fa-solid fa-arrow-up-right-from-square"></i></code></a> | <a href="https://platform.openai.com" target="_blank"><code>OpenAI(官方)<i class="fa-solid fa-arrow-up-right-from-square"></i></code></a>(注意:第三方中转由第三方服务商提供,本程序不承诺任何担保,若有任何疑问请咨询对应的网站客服)', PUOCK),
],
[
'id' => 'ai_chat_key',
'label' => __('API KEY', PUOCK),
'type' => 'text',
'sdt' => pk_get_option('openai_api_key'),
'tips' => __('请在<a href="https://platform.openai.com/" target="_blank">OpenAI - Platform</a>申请获取API Key,或填入您其他平台的KEY', PUOCK),
'tips' => __('请在上方选择的对应的服务商申请获取API Key,然后在此填入', PUOCK),
],
[
'id' => 'ai_chat_agent',
'label' => __('API 代理域', PUOCK),
'label' => __('自定义 API 代理域', PUOCK),
'type' => 'text',
'sdt' => pk_get_option('openai_api_agent'),
'tips' => __('默认为<code>https://api.openai.com</code>,如果您要使用其他平台请自行配置代理域名,例如您自己的反向代理、Api2D、OpenAISB或自建的OneAPI', PUOCK),
'sdt' => '',
'showRefId'=>'func:(function(args){return args.data.ai_chat_platform==="custom"})(args)',
'tips' => __('如果您要使用其他平台请自行配置代理域名,例如您自己的反向代理等,其API规范必须符合OpenAI API', PUOCK),
],
[
'id' => 'ai_chat_models',
Expand Down

0 comments on commit df703c4

Please sign in to comment.