Skip to content

Commit

Permalink
rerank api (labring#525)
Browse files Browse the repository at this point in the history
  • Loading branch information
c121914yu authored Nov 28, 2023
1 parent a74e1d7 commit abc1e57
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 8 deletions.
2 changes: 1 addition & 1 deletion packages/global/core/ai/api.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 }[];
13 changes: 7 additions & 6 deletions projects/app/src/pages/api/v1/rerank.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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>) {
let { query, inputs } = req.body as PostReRankProps;
try {
let { query, inputs } = req.body as PostReRankProps;
await connectToDatabase();
const { teamId, tmbId } = await authCert({
req,
Expand All @@ -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
}))
});
}
});
2 changes: 1 addition & 1 deletion projects/app/src/service/core/dataset/data/pg.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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[];
Expand Down

0 comments on commit abc1e57

Please sign in to comment.