perrf chat不请求余额
This commit is contained in:
parent
df9ac99ef2
commit
a3d74ec4a6
@ -91,7 +91,8 @@ export default async function handler(req: NextApiRequest, res: NextApiResponse)
|
|||||||
messages: formatPrompts,
|
messages: formatPrompts,
|
||||||
frequency_penalty: 0.5, // 越大,重复内容越少
|
frequency_penalty: 0.5, // 越大,重复内容越少
|
||||||
presence_penalty: -0.5, // 越大,越容易出现新内容
|
presence_penalty: -0.5, // 越大,越容易出现新内容
|
||||||
stream: true
|
stream: true,
|
||||||
|
stop: ['.!?。']
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
timeout: 40000,
|
timeout: 40000,
|
||||||
|
|||||||
@ -40,7 +40,7 @@ export async function generateAbstract(next = false): Promise<any> {
|
|||||||
// 获取 openapi Key
|
// 获取 openapi Key
|
||||||
let userApiKey, systemKey;
|
let userApiKey, systemKey;
|
||||||
try {
|
try {
|
||||||
const key = await getOpenApiKey(dataItem.userId);
|
const key = await getOpenApiKey(dataItem.userId, true);
|
||||||
userApiKey = key.userApiKey;
|
userApiKey = key.userApiKey;
|
||||||
systemKey = key.systemKey;
|
systemKey = key.systemKey;
|
||||||
} catch (error: any) {
|
} catch (error: any) {
|
||||||
|
|||||||
@ -37,7 +37,7 @@ export async function generateQA(next = false): Promise<any> {
|
|||||||
// 获取 openapi Key
|
// 获取 openapi Key
|
||||||
let userApiKey, systemKey;
|
let userApiKey, systemKey;
|
||||||
try {
|
try {
|
||||||
const key = await getOpenApiKey(dataItem.userId);
|
const key = await getOpenApiKey(dataItem.userId, true);
|
||||||
userApiKey = key.userApiKey;
|
userApiKey = key.userApiKey;
|
||||||
systemKey = key.systemKey;
|
systemKey = key.systemKey;
|
||||||
} catch (error: any) {
|
} catch (error: any) {
|
||||||
|
|||||||
@ -35,7 +35,10 @@ export const authChat = async (chatId: string, authorization?: string) => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// 获取 user 的 apiKey
|
// 获取 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 的内容
|
// filter 掉被 deleted 的内容
|
||||||
chat.content = chat.content.filter((item) => item.deleted !== true);
|
chat.content = chat.content.filter((item) => item.deleted !== true);
|
||||||
|
|||||||
@ -97,7 +97,7 @@ export const getUserApiOpenai = async (userId: string) => {
|
|||||||
};
|
};
|
||||||
|
|
||||||
/* 获取 open api key,如果用户没有自己的key,就用平台的,用平台记得加账单 */
|
/* 获取 open api key,如果用户没有自己的key,就用平台的,用平台记得加账单 */
|
||||||
export const getOpenApiKey = async (userId: string) => {
|
export const getOpenApiKey = async (userId: string, checkGrant = false) => {
|
||||||
const user = await User.findById(userId);
|
const user = await User.findById(userId);
|
||||||
if (!user) {
|
if (!user) {
|
||||||
return Promise.reject('找不到用户');
|
return Promise.reject('找不到用户');
|
||||||
@ -108,12 +108,14 @@ export const getOpenApiKey = async (userId: string) => {
|
|||||||
// 有自己的key
|
// 有自己的key
|
||||||
if (userApiKey) {
|
if (userApiKey) {
|
||||||
// api 余额校验
|
// api 余额校验
|
||||||
const hasGrant = await checkKeyGrant(userApiKey);
|
if (checkGrant) {
|
||||||
if (!hasGrant) {
|
const hasGrant = await checkKeyGrant(userApiKey);
|
||||||
return Promise.reject({
|
if (!hasGrant) {
|
||||||
code: 501,
|
return Promise.reject({
|
||||||
message: 'API 余额不足'
|
code: 501,
|
||||||
});
|
message: 'API 余额不足'
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return {
|
return {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user