Skip to content

Commit

Permalink
feat: support cohere's web search
Browse files Browse the repository at this point in the history
  • Loading branch information
songquanpeng committed Apr 26, 2024
1 parent ea210b6 commit e64e770
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 0 deletions.
7 changes: 7 additions & 0 deletions relay/adaptor/cohere/constant.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,10 @@ var ModelList = []string{
"command-light", "command-light-nightly",
"command-r", "command-r-plus",
}

func init() {
num := len(ModelList)
for i := 0; i < num; i++ {
ModelList = append(ModelList, ModelList[i]+"-internet")
}
}
8 changes: 8 additions & 0 deletions relay/adaptor/cohere/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@ import (
"github.com/songquanpeng/one-api/relay/model"
)

var (
WebSearchConnector = Connector{ID: "web-search"}
)

func stopReasonCohere2OpenAI(reason *string) string {
if reason == nil {
return ""
Expand Down Expand Up @@ -45,6 +49,10 @@ func ConvertRequest(textRequest model.GeneralOpenAIRequest) *Request {
if cohereRequest.Model == "" {
cohereRequest.Model = "command-r"
}
if strings.HasSuffix(cohereRequest.Model, "-internet") {
cohereRequest.Model = strings.TrimSuffix(cohereRequest.Model, "-internet")
cohereRequest.Connectors = append(cohereRequest.Connectors, WebSearchConnector)
}
for _, message := range textRequest.Messages {
if message.Role == "user" {
cohereRequest.Message = message.Content.(string)
Expand Down
3 changes: 3 additions & 0 deletions relay/billing/ratio/model.go
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,9 @@ func GetModelRatio(name string) float64 {
if strings.HasPrefix(name, "qwen-") && strings.HasSuffix(name, "-internet") {
name = strings.TrimSuffix(name, "-internet")
}
if strings.HasPrefix(name, "command-") && strings.HasSuffix(name, "-internet") {
name = strings.TrimSuffix(name, "-internet")
}
ratio, ok := ModelRatio[name]
if !ok {
ratio, ok = DefaultModelRatio[name]
Expand Down

0 comments on commit e64e770

Please sign in to comment.