Skip to content

feat: expose richer model metadata in v1/models#721

Open
VedantMadane wants to merge 1 commit intodocker:mainfrom
VedantMadane:feat/rich-model-metadata
Open

feat: expose richer model metadata in v1/models#721
VedantMadane wants to merge 1 commit intodocker:mainfrom
VedantMadane:feat/rich-model-metadata

Conversation

@VedantMadane
Copy link

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:

  • \context_window: Maximum context length supported by the model.
  • \�rchitecture: Technical architecture of the model.
  • \parameters: Description of model parameters.
  • \quantization: Quantization method used.
  • \size: Parameter size (e.g., " 8B).

Enrich OpenAIModel schema with additional metadata:
- context_window
- architecture
- parameters
- quantization
- size

This allows client applications to better understand model capabilities.
Copy link
Contributor

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey - I've reviewed your changes and they look great!


Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment on lines +85 to 105
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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

critical

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

@doringeman
Copy link
Contributor

Hey @VedantMadane, why do you need this?
This API you've modified corresponds with the official List models.
Isn't /models what you're looking for? E.g., curl -s http://localhost:12434/models | jq .

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Enhancement: Expose richer model metadata in /engines/v1/models (similar to OpenRouter)

2 participants