fix: fix rerank

This commit is contained in:
CalciumIon 2024-07-06 17:28:00 +08:00
parent 8af4e28f75
commit 1735e093db
2 changed files with 5 additions and 3 deletions

View File

@ -4,6 +4,7 @@ import (
"fmt" "fmt"
"github.com/gin-gonic/gin" "github.com/gin-gonic/gin"
"io" "io"
"log"
"net/http" "net/http"
"one-api/dto" "one-api/dto"
"one-api/relay/channel" "one-api/relay/channel"
@ -39,6 +40,7 @@ func (a *Adaptor) ConvertRequest(c *gin.Context, relayMode int, request *dto.Gen
} }
func (a *Adaptor) DoRequest(c *gin.Context, info *relaycommon.RelayInfo, requestBody io.Reader) (*http.Response, error) { func (a *Adaptor) DoRequest(c *gin.Context, info *relaycommon.RelayInfo, requestBody io.Reader) (*http.Response, error) {
log.Printf("requestBody: %v", requestBody)
return channel.DoApiRequest(a, c, info, requestBody) return channel.DoApiRequest(a, c, info, requestBody)
} }

View File

@ -48,6 +48,9 @@ func requestOpenAI2Cohere(textRequest dto.GeneralOpenAIRequest) *CohereRequest {
} }
func requestConvertRerank2Cohere(rerankRequest dto.RerankRequest) *CohereRerankRequest { func requestConvertRerank2Cohere(rerankRequest dto.RerankRequest) *CohereRerankRequest {
if rerankRequest.TopN == 0 {
rerankRequest.TopN = 1
}
cohereReq := CohereRerankRequest{ cohereReq := CohereRerankRequest{
Query: rerankRequest.Query, Query: rerankRequest.Query,
Documents: rerankRequest.Documents, Documents: rerankRequest.Documents,
@ -55,9 +58,6 @@ func requestConvertRerank2Cohere(rerankRequest dto.RerankRequest) *CohereRerankR
TopN: rerankRequest.TopN, TopN: rerankRequest.TopN,
ReturnDocuments: true, ReturnDocuments: true,
} }
for _, doc := range rerankRequest.Documents {
cohereReq.Documents = append(cohereReq.Documents, doc)
}
return &cohereReq return &cohereReq
} }