perrf chat不请求余额

This commit is contained in:
archer
2023-03-31 14:13:00 +08:00
parent df9ac99ef2
commit a3d74ec4a6
5 changed files with 17 additions and 11 deletions

View File

@@ -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,12 +108,14 @@ export const getOpenApiKey = async (userId: string) => {
// 有自己的key
if (userApiKey) {
// api 余额校验
const hasGrant = await checkKeyGrant(userApiKey);
if (!hasGrant) {
return Promise.reject({
code: 501,
message: 'API 余额不足'
});
if (checkGrant) {
const hasGrant = await checkKeyGrant(userApiKey);
if (!hasGrant) {
return Promise.reject({
code: 501,
message: 'API 余额不足'
});
}
}
return {