Skip to content

feat(go/ollama): implement DynamicPlugin for dynamic model discovery#4529

Open
Zereker wants to merge 5 commits intofirebase:mainfrom
Zereker:feat/go-ollama-dynamic-models
Open

feat(go/ollama): implement DynamicPlugin for dynamic model discovery#4529
Zereker wants to merge 5 commits intofirebase:mainfrom
Zereker:feat/go-ollama-dynamic-models

Conversation

@Zereker
Copy link
Contributor

@Zereker Zereker commented Feb 9, 2026

Summary

  • Implement DynamicPlugin interface (ListActions + ResolveAction) on the Ollama plugin to support dynamic model discovery via /api/tags
  • Models not in the hardcoded lists (e.g. moondream:v2) can now be used without manual DefineModel calls
  • Embedding models are filtered out automatically (name contains embed)

Fixes #4490

Changes

  • Added listLocalModels() to call Ollama's GET /api/tags endpoint
  • Added newModel() helper to create model instances without registry registration
  • Implemented ListActions() to enumerate locally installed models
  • Implemented ResolveAction() to create models on demand
  • Fully backward compatible: DefineModel and hardcoded capability lists preserved

Design Notes (referencing JS implementation)

This implementation follows the JS plugin (js/plugins/ollama/src/index.ts) as closely as possible:

Media support: defaultOllamaSupports sets Media: true for all dynamically discovered models, matching JS's GENERIC_MODEL_INFO. Note that the existing generate function restricts image extraction to a hardcoded mediaSupportedModels list — this is a pre-existing limitation in the Go plugin, not introduced by this PR. The JS implementation does not check model capabilities before sending images (it unconditionally forwards images to Ollama). Fixing the Go generate function to match JS behavior (removing the hardcoded media check) is a separate concern and should be addressed in a follow-up PR.

Timeout for /api/tags: The JS implementation (listLocalModels at line 167-188) does not set an explicit timeout on the fetch call either, relying on default behavior. Our Go implementation uses http.NewRequestWithContext, so callers can control timeout via context. Adding an explicit http.Client timeout could be done as a follow-up improvement but is not required for parity with the JS version.

Test plan

  • go build ./plugins/ollama/ passes
  • go vet ./plugins/ollama/ passes
  • go test ./plugins/ollama/ -v — all unit tests pass
  • Integration test with local Ollama service (go test ./plugins/ollama/ -v -test-live) — ListActions discovered 2 local models, ResolveAction dynamically resolved moondream (not in hardcoded lists), and generated a response successfully

Implement ListActions and ResolveAction on the Ollama plugin so that
locally installed models are discovered automatically via /api/tags,
removing the need for users to manually register every model.

Fixes firebase#4490
@gemini-code-assist
Copy link
Contributor

Summary of Changes

Hello @Zereker, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request significantly enhances the Ollama plugin's flexibility by introducing dynamic model discovery. By implementing the DynamicPlugin interface, the plugin can now automatically identify and make available locally installed Ollama models, eliminating the need for manual configuration of new models. This streamlines the user experience and ensures broader compatibility with the diverse range of models available in the Ollama ecosystem.

Highlights

  • Dynamic Model Discovery: The Ollama plugin now implements the DynamicPlugin interface, enabling automatic discovery of locally installed models through the /api/tags endpoint.
  • Reduced Manual Configuration: Users can now utilize models not explicitly defined in hardcoded lists (e.g., moondream:v2) without needing manual DefineModel calls.
  • Embedding Model Filtering: Embedding models are automatically filtered out during discovery, preventing their accidental use in chat contexts.
  • Backward Compatibility: The changes are fully backward compatible, preserving existing DefineModel functionality and hardcoded capability lists.

🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console.

Changelog
  • go/plugins/ollama/ollama.go
    • Added log/slog import for structured logging.
    • Introduced defaultOllamaSupports to define default capabilities for dynamically discovered models.
    • Defined ollamaTagsResponse and ollamaLocalModel structs for parsing the /api/tags response.
    • Implemented listLocalModels function to fetch local Ollama models from the /api/tags endpoint.
    • Added newModel helper function to create ai.Model instances without Genkit registry registration.
    • Implemented ListActions to discover and return descriptions of available local Ollama models, excluding embedding models.
    • Implemented ResolveAction to dynamically create and return an ai.Model action based on a requested name.
Activity
  • The pull request was created by Zereker, introducing dynamic model discovery for the Ollama plugin.
  • No human activity (comments, reviews) has been recorded on this pull request yet.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

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 introduces dynamic model discovery for the Ollama plugin, allowing models not explicitly defined to be used via the /api/tags endpoint. The implementation includes new types for Ollama API responses, a function to list local models, and methods to implement the DynamicPlugin interface (newModel, ListActions, ResolveAction). The changes are generally well-structured, but there are a few areas related to efficiency and correctness that could be improved, particularly around HTTP client reuse and assumptions about dynamically discovered model types.

Add tests for listLocalModels, ListActions, ResolveAction and newModel,
covering success paths, embed model filtering, server errors, and
non-model action type rejection.
Add TestLiveDynamicDiscovery to verify that models not in hardcoded
lists can be discovered via ListActions and used via ResolveAction
with a real Ollama server.
…icPlugin

Group listLocalModels, ListActions, ResolveAction, and newModel tests
into a single TestDynamicPlugin with t.Run subtests.
…test

The test appended ":latest" to the model name flag, which broke models
with explicit tags like moondream:v2 (producing moondream:v2:latest).
Use the flag value directly since /api/tags already returns full names.
@hugoaguirre hugoaguirre self-requested a review February 9, 2026 16:10
@apascal07 apascal07 self-requested a review February 11, 2026 17:34
@apascal07
Copy link
Collaborator

Thank you @Zereker for the contribution!

@hugoaguirre please test this out

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

Labels

Projects

Status: No status

Development

Successfully merging this pull request may close these issues.

[Go] Cannot use moon dream:v2 with Ollama plugin

2 participants