Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
赵月辉
/
fastgpt-migrated
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Snippets
Members
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Unverified
Commit
bb824ab3
authored
Aug 05, 2023
by
archer
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
perf: user openai
parent
37a6293f
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
23 additions
and
20 deletions
+23
-20
client/.env.template
+7
-6
client/src/pages/api/app/share/getModels.ts
+2
-8
client/src/service/ai/openai.ts
+3
-3
client/src/store/chat.ts
+1
-1
client/src/store/shareChat.ts
+1
-1
client/src/store/user.ts
+9
-1
No files found.
client/.env.template
View file @
bb824ab3
...
@@ -17,12 +17,13 @@ aliTemplateCode=xxxx
...
@@ -17,12 +17,13 @@ aliTemplateCode=xxxx
TOKEN_KEY=dfdasfdas
TOKEN_KEY=dfdasfdas
# root key, 最高权限
# root key, 最高权限
ROOT_KEY=fdafasd
ROOT_KEY=fdafasd
# 使用 oneapi
# openai 基本地址,可用作中转。
# ONEAPI_URL=https://xxxx.cloud.sealos.io/v1
OPENAI_BASE_URL=https://api.openai.com/v1
# ONEAPI_KEY=sk-xxxx
# oneapi 地址,可以使用 oneapi 来实现多模型接入
# openai 的基本地址(国外的可以忽略,默认走 api.openai.com)。不用 oneapi 的话需要下面 2 个参数,用户的 key 也会走下面的参数
ONEAPI_URL=https://xxxx.cloud.sealos.io/openai/v1
OPENAI_BASE_URL=https://xxxx.cloud.sealos.io/openai/v1
# 通用key。可以是 openai 的也可以是 oneapi 的。
OPENAIKEY=sk-xxxx
# 此处填写逻辑:填了 ONEAPI_URL,key 就填 oneapi 的。没填 ONEAPI_URL,key 就填 OPENAI_BASE_URL 对应的。
CHAT_API_KEY=sk-xxxx
# db
# db
MONGODB_URI=mongodb://username:password@0.0.0.0:27017/?authSource=admin
MONGODB_URI=mongodb://username:password@0.0.0.0:27017/?authSource=admin
MONGODB_NAME=fastgpt
MONGODB_NAME=fastgpt
...
...
client/src/pages/api/app/share/getModels.ts
View file @
bb824ab3
...
@@ -3,7 +3,7 @@ import { jsonRes } from '@/service/response';
...
@@ -3,7 +3,7 @@ import { jsonRes } from '@/service/response';
import
{
connectToDatabase
,
App
}
from
'@/service/mongo'
;
import
{
connectToDatabase
,
App
}
from
'@/service/mongo'
;
import
type
{
PagingData
}
from
'@/types'
;
import
type
{
PagingData
}
from
'@/types'
;
import
type
{
ShareAppItem
}
from
'@/types/app'
;
import
type
{
ShareAppItem
}
from
'@/types/app'
;
import
{
parseCookie
}
from
'@/service/utils/auth'
;
import
{
authUser
}
from
'@/service/utils/auth'
;
import
{
Types
}
from
'mongoose'
;
import
{
Types
}
from
'mongoose'
;
/* 获取模型列表 */
/* 获取模型列表 */
...
@@ -17,13 +17,7 @@ export default async function handler(req: NextApiRequest, res: NextApiResponse<
...
@@ -17,13 +17,7 @@ export default async function handler(req: NextApiRequest, res: NextApiResponse<
await
connectToDatabase
();
await
connectToDatabase
();
let
userId
=
''
;
const
{
userId
}
=
await
authUser
({
req
,
authToken
:
true
});
try
{
userId
=
await
parseCookie
(
req
.
headers
.
cookie
);
}
catch
(
error
)
{
error
;
}
const
regex
=
new
RegExp
(
searchText
,
'i'
);
const
regex
=
new
RegExp
(
searchText
,
'i'
);
...
...
client/src/service/ai/openai.ts
View file @
bb824ab3
import
{
UserModelSchema
}
from
'@/types/mongoSchema'
;
import
{
UserModelSchema
}
from
'@/types/mongoSchema'
;
import
{
Configuration
,
OpenAIApi
}
from
'openai'
;
import
{
Configuration
,
OpenAIApi
}
from
'openai'
;
export
const
openaiBaseUrl
=
'https://api.openai.com/v1'
;
export
const
openaiBaseUrl
=
process
.
env
.
OPENAI_BASE_URL
||
'https://api.openai.com/v1'
;
export
const
baseUrl
=
process
.
env
.
ONEAPI_URL
||
process
.
env
.
OPENAI_BASE_URL
||
openaiBaseUrl
;
export
const
baseUrl
=
process
.
env
.
ONEAPI_URL
||
openaiBaseUrl
;
export
const
systemAIChatKey
=
process
.
env
.
ONEAPI_KEY
||
process
.
env
.
OPENAI
KEY
||
''
;
export
const
systemAIChatKey
=
process
.
env
.
CHAT_API_
KEY
||
''
;
export
const
getAIChatApi
=
(
props
?:
UserModelSchema
[
'openaiAccount'
])
=>
{
export
const
getAIChatApi
=
(
props
?:
UserModelSchema
[
'openaiAccount'
])
=>
{
return
new
OpenAIApi
(
return
new
OpenAIApi
(
...
...
client/src/store/chat.ts
View file @
bb824ab3
...
@@ -24,7 +24,7 @@ const defaultChatData: InitChatResponse = {
...
@@ -24,7 +24,7 @@ const defaultChatData: InitChatResponse = {
chatId
:
''
,
chatId
:
''
,
appId
:
''
,
appId
:
''
,
app
:
{
app
:
{
name
:
''
,
name
:
'
FastAI
'
,
avatar
:
'/icon/logo.png'
,
avatar
:
'/icon/logo.png'
,
intro
:
''
,
intro
:
''
,
canUse
:
false
canUse
:
false
...
...
client/src/store/shareChat.ts
View file @
bb824ab3
...
@@ -30,7 +30,7 @@ export const defaultHistory: ShareChatHistoryItemType = {
...
@@ -30,7 +30,7 @@ export const defaultHistory: ShareChatHistoryItemType = {
const
defaultShareChatData
:
ShareChatType
=
{
const
defaultShareChatData
:
ShareChatType
=
{
userAvatar
:
HUMAN_ICON
,
userAvatar
:
HUMAN_ICON
,
app
:
{
app
:
{
name
:
''
,
name
:
'
AI
'
,
avatar
:
'/icon/logo.png'
,
avatar
:
'/icon/logo.png'
,
intro
:
''
intro
:
''
},
},
...
...
client/src/store/user.ts
View file @
bb824ab3
...
@@ -53,6 +53,7 @@ export const useUserStore = create<State>()(
...
@@ -53,6 +53,7 @@ export const useUserStore = create<State>()(
});
});
},
},
async
updateUserInfo
(
user
:
UserUpdateParams
)
{
async
updateUserInfo
(
user
:
UserUpdateParams
)
{
const
oldInfo
=
(
get
().
userInfo
?
{
...
get
().
userInfo
}
:
null
)
as
UserType
|
null
;
set
((
state
)
=>
{
set
((
state
)
=>
{
if
(
!
state
.
userInfo
)
return
;
if
(
!
state
.
userInfo
)
return
;
state
.
userInfo
=
{
state
.
userInfo
=
{
...
@@ -60,7 +61,14 @@ export const useUserStore = create<State>()(
...
@@ -60,7 +61,14 @@ export const useUserStore = create<State>()(
...
user
...
user
};
};
});
});
await
putUserInfo
(
user
);
try
{
await
putUserInfo
(
user
);
}
catch
(
error
)
{
set
((
state
)
=>
{
state
.
userInfo
=
oldInfo
;
});
return
Promise
.
reject
(
error
);
}
},
},
myApps
:
[],
myApps
:
[],
myCollectionApps
:
[],
myCollectionApps
:
[],
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment