feat: expose richer model metadata in v1/models#721
feat: expose richer model metadata in v1/models#721VedantMadane wants to merge 1 commit intodocker:mainfrom
Conversation
Enrich OpenAIModel schema with additional metadata: - context_window - architecture - parameters - quantization - size This allows client applications to better understand model capabilities.
There was a problem hiding this comment.
Code Review
This pull request enhances the /v1/models endpoint by including additional metadata for each model, such as context window size and architecture. The changes look good, but I've found a critical issue where the code could panic if a model's configuration is missing. I've provided a suggestion to handle this case gracefully.
| config, err := m.Config() | ||
| if err != nil { | ||
| return nil, fmt.Errorf("get config: %w", err) | ||
| } | ||
|
|
||
| var contextWindow int32 | ||
| if cw := config.GetContextSize(); cw != nil { | ||
| contextWindow = *cw | ||
| } | ||
|
|
||
| return &OpenAIModel{ | ||
| ID: id, | ||
| Object: "model", | ||
| Created: created, | ||
| OwnedBy: "docker", | ||
| ID: id, | ||
| Object: "model", | ||
| Created: created, | ||
| OwnedBy: "docker", | ||
| ContextWindow: contextWindow, | ||
| Architecture: config.GetArchitecture(), | ||
| Parameters: config.GetParameters(), | ||
| Quantization: config.GetQuantization(), | ||
| Size: config.GetSize(), | ||
| }, nil |
There was a problem hiding this comment.
The m.Config() method can return a nil config with a nil error. If this happens, the subsequent calls to methods on config (e.g., config.GetContextSize() on line 91) will cause a nil pointer dereference, leading to a panic. You should add a check to handle the case where config is nil.
config, err := m.Config()
if err != nil {
return nil, fmt.Errorf("get config: %w", err)
}
if config == nil {
// If there's no config, return the model with only basic info.
return &OpenAIModel{
ID: id,
Object: "model",
Created: created,
OwnedBy: "docker",
}, nil
}
var contextWindow int32
if cw := config.GetContextSize(); cw != nil {
contextWindow = *cw
}
return &OpenAIModel{
ID: id,
Object: "model",
Created: created,
OwnedBy: "docker",
ContextWindow: contextWindow,
Architecture: config.GetArchitecture(),
Parameters: config.GetParameters(),
Quantization: config.GetQuantization(),
Size: config.GetSize(),
}, nil|
Hey @VedantMadane, why do you need this? |
Fixes #143.
This PR expands the model schema returned by the /v1/models\ endpoint to include additional metadata about each model, similar to what other providers like OpenRouter expose.
New fields added to OpenAIModel: