@@ -222,6 +222,8 @@ func escapeJSON(str string) string {
222
222
return string (b [1 : len (b )- 1 ])
223
223
}
224
224
225
+ var allowModels = []string {"claude-3-haiku-20240307" , "claude-3-sonnet-20240229" , "claude-3-opus-20240229" , "claude-3-5-sonnet-20240620" }
226
+
225
227
func handler (c * gin.Context ) {
226
228
var openAIReq OpenAIRequest
227
229
@@ -230,11 +232,9 @@ func handler(c *gin.Context) {
230
232
return
231
233
}
232
234
233
- allowModels := []string {"claude-3-haiku-20240307" , "claude-3-sonnet-20240229" , "claude-3-opus-20240229" }
234
-
235
235
// Default model is claude-3-haiku-20240307
236
236
if ! isInSlice (openAIReq .Model , allowModels ) {
237
- openAIReq .Model = "claude-3-haiku-20240307"
237
+ openAIReq .Model = allowModels [ 0 ]
238
238
}
239
239
240
240
// If stream is true, proxy to Claude with stream
@@ -245,6 +245,20 @@ func handler(c *gin.Context) {
245
245
}
246
246
}
247
247
248
+ func modelsHandler (c * gin.Context ) {
249
+ openAIResp := OpenAIModelsResponse {
250
+ Object : "list" ,
251
+ }
252
+ for _ , model := range allowModels {
253
+ openAIResp .Data = append (openAIResp .Data , OpenAIModel {
254
+ ID : model ,
255
+ Object : "model" ,
256
+ OwnedBy : "user" ,
257
+ })
258
+ }
259
+ c .JSON (http .StatusOK , openAIResp )
260
+ }
261
+
248
262
func isInSlice (str string , list []string ) bool {
249
263
for _ , item := range list {
250
264
if item == str {
@@ -264,6 +278,7 @@ func main() {
264
278
})
265
279
})
266
280
r .POST ("/v1/chat/completions" , handler )
281
+ r .GET ("/v1/models" , modelsHandler )
267
282
r .NoRoute (func (c * gin.Context ) {
268
283
c .JSON (http .StatusNotFound , gin.H {
269
284
"code" : http .StatusNotFound ,
0 commit comments