Skip to content

Commit c275b1e

Browse files
author
Kerwin
committed
chore: 单独设置API地址 (Close #369)
1 parent d5a1a09 commit c275b1e

File tree

4 files changed

+29
-9
lines changed

4 files changed

+29
-9
lines changed

service/src/chatgpt/index.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ export async function initApi(key: KeyConfig, chatModel: string, maxContextCount
4141
const model = chatModel as string
4242

4343
if (key.keyModel === 'ChatGPTAPI') {
44-
const OPENAI_API_BASE_URL = config.apiBaseUrl
44+
const OPENAI_API_BASE_URL = isNotEmptyString(key.baseUrl) ? key.baseUrl : config.apiBaseUrl
4545

4646
let contextCount = 0
4747
const options: ChatGPTAPIOptions = {
@@ -97,7 +97,11 @@ export async function initApi(key: KeyConfig, chatModel: string, maxContextCount
9797
else {
9898
const options: ChatGPTUnofficialProxyAPIOptions = {
9999
accessToken: key.key,
100-
apiReverseProxyUrl: isNotEmptyString(config.reverseProxy) ? config.reverseProxy : 'https://ai.fakeopen.com/api/conversation',
100+
apiReverseProxyUrl: isNotEmptyString(key.baseUrl)
101+
? key.baseUrl
102+
: isNotEmptyString(config.reverseProxy)
103+
? config.reverseProxy
104+
: 'https://ai.fakeopen.com/api/conversation',
101105
model,
102106
debug: !config.apiDisableDebug,
103107
}

service/src/storage/model.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -228,6 +228,7 @@ export class KeyConfig {
228228
userRoles: UserRole[]
229229
status: Status
230230
remark: string
231+
baseUrl?: string
231232
constructor(key: string, keyModel: APIMODEL, chatModels: string[], userRoles: UserRole[], remark: string) {
232233
this.key = key
233234
this.keyModel = keyModel

src/components/common/Setting/Keys.vue

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -23,20 +23,25 @@ const columns = [
2323
title: 'Key',
2424
key: 'key',
2525
resizable: true,
26-
width: 200,
27-
minWidth: 100,
28-
maxWidth: 200,
26+
width: 120,
27+
minWidth: 50,
28+
maxWidth: 120,
2929
ellipsis: true,
3030
},
3131
{
3232
title: 'Api Model',
3333
key: 'keyModel',
34-
width: 190,
34+
width: 150,
35+
},
36+
{
37+
title: 'Base url',
38+
key: 'baseUrl',
39+
width: 150,
3540
},
3641
{
3742
title: 'Chat Model',
3843
key: 'chatModels',
39-
width: 320,
44+
width: 300,
4045
render(row: any) {
4146
const tags = row.chatModels.map((chatModel: string) => {
4247
return h(
@@ -59,7 +64,7 @@ const columns = [
5964
{
6065
title: 'User Roles',
6166
key: 'userRoles',
62-
width: 200,
67+
width: 180,
6368
render(row: any) {
6469
const tags = row.userRoles.map((userRole: UserRole) => {
6570
return h(
@@ -82,7 +87,7 @@ const columns = [
8287
{
8388
title: 'Remark',
8489
key: 'remark',
85-
width: 220,
90+
width: 150,
8691
},
8792
{
8893
title: 'Action',
@@ -256,6 +261,15 @@ onMounted(async () => {
256261
/>
257262
</div>
258263
</div>
264+
<div class="flex items-center space-x-4">
265+
<span class="flex-shrink-0 w-[100px]">{{ $t('setting.apiBaseUrl') }}</span>
266+
<div class="flex-1">
267+
<NInput
268+
v-model:value="keyConfig.baseUrl"
269+
style="width: 100%" placeholder=""
270+
/>
271+
</div>
272+
</div>
259273
<div class="flex items-center space-x-4">
260274
<span class="flex-shrink-0 w-[100px]">{{ $t('setting.chatModels') }}</span>
261275
<div class="flex-1">

src/components/common/Setting/model.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,7 @@ export class KeyConfig {
9191
userRoles: UserRole[]
9292
status: Status
9393
remark: string
94+
baseUrl?: string
9495
constructor(key: string, keyModel: APIMODEL, chatModels: string[], userRoles: UserRole[], remark: string) {
9596
this.key = key
9697
this.keyModel = keyModel

0 commit comments

Comments
 (0)