mirror of
https://github.com/labring/FastGPT.git
synced 2025-07-30 18:48:55 +00:00
4.6.3-website dataset (#532)
This commit is contained in:
@@ -14,10 +14,10 @@ import { getChatHistory } from './getHistory';
|
||||
import { saveChat } from '@/service/utils/chat/saveChat';
|
||||
import { responseWrite } from '@fastgpt/service/common/response';
|
||||
import { pushChatBill } from '@/service/support/wallet/bill/push';
|
||||
import { BillSourceEnum } from '@fastgpt/global/support/wallet/bill/constants';
|
||||
import { authOutLinkChat } from '@/service/support/permission/auth/outLink';
|
||||
import { pushResult2Remote, updateOutLinkUsage } from '@fastgpt/service/support/outLink/tools';
|
||||
import requestIp from 'request-ip';
|
||||
import { getBillSourceByAuthType } from '@fastgpt/global/support/wallet/bill/tools';
|
||||
|
||||
import { selectShareResponse } from '@/utils/service/core/chat';
|
||||
import { updateApiKeyUsage } from '@fastgpt/service/support/openapi/tools';
|
||||
@@ -276,11 +276,7 @@ export default withNextCors(async function handler(req: NextApiRequest, res: Nex
|
||||
appId: app._id,
|
||||
teamId: user.team.teamId,
|
||||
tmbId: user.team.tmbId,
|
||||
source: (() => {
|
||||
if (authType === 'apikey') return BillSourceEnum.api;
|
||||
if (shareId) return BillSourceEnum.shareLink;
|
||||
return BillSourceEnum.fastgpt;
|
||||
})(),
|
||||
source: getBillSourceByAuthType({ shareId, authType }),
|
||||
response: responseData
|
||||
});
|
||||
|
||||
|
@@ -6,6 +6,8 @@ import { pushGenerateVectorBill } from '@/service/support/wallet/bill/push';
|
||||
import { connectToDatabase } from '@/service/mongo';
|
||||
import { authTeamBalance } from '@/service/support/permission/auth/bill';
|
||||
import { getVectorsByText, GetVectorProps } from '@/service/core/ai/vector';
|
||||
import { updateApiKeyUsage } from '@fastgpt/service/support/openapi/tools';
|
||||
import { getBillSourceByAuthType } from '@fastgpt/global/support/wallet/bill/tools';
|
||||
|
||||
type Props = GetVectorProps & {
|
||||
billId?: string;
|
||||
@@ -15,24 +17,21 @@ export default withNextCors(async function handler(req: NextApiRequest, res: Nex
|
||||
try {
|
||||
let { input, model, billId } = req.body as Props;
|
||||
await connectToDatabase();
|
||||
const { teamId, tmbId } = await authCert({ req, authToken: true, authApiKey: true });
|
||||
|
||||
if (!Array.isArray(input) || typeof input !== 'string') {
|
||||
if (!Array.isArray(input) && typeof input !== 'string') {
|
||||
throw new Error('input is nor array or string');
|
||||
}
|
||||
|
||||
const { teamId, tmbId, apikey, authType } = await authCert({
|
||||
req,
|
||||
authToken: true,
|
||||
authApiKey: true
|
||||
});
|
||||
|
||||
await authTeamBalance(teamId);
|
||||
|
||||
const { tokenLen, vectors } = await getVectorsByText({ input, model });
|
||||
|
||||
pushGenerateVectorBill({
|
||||
teamId,
|
||||
tmbId,
|
||||
tokenLen: tokenLen,
|
||||
model,
|
||||
billId
|
||||
});
|
||||
|
||||
jsonRes(res, {
|
||||
data: {
|
||||
object: 'list',
|
||||
@@ -48,6 +47,22 @@ export default withNextCors(async function handler(req: NextApiRequest, res: Nex
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
const { total } = pushGenerateVectorBill({
|
||||
teamId,
|
||||
tmbId,
|
||||
tokenLen,
|
||||
model,
|
||||
billId,
|
||||
source: getBillSourceByAuthType({ authType })
|
||||
});
|
||||
|
||||
if (apikey) {
|
||||
updateApiKeyUsage({
|
||||
apikey,
|
||||
usage: total
|
||||
});
|
||||
}
|
||||
} catch (err) {
|
||||
console.log(err);
|
||||
jsonRes(res, {
|
||||
|
@@ -7,12 +7,13 @@ import { connectToDatabase } from '@/service/mongo';
|
||||
import { authTeamBalance } from '@/service/support/permission/auth/bill';
|
||||
import { PostReRankProps, PostReRankResponse } from '@fastgpt/global/core/ai/api';
|
||||
import { reRankRecall } from '@/service/core/ai/rerank';
|
||||
import { updateApiKeyUsage } from '@fastgpt/service/support/openapi/tools';
|
||||
|
||||
export default withNextCors(async function handler(req: NextApiRequest, res: NextApiResponse<any>) {
|
||||
let { query, inputs } = req.body as PostReRankProps;
|
||||
try {
|
||||
await connectToDatabase();
|
||||
const { teamId, tmbId } = await authCert({
|
||||
const { teamId, tmbId, apikey } = await authCert({
|
||||
req,
|
||||
authApiKey: true
|
||||
});
|
||||
@@ -23,12 +24,19 @@ export default withNextCors(async function handler(req: NextApiRequest, res: Nex
|
||||
|
||||
const result = await reRankRecall({ query, inputs });
|
||||
|
||||
pushReRankBill({
|
||||
const { total } = pushReRankBill({
|
||||
teamId,
|
||||
tmbId,
|
||||
source: 'api'
|
||||
});
|
||||
|
||||
if (apikey) {
|
||||
updateApiKeyUsage({
|
||||
apikey,
|
||||
usage: total
|
||||
});
|
||||
}
|
||||
|
||||
jsonRes<PostReRankResponse>(res, {
|
||||
data: result
|
||||
});
|
||||
|
Reference in New Issue
Block a user