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
a3d74ec4
authored
Mar 31, 2023
by
archer
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
perrf chat不请求余额
parent
df9ac99e
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
11 additions
and
5 deletions
+11
-5
src/pages/api/chat/chatGpt.ts
+2
-1
src/service/events/generateAbstract.ts
+1
-1
src/service/events/generateQA.ts
+1
-1
src/service/utils/chat.ts
+4
-1
src/service/utils/tools.ts
+3
-1
No files found.
src/pages/api/chat/chatGpt.ts
View file @
a3d74ec4
...
...
@@ -91,7 +91,8 @@ export default async function handler(req: NextApiRequest, res: NextApiResponse)
messages
:
formatPrompts
,
frequency_penalty
:
0.5
,
// 越大,重复内容越少
presence_penalty
:
-
0.5
,
// 越大,越容易出现新内容
stream
:
true
stream
:
true
,
stop
:
[
'.!?。'
]
},
{
timeout
:
40000
,
...
...
src/service/events/generateAbstract.ts
View file @
a3d74ec4
...
...
@@ -40,7 +40,7 @@ export async function generateAbstract(next = false): Promise<any> {
// 获取 openapi Key
let
userApiKey
,
systemKey
;
try
{
const
key
=
await
getOpenApiKey
(
dataItem
.
userId
);
const
key
=
await
getOpenApiKey
(
dataItem
.
userId
,
true
);
userApiKey
=
key
.
userApiKey
;
systemKey
=
key
.
systemKey
;
}
catch
(
error
:
any
)
{
...
...
src/service/events/generateQA.ts
View file @
a3d74ec4
...
...
@@ -37,7 +37,7 @@ export async function generateQA(next = false): Promise<any> {
// 获取 openapi Key
let
userApiKey
,
systemKey
;
try
{
const
key
=
await
getOpenApiKey
(
dataItem
.
userId
);
const
key
=
await
getOpenApiKey
(
dataItem
.
userId
,
true
);
userApiKey
=
key
.
userApiKey
;
systemKey
=
key
.
systemKey
;
}
catch
(
error
:
any
)
{
...
...
src/service/utils/chat.ts
View file @
a3d74ec4
...
...
@@ -35,7 +35,10 @@ export const authChat = async (chatId: string, authorization?: string) => {
}
// 获取 user 的 apiKey
const
{
user
,
userApiKey
,
systemKey
}
=
await
getOpenApiKey
(
chat
.
userId
as
unknown
as
string
);
const
{
user
,
userApiKey
,
systemKey
}
=
await
getOpenApiKey
(
chat
.
userId
as
unknown
as
string
,
false
);
// filter 掉被 deleted 的内容
chat
.
content
=
chat
.
content
.
filter
((
item
)
=>
item
.
deleted
!==
true
);
...
...
src/service/utils/tools.ts
View file @
a3d74ec4
...
...
@@ -97,7 +97,7 @@ export const getUserApiOpenai = async (userId: string) => {
};
/* 获取 open api key,如果用户没有自己的key,就用平台的,用平台记得加账单 */
export
const
getOpenApiKey
=
async
(
userId
:
string
)
=>
{
export
const
getOpenApiKey
=
async
(
userId
:
string
,
checkGrant
=
false
)
=>
{
const
user
=
await
User
.
findById
(
userId
);
if
(
!
user
)
{
return
Promise
.
reject
(
'找不到用户'
);
...
...
@@ -108,6 +108,7 @@ export const getOpenApiKey = async (userId: string) => {
// 有自己的key
if
(
userApiKey
)
{
// api 余额校验
if
(
checkGrant
)
{
const
hasGrant
=
await
checkKeyGrant
(
userApiKey
);
if
(
!
hasGrant
)
{
return
Promise
.
reject
({
...
...
@@ -115,6 +116,7 @@ export const getOpenApiKey = async (userId: string) => {
message
:
'API 余额不足'
});
}
}
return
{
user
,
...
...
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