Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
赵月辉
/
fastgpt-migrated
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Snippets
Members
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Unverified
Commit
abc1e576
authored
Nov 28, 2023
by
Archer
Committed by
GitHub
Nov 28, 2023
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
rerank api (#525)
parent
a74e1d71
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
9 additions
and
8 deletions
+9
-8
packages/global/core/ai/api.d.ts
+1
-1
projects/app/src/pages/api/v1/rerank.ts
+7
-6
projects/app/src/service/core/dataset/data/pg.ts
+1
-1
No files found.
packages/global/core/ai/api.d.ts
View file @
abc1e576
...
@@ -2,4 +2,4 @@ export type PostReRankProps = {
...
@@ -2,4 +2,4 @@ export type PostReRankProps = {
query
:
string
;
query
:
string
;
inputs
:
{
id
:
string
;
text
:
string
}[];
inputs
:
{
id
:
string
;
text
:
string
}[];
};
};
export
type
PostReRankResponse
=
{
id
:
string
;
score
:
number
}[];
export
type
PostReRankResponse
=
{
id
:
string
;
score
?
:
number
}[];
projects/app/src/pages/api/v1/rerank.ts
View file @
abc1e576
...
@@ -5,12 +5,12 @@ import { withNextCors } from '@fastgpt/service/common/middle/cors';
...
@@ -5,12 +5,12 @@ import { withNextCors } from '@fastgpt/service/common/middle/cors';
import
{
pushReRankBill
}
from
'@/service/support/wallet/bill/push'
;
import
{
pushReRankBill
}
from
'@/service/support/wallet/bill/push'
;
import
{
connectToDatabase
}
from
'@/service/mongo'
;
import
{
connectToDatabase
}
from
'@/service/mongo'
;
import
{
authTeamBalance
}
from
'@/service/support/permission/auth/bill'
;
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'
;
import
{
reRankRecall
}
from
'@/service/core/ai/rerank'
;
export
default
withNextCors
(
async
function
handler
(
req
:
NextApiRequest
,
res
:
NextApiResponse
<
any
>
)
{
export
default
withNextCors
(
async
function
handler
(
req
:
NextApiRequest
,
res
:
NextApiResponse
<
any
>
)
{
try
{
let
{
query
,
inputs
}
=
req
.
body
as
PostReRankProps
;
let
{
query
,
inputs
}
=
req
.
body
as
PostReRankProps
;
try
{
await
connectToDatabase
();
await
connectToDatabase
();
const
{
teamId
,
tmbId
}
=
await
authCert
({
const
{
teamId
,
tmbId
}
=
await
authCert
({
req
,
req
,
...
@@ -29,14 +29,15 @@ export default withNextCors(async function handler(req: NextApiRequest, res: Nex
...
@@ -29,14 +29,15 @@ export default withNextCors(async function handler(req: NextApiRequest, res: Nex
source
:
'api'
source
:
'api'
});
});
jsonRes
(
res
,
{
jsonRes
<
PostReRankResponse
>
(
res
,
{
data
:
result
data
:
result
});
});
}
catch
(
err
)
{
}
catch
(
err
)
{
console
.
log
(
err
);
console
.
log
(
err
);
jsonRes
(
res
,
{
jsonRes
<
PostReRankResponse
>
(
res
,
{
code
:
500
,
data
:
inputs
.
map
((
input
)
=>
({
error
:
err
id
:
input
.
id
}))
});
});
}
}
});
});
projects/app/src/service/core/dataset/data/pg.ts
View file @
abc1e576
...
@@ -398,7 +398,7 @@ export async function reRankSearchResult({
...
@@ -398,7 +398,7 @@ export async function reRankSearchResult({
if
(
!
target
)
return
null
;
if
(
!
target
)
return
null
;
return
{
return
{
...
target
,
...
target
,
score
:
item
.
score
||
0
score
:
item
.
score
||
target
.
score
};
};
})
})
.
filter
(
Boolean
)
as
SearchDataResponseItemType
[];
.
filter
(
Boolean
)
as
SearchDataResponseItemType
[];
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment