@@ -8,16 +8,24 @@ import (
88 "one-api/dto"
99 "one-api/relay/channel"
1010 relaycommon "one-api/relay/common"
11+ "one-api/relay/constant"
1112)
1213
1314type Adaptor struct {
1415}
1516
17+ func (a * Adaptor ) InitRerank (info * relaycommon.RelayInfo , request dto.RerankRequest ) {
18+ }
19+
1620func (a * Adaptor ) Init (info * relaycommon.RelayInfo , request dto.GeneralOpenAIRequest ) {
1721}
1822
1923func (a * Adaptor ) GetRequestURL (info * relaycommon.RelayInfo ) (string , error ) {
20- return fmt .Sprintf ("%s/v1/chat" , info .BaseUrl ), nil
24+ if info .RelayMode == constant .RelayModeRerank {
25+ return fmt .Sprintf ("%s/v1/rerank" , info .BaseUrl ), nil
26+ } else {
27+ return fmt .Sprintf ("%s/v1/chat" , info .BaseUrl ), nil
28+ }
2129}
2230
2331func (a * Adaptor ) SetupRequestHeader (c * gin.Context , req * http.Request , info * relaycommon.RelayInfo ) error {
@@ -34,11 +42,19 @@ func (a *Adaptor) DoRequest(c *gin.Context, info *relaycommon.RelayInfo, request
3442 return channel .DoApiRequest (a , c , info , requestBody )
3543}
3644
45+ func (a * Adaptor ) ConvertRerankRequest (c * gin.Context , relayMode int , request dto.RerankRequest ) (any , error ) {
46+ return requestConvertRerank2Cohere (request ), nil
47+ }
48+
3749func (a * Adaptor ) DoResponse (c * gin.Context , resp * http.Response , info * relaycommon.RelayInfo ) (usage * dto.Usage , err * dto.OpenAIErrorWithStatusCode ) {
38- if info .IsStream {
39- err , usage = cohereStreamHandler (c , resp , info )
50+ if info .RelayMode == constant . RelayModeRerank {
51+ err , usage = cohereRerankHandler (c , resp , info )
4052 } else {
41- err , usage = cohereHandler (c , resp , info .UpstreamModelName , info .PromptTokens )
53+ if info .IsStream {
54+ err , usage = cohereStreamHandler (c , resp , info )
55+ } else {
56+ err , usage = cohereHandler (c , resp , info .UpstreamModelName , info .PromptTokens )
57+ }
4258 }
4359 return
4460}
0 commit comments