Skip to content

Commit

Permalink
ai config
Browse files Browse the repository at this point in the history
  • Loading branch information
star7th committed Apr 2, 2023
1 parent 242c165 commit 375402c
Show file tree
Hide file tree
Showing 7 changed files with 38 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,15 @@ public function saveConfig()
$beian = I("beian");
$site_url = I("site_url");
$open_api_key = I("open_api_key");
$open_api_host = I("open_api_host");
D("Options")->set("history_version_count", $history_version_count);
D("Options")->set("register_open", $register_open);
D("Options")->set("home_page", $home_page);
D("Options")->set("home_item", $home_item);
D("Options")->set("beian", $beian);
D("Options")->set("site_url", $site_url);
D("Options")->set("open_api_key", $open_api_key);
D("Options")->set("open_api_host", $open_api_host);
D("Options")->set("show_watermark", $show_watermark);

if ($oss_open) {
Expand All @@ -55,6 +57,7 @@ public function loadConfig()
$beian = D("Options")->get("beian");
$site_url = D("Options")->get("site_url");
$open_api_key = D("Options")->get("open_api_key");
$open_api_host = D("Options")->get("open_api_host");
$oss_setting = json_decode($oss_setting, 1);

//如果强等于false,那就是尚未有数据。关闭注册应该是有数据且数据为字符串0
Expand All @@ -72,6 +75,7 @@ public function loadConfig()
"site_url" => $site_url,
"oss_setting" => $oss_setting,
"open_api_key" => $open_api_key,
"open_api_host" => $open_api_host,
);
$this->sendResult($array);
}
Expand Down
14 changes: 12 additions & 2 deletions server/Application/Api/Controller/AiController.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,20 @@ public function send($content)
),
),
));
$api_base_url = env('API_BASE_URL', 'https://api.openai.com');
$open_api_host = D("Options")->get("open_api_host");
if (!$open_api_host) {
$open_api_host = 'https://api.openai.com';
}
if (!strstr($open_api_host, 'http')) {
$open_api_host = 'https://' . $open_api_host;
}
if (substr($open_api_host, -1) === '/') { // 如果字符串以 / 符号结尾:
$open_api_host = substr($open_api_host, 0, -1); // 将字符串的最后一个字符剪切掉

}
$curl = curl_init(); //初始化
curl_setopt($curl, CURLOPT_ENCODING, '');
curl_setopt($curl, CURLOPT_URL, $api_base_url . '/v1/chat/completions'); //设置url
curl_setopt($curl, CURLOPT_URL, $open_api_host . '/v1/chat/completions'); //设置url
curl_setopt($curl, CURLOPT_HTTPAUTH, CURLAUTH_BASIC); //设置http验证方法
curl_setopt($curl, CURLOPT_TIMEOUT, 120);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1); //设置curl_exec获取的信息的返回方式
Expand Down
2 changes: 1 addition & 1 deletion web/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,4 @@
'../server/index.php?s=',
// "lang" :'en'
lang: 'zh-cn'
}</script><link href=./static/css/app.ebeffe2948eb6b4f85c67f44a1860bf3.css rel=stylesheet></head><body class=grey-bg><div id=app></div><script type=text/javascript src=./static/js/manifest.3ad1d5771e9b13dbdad2.js></script><script type=text/javascript src=./static/js/vendor.339f5a1f86786a88b9d4.js></script><script type=text/javascript src=./static/js/app.0cf128d74464e1dccf3a.js></script></body></html>
}</script><link href=./static/css/app.cf5cf8d7db49bba7dd9f2a5241bd431c.css rel=stylesheet></head><body class=grey-bg><div id=app></div><script type=text/javascript src=./static/js/manifest.3ad1d5771e9b13dbdad2.js></script><script type=text/javascript src=./static/js/vendor.339f5a1f86786a88b9d4.js></script><script type=text/javascript src=./static/js/app.7d4ce78ff195400edcb7.js></script></body></html>

Large diffs are not rendered by default.

1 change: 0 additions & 1 deletion web/static/js/app.0cf128d74464e1dccf3a.js

This file was deleted.

1 change: 1 addition & 0 deletions web/static/js/app.7d4ce78ff195400edcb7.js

Large diffs are not rendered by default.

20 changes: 19 additions & 1 deletion web_src/src/components/admin/setting/Index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,20 @@
></i>
</el-tooltip>
</el-form-item>
<el-form-item v-show="$lang == 'zh-cn'" label="AI助手代理HOST">
<el-input
v-model="form.open_api_host"
class="form-el"
placeholder="可选"
></el-input>

<el-tooltip effect="dark" content="点击查看填写说明" placement="top">
<i
class="el-icon-question cursor-pointer "
@click="toOutLink('https://github.com/star7th/showdoc/issues/1904')"
></i>
</el-tooltip>
</el-form-item>
<el-form-item :label="$t('oss_open')">
<el-switch v-model="form.oss_open"></el-switch>
</el-form-item>
Expand Down Expand Up @@ -225,7 +239,8 @@ export default {
beian: '',
show_watermark: false,
site_url: '',
open_api_key: ''
open_api_key: '',
open_api_host: ''
},
itemList: []
}
Expand Down Expand Up @@ -272,6 +287,9 @@ export default {
this.form.open_api_key = data.data.open_api_key
? data.data.open_api_key
: ''
this.form.open_api_host = data.data.open_api_host
? data.data.open_api_host
: ''
})
},
getItemList() {
Expand Down

0 comments on commit 375402c

Please sign in to comment.