rerank api (#525)

This commit is contained in:
Archer
2023-11-28 21:13:15 +08:00
committed by GitHub
parent a74e1d7166
commit abc1e576b7
3 changed files with 9 additions and 8 deletions

View File

@@ -2,4 +2,4 @@ export type PostReRankProps = {
query: string;
inputs: { id: string; text: string }[];
};
export type PostReRankResponse = { id: string; score: number }[];
export type PostReRankResponse = { id: string; score?: number }[];

View File

@@ -5,12 +5,12 @@ 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 { PostReRankProps, PostReRankResponse } 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;
try {
await connectToDatabase();
const { teamId, tmbId } = await authCert({
req,
@@ -29,14 +29,15 @@ export default withNextCors(async function handler(req: NextApiRequest, res: Nex
source: 'api'
});
jsonRes(res, {
jsonRes<PostReRankResponse>(res, {
data: result
});
} catch (err) {
console.log(err);
jsonRes(res, {
code: 500,
error: err
jsonRes<PostReRankResponse>(res, {
data: inputs.map((input) => ({
id: input.id
}))
});
}
});

View File

@@ -398,7 +398,7 @@ export async function reRankSearchResult({
if (!target) return null;
return {
...target,
score: item.score || 0
score: item.score || target.score
};
})
.filter(Boolean) as SearchDataResponseItemType[];