mirror of
https://github.com/router-for-me/CLIProxyAPI.git
synced 2026-02-03 04:50:52 +08:00
Filter OpenAI models response to include only essential fields (id, object, created, owned_by).
This commit is contained in:
@@ -60,9 +60,33 @@ func (h *OpenAIAPIHandler) Models() []map[string]any {
|
||||
// It returns a list of available AI models with their capabilities
|
||||
// and specifications in OpenAI-compatible format.
|
||||
func (h *OpenAIAPIHandler) OpenAIModels(c *gin.Context) {
|
||||
// Get all available models
|
||||
allModels := h.Models()
|
||||
|
||||
// Filter to only include the 4 required fields: id, object, created, owned_by
|
||||
filteredModels := make([]map[string]any, len(allModels))
|
||||
for i, model := range allModels {
|
||||
filteredModel := map[string]any{
|
||||
"id": model["id"],
|
||||
"object": model["object"],
|
||||
}
|
||||
|
||||
// Add created field if it exists
|
||||
if created, exists := model["created"]; exists {
|
||||
filteredModel["created"] = created
|
||||
}
|
||||
|
||||
// Add owned_by field if it exists
|
||||
if ownedBy, exists := model["owned_by"]; exists {
|
||||
filteredModel["owned_by"] = ownedBy
|
||||
}
|
||||
|
||||
filteredModels[i] = filteredModel
|
||||
}
|
||||
|
||||
c.JSON(http.StatusOK, gin.H{
|
||||
"object": "list",
|
||||
"data": h.Models(),
|
||||
"data": filteredModels,
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user