1
1
/*
2
2
* @Author: Vincent Yang
3
3
* @Date: 2024-04-16 22:58:22
4
- * @LastEditors: Vincent Yang
5
- * @LastEditTime: 2024-04-18 20:13:27
4
+ * @LastEditors: Vincent Young
5
+ * @LastEditTime: 2024-04-19 03:45:05
6
6
* @FilePath: /cohere2openai/main.go
7
7
* @Telegram: https://t.me/missuo
8
8
* @GitHub: https://github.com/missuo
@@ -45,6 +45,7 @@ func cohereRequest(c *gin.Context, openAIReq OpenAIRequest) {
45
45
ChatHistory : []ChatMessage {},
46
46
Message : "" ,
47
47
Stream : openAIReq .Stream ,
48
+ MaxTokens : openAIReq .MaxTokens ,
48
49
}
49
50
50
51
for _ , msg := range openAIReq .Messages {
@@ -67,6 +68,7 @@ func cohereRequest(c *gin.Context, openAIReq OpenAIRequest) {
67
68
}
68
69
69
70
reqBody , _ := json .Marshal (cohereReq )
71
+ fmt .Println (string (reqBody ))
70
72
req , err := http .NewRequest ("POST" , "https://api.cohere.ai/v1/chat" , bytes .NewBuffer (reqBody ))
71
73
if err != nil {
72
74
c .JSON (http .StatusInternalServerError , gin.H {"error" : err .Error ()})
@@ -180,6 +182,7 @@ func cohereNonStreamRequest(c *gin.Context, openAIReq OpenAIRequest) {
180
182
ChatHistory : []ChatMessage {},
181
183
Message : "" ,
182
184
Stream : openAIReq .Stream ,
185
+ MaxTokens : openAIReq .MaxTokens ,
183
186
}
184
187
185
188
for _ , msg := range openAIReq .Messages {
@@ -261,6 +264,25 @@ func handler(c *gin.Context) {
261
264
if ! isInSlice (openAIReq .Model , allowModels ) {
262
265
openAIReq .Model = "command-r-plus"
263
266
}
267
+
268
+ // Set max tokens based on model
269
+ switch openAIReq .Model {
270
+ case "command-light" :
271
+ openAIReq .MaxTokens = 4000
272
+ case "command" :
273
+ openAIReq .MaxTokens = 4000
274
+ case "command-light-nightly" :
275
+ openAIReq .MaxTokens = 4000
276
+ case "command-nightly" :
277
+ openAIReq .MaxTokens = 4000
278
+ case "command-r" :
279
+ openAIReq .MaxTokens = 4000
280
+ case "command-r-plus" :
281
+ openAIReq .MaxTokens = 4000
282
+ default :
283
+ openAIReq .MaxTokens = 4096
284
+ }
285
+
264
286
if openAIReq .Stream {
265
287
cohereRequest (c , openAIReq )
266
288
} else {
0 commit comments