Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
phsl
/
new-api
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
Commit
4f616724
authored
Mar 17, 2025
by
1808837298@qq.com
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
feat: Update RerankerInfo structure and modify GenRelayInfoRerank function to accept RerankRequest
parent
eafbfac6
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
25 additions
and
15 deletions
+25
-15
dto/rerank.go
+8
-1
relay/common/relay_info.go
+5
-3
relay/common_handler/rerank.go
+11
-10
relay/relay_rerank.go
+1
-1
No files found.
dto/rerank.go
View file @
4f616724
...
...
@@ -5,11 +5,18 @@ type RerankRequest struct {
Query
string
`json:"query"`
Model
string
`json:"model"`
TopN
int
`json:"top_n"`
ReturnDocuments
bool
`json:"return_documents,omitempty"`
ReturnDocuments
*
bool
`json:"return_documents,omitempty"`
MaxChunkPerDoc
int
`json:"max_chunk_per_doc,omitempty"`
OverLapTokens
int
`json:"overlap_tokens,omitempty"`
}
func
(
r
*
RerankRequest
)
GetReturnDocuments
()
bool
{
if
r
.
ReturnDocuments
==
nil
{
return
false
}
return
*
r
.
ReturnDocuments
}
type
RerankResponseResult
struct
{
Document
any
`json:"document,omitempty"`
Index
int
`json:"index"`
...
...
relay/common/relay_info.go
View file @
4f616724
...
...
@@ -34,7 +34,8 @@ const (
)
type
RerankerInfo
struct
{
Documents
[]
any
Documents
[]
any
ReturnDocuments
bool
}
type
RelayInfo
struct
{
...
...
@@ -116,11 +117,12 @@ func GenRelayInfoClaude(c *gin.Context) *RelayInfo {
return
info
}
func
GenRelayInfoRerank
(
c
*
gin
.
Context
,
documents
[]
any
)
*
RelayInfo
{
func
GenRelayInfoRerank
(
c
*
gin
.
Context
,
req
*
dto
.
RerankRequest
)
*
RelayInfo
{
info
:=
GenRelayInfo
(
c
)
info
.
RelayMode
=
relayconstant
.
RelayModeRerank
info
.
RerankerInfo
=
&
RerankerInfo
{
Documents
:
documents
,
Documents
:
req
.
Documents
,
ReturnDocuments
:
req
.
GetReturnDocuments
(),
}
return
info
}
...
...
relay/common_handler/rerank.go
View file @
4f616724
...
...
@@ -32,19 +32,20 @@ func RerankHandler(c *gin.Context, info *relaycommon.RelayInfo, resp *http.Respo
}
jinaRespResults
:=
make
([]
dto
.
RerankResponseResult
,
len
(
xinRerankResponse
.
Results
))
for
i
,
result
:=
range
xinRerankResponse
.
Results
{
var
document
any
if
result
.
Document
==
""
{
document
=
info
.
Documents
[
result
.
Index
]
}
else
{
document
=
result
.
Document
}
jinaRespResults
[
i
]
=
dto
.
RerankResponseResult
{
respResult
:=
dto
.
RerankResponseResult
{
Index
:
result
.
Index
,
RelevanceScore
:
result
.
RelevanceScore
,
Document
:
dto
.
RerankDocument
{
Text
:
document
,
},
}
if
info
.
ReturnDocuments
{
var
document
any
if
result
.
Document
==
""
{
document
=
info
.
Documents
[
result
.
Index
]
}
else
{
document
=
result
.
Document
}
respResult
.
Document
=
document
}
jinaRespResults
[
i
]
=
respResult
}
jinaResp
=
dto
.
RerankResponse
{
Results
:
jinaRespResults
,
...
...
relay/relay_rerank.go
View file @
4f616724
...
...
@@ -33,7 +33,7 @@ func RerankHelper(c *gin.Context, relayMode int) (openaiErr *dto.OpenAIErrorWith
return
service
.
OpenAIErrorWrapperLocal
(
err
,
"invalid_text_request"
,
http
.
StatusBadRequest
)
}
relayInfo
:=
relaycommon
.
GenRelayInfoRerank
(
c
,
rerankRequest
.
Documents
)
relayInfo
:=
relaycommon
.
GenRelayInfoRerank
(
c
,
rerankRequest
)
if
rerankRequest
.
Query
==
""
{
return
service
.
OpenAIErrorWrapperLocal
(
fmt
.
Errorf
(
"query is empty"
),
"invalid_query"
,
http
.
StatusBadRequest
)
...
...
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