Skip to content

Commit

Permalink
chore: 单独设置API地址 (Close #369)
Browse files Browse the repository at this point in the history
  • Loading branch information
Kerwin committed Dec 30, 2023
1 parent d5a1a09 commit c275b1e
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 9 deletions.
8 changes: 6 additions & 2 deletions service/src/chatgpt/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ export async function initApi(key: KeyConfig, chatModel: string, maxContextCount
const model = chatModel as string

if (key.keyModel === 'ChatGPTAPI') {
const OPENAI_API_BASE_URL = config.apiBaseUrl
const OPENAI_API_BASE_URL = isNotEmptyString(key.baseUrl) ? key.baseUrl : config.apiBaseUrl

let contextCount = 0
const options: ChatGPTAPIOptions = {
Expand Down Expand Up @@ -97,7 +97,11 @@ export async function initApi(key: KeyConfig, chatModel: string, maxContextCount
else {
const options: ChatGPTUnofficialProxyAPIOptions = {
accessToken: key.key,
apiReverseProxyUrl: isNotEmptyString(config.reverseProxy) ? config.reverseProxy : 'https://ai.fakeopen.com/api/conversation',
apiReverseProxyUrl: isNotEmptyString(key.baseUrl)
? key.baseUrl
: isNotEmptyString(config.reverseProxy)
? config.reverseProxy
: 'https://ai.fakeopen.com/api/conversation',
model,
debug: !config.apiDisableDebug,
}
Expand Down
1 change: 1 addition & 0 deletions service/src/storage/model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,7 @@ export class KeyConfig {
userRoles: UserRole[]
status: Status
remark: string
baseUrl?: string
constructor(key: string, keyModel: APIMODEL, chatModels: string[], userRoles: UserRole[], remark: string) {
this.key = key
this.keyModel = keyModel
Expand Down
28 changes: 21 additions & 7 deletions src/components/common/Setting/Keys.vue
Original file line number Diff line number Diff line change
Expand Up @@ -23,20 +23,25 @@ const columns = [
title: 'Key',
key: 'key',
resizable: true,
width: 200,
minWidth: 100,
maxWidth: 200,
width: 120,
minWidth: 50,
maxWidth: 120,
ellipsis: true,
},
{
title: 'Api Model',
key: 'keyModel',
width: 190,
width: 150,
},
{
title: 'Base url',
key: 'baseUrl',
width: 150,
},
{
title: 'Chat Model',
key: 'chatModels',
width: 320,
width: 300,
render(row: any) {
const tags = row.chatModels.map((chatModel: string) => {
return h(
Expand All @@ -59,7 +64,7 @@ const columns = [
{
title: 'User Roles',
key: 'userRoles',
width: 200,
width: 180,
render(row: any) {
const tags = row.userRoles.map((userRole: UserRole) => {
return h(
Expand All @@ -82,7 +87,7 @@ const columns = [
{
title: 'Remark',
key: 'remark',
width: 220,
width: 150,
},
{
title: 'Action',
Expand Down Expand Up @@ -256,6 +261,15 @@ onMounted(async () => {
/>
</div>
</div>
<div class="flex items-center space-x-4">
<span class="flex-shrink-0 w-[100px]">{{ $t('setting.apiBaseUrl') }}</span>
<div class="flex-1">
<NInput
v-model:value="keyConfig.baseUrl"
style="width: 100%" placeholder=""
/>
</div>
</div>
<div class="flex items-center space-x-4">
<span class="flex-shrink-0 w-[100px]">{{ $t('setting.chatModels') }}</span>
<div class="flex-1">
Expand Down
1 change: 1 addition & 0 deletions src/components/common/Setting/model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ export class KeyConfig {
userRoles: UserRole[]
status: Status
remark: string
baseUrl?: string
constructor(key: string, keyModel: APIMODEL, chatModels: string[], userRoles: UserRole[], remark: string) {
this.key = key
this.keyModel = keyModel
Expand Down

0 comments on commit c275b1e

Please sign in to comment.