mirror of
https://github.com/labring/FastGPT.git
synced 2025-08-01 11:58:38 +00:00
v4.6.2 (#523)
This commit is contained in:
@@ -15,7 +15,7 @@ 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 });
|
||||
const { teamId, tmbId } = await authCert({ req, authToken: true, authApiKey: true });
|
||||
|
||||
if (!Array.isArray(input) || typeof input !== 'string') {
|
||||
throw new Error('input is nor array or string');
|
||||
|
42
projects/app/src/pages/api/v1/rerank.ts
Normal file
42
projects/app/src/pages/api/v1/rerank.ts
Normal file
@@ -0,0 +1,42 @@
|
||||
import type { NextApiRequest, NextApiResponse } from 'next';
|
||||
import { jsonRes } from '@fastgpt/service/common/response';
|
||||
import { authCert } from '@fastgpt/service/support/permission/auth/common';
|
||||
import { withNextCors } from '@fastgpt/service/common/middle/cors';
|
||||
import { pushReRankBill } from '@/service/support/wallet/bill/push';
|
||||
import { connectToDatabase } from '@/service/mongo';
|
||||
import { authTeamBalance } from '@/service/support/permission/auth/bill';
|
||||
import { PostReRankProps } from '@fastgpt/global/core/ai/api';
|
||||
import { reRankRecall } from '@/service/core/ai/rerank';
|
||||
|
||||
export default withNextCors(async function handler(req: NextApiRequest, res: NextApiResponse<any>) {
|
||||
try {
|
||||
let { query, inputs } = req.body as PostReRankProps;
|
||||
await connectToDatabase();
|
||||
const { teamId, tmbId } = await authCert({
|
||||
req,
|
||||
authApiKey: true
|
||||
});
|
||||
await authTeamBalance(teamId);
|
||||
|
||||
// max 150 length
|
||||
inputs = inputs.slice(0, 150);
|
||||
|
||||
const result = await reRankRecall({ query, inputs });
|
||||
|
||||
pushReRankBill({
|
||||
teamId,
|
||||
tmbId,
|
||||
source: 'api'
|
||||
});
|
||||
|
||||
jsonRes(res, {
|
||||
data: result
|
||||
});
|
||||
} catch (err) {
|
||||
console.log(err);
|
||||
jsonRes(res, {
|
||||
code: 500,
|
||||
error: err
|
||||
});
|
||||
}
|
||||
});
|
Reference in New Issue
Block a user