Skip to content

Conversation

@simakmak
Copy link

@simakmak simakmak commented Jan 2, 2026

Description

Add support for runtime generation options and thinking modes in Ollama integration.

  • Introduces GenerateContentConfig with:

    • Think (Ollama: true/false; GPT-OSS: "low" | "medium" | "high")
    • Runtime options: Temperature, TopK, TopP, MinP, Stop, NumCtx, NumPredict
    • Ollama-specific: KeepAlive
  • Adds applyGenerateConfigToOllama to map config into ollamaChatRequest (Think + Options)

  • Ensures Thinking content from model is mapped into ai.ReasoningPart

Example usage:

genkit.Generate(ctx, g,
    ai.WithSystem(systemPostPrompt),
    ai.WithPrompt(in),
    ai.WithModel(llm),
    ai.WithTools(tools...),
    ai.WithConfig(
        ollama.GenerateContentConfig{
            Think:       true,
            Temperature: genai.Ptr[float64](0.2),
        },
    ),
)

Checklist

  • PR title follows [[Conventional Commits](https://www.conventionalcommits.org/en/v1.0.0/)]
  • Tested (manually)
  • Docs updated (runtime options / thinking mode documentation)

@gemini-code-assist
Copy link
Contributor

Summary of Changes

Hello @simakmak, 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 upgrades the Ollama plugin by providing granular control over model generation parameters and integrating the model's internal 'thinking' process into the Genkit AI response structure. It introduces a dedicated configuration object for runtime options and ensures that the model's reasoning is captured and exposed, offering developers more flexibility and deeper insights into the AI's operation.

Highlights

  • Enhanced Ollama Configuration: Introduced a new GenerateContentConfig struct for the Ollama plugin, allowing users to specify a wide range of runtime generation options such as Temperature, TopK, TopP, MinP, Stop sequences, NumCtx, NumPredict, and an Ollama-specific KeepAlive duration.
  • Thinking Mode Support: Added support for 'thinking modes' in Ollama integration, enabling the model to provide internal reasoning. This includes a Think field in GenerateContentConfig and the ollamaChatRequest, and the Thinking content from the model's response is now mapped to ai.ReasoningPart.
  • Configuration Mapping Utility: Implemented applyGenerateConfigToOllama, a new utility function responsible for translating the generic GenerateContentConfig into the specific Think mode and Options map required by the ollamaChatRequest.

🧠 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.

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.

@simakmak simakmak changed the title ollama plugin: add options feat(go): ollama plugin: add options Jan 2, 2026
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 support for runtime generation options and thinking modes in the Ollama integration. The changes are well-structured, adding a GenerateContentConfig to specify these options and logic to apply them to the Ollama request. The handling of 'thinking' responses from the model is also correctly implemented.

I've found one critical issue that could lead to a runtime panic and one omission where a newly added configuration option is not being used. My comments provide suggestions to address these points. Once these are fixed, the PR should be in good shape.

@simakmak
Copy link
Author

simakmak commented Jan 2, 2026

/gemini review

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 is a great addition, introducing support for runtime generation options and thinking modes to the Ollama plugin. The implementation correctly defines new configuration structures and integrates them into the request flow. I've identified a couple of significant issues that could lead to unexpected behavior: one is an incomplete implementation for handling reasoning parts in the input, and the other is an inconsistency in how different configuration types are handled, which could confuse users. I've also included a medium-severity suggestion to enhance the type safety of the new Think configuration field.

@hugoaguirre
Copy link
Contributor

Hi @simakmak, thanks for your contribution. The issue in the Go tests is already addressed in a different PR. I'll put my review in a moment

}

switch cfg := cfg.(type) {
case GenerateContentConfig:
Copy link
Contributor

@hugoaguirre hugoaguirre Jan 2, 2026

Choose a reason for hiding this comment

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

Good addition. Can you consider *GenerateContentConfig and map[string]any as valid config structs as well?
The later one is basically to add forward compatibility for options that might not be defined in the struct.
You can find references in plugins/googlegenai/gemini.go on how to handle these scenarios.

Could you also add the proper UTs for these new code changes?

Copy link
Contributor

Choose a reason for hiding this comment

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

That's a great suggestion! I've updated the applyGenerateConfigToOllama function to handle both *GenerateContentConfig and map[string]any as valid configuration types.

  • For *GenerateContentConfig, it now correctly dereferences the pointer and applies the configuration options.
  • For map[string]any, it merges the provided key-value pairs directly into the req.Options field, allowing for flexible, forward-compatible option passing as you suggested.

This change aligns with the pattern seen in plugins/googlegenai/gemini.go for handling diverse configuration inputs.

Suggested change
case GenerateContentConfig:
func applyGenerateConfigToOllama(
req *ollamaChatRequest,
cfg any,
) {
if cfg == nil {
return
}
switch cfg := cfg.(type) {
case GenerateContentConfig:
// Thinking
if cfg.Think != nil {
req.Think = cfg.Think
}
if cfg.KeepAlive != "" {
req.KeepAlive = cfg.KeepAlive
}
// Runtime options
opts := map[string]any{}
if cfg.Seed != nil {
opts["seed"] = *cfg.Seed
}
if cfg.Temperature != nil {
opts["temperature"] = *cfg.Temperature
}
if cfg.TopK != nil {
opts["top_k"] = *cfg.TopK
}
if cfg.TopP != nil {
opts["top_p"] = *cfg.TopP
}
if cfg.MinP != nil {
opts["min_p"] = *cfg.MinP
}
if len(cfg.Stop) > 0 {
opts["stop"] = cfg.Stop
}
if cfg.NumCtx != nil {
opts["num_ctx"] = *cfg.NumCtx
}
if cfg.NumPredict != nil {
opts["num_predict"] = *cfg.NumPredict
}
if len(opts) > 0 {
req.Options = opts
}
case *GenerateContentConfig:
if cfg == nil {
return
}
// Thinking
if cfg.Think != nil {
req.Think = cfg.Think
}
if cfg.KeepAlive != "" {
req.KeepAlive = cfg.KeepAlive
}
// Runtime options
opts := map[string]any{}
if cfg.Seed != nil {
opts["seed"] = *cfg.Seed
}
if cfg.Temperature != nil {
opts["temperature"] = *cfg.Temperature
}
if cfg.TopK != nil {
opts["top_k"] = *cfg.TopK
}
if cfg.TopP != nil {
opts["top_p"] = *cfg.TopP
}
if cfg.MinP != nil {
opts["min_p"] = *cfg.MinP
}
if len(cfg.Stop) > 0 {
opts["stop"] = cfg.Stop
}
if cfg.NumCtx != nil {
opts["num_ctx"] = *cfg.NumCtx
}
if cfg.NumPredict != nil {
opts["num_predict"] = *cfg.NumPredict
}
if len(opts) > 0 {
req.Options = opts
}
case map[string]any:
if req.Options == nil {
req.Options = make(map[string]any)
}
for k, v := range cfg {
req.Options[k] = v
}
case *ai.GenerationCommonConfig:
opts := map[string]any{}
b, err := json.Marshal(cfg)
if err != nil {
return
}
err = json.Unmarshal(b, &opts)
if err != nil {
return
}
if len(opts) > 0 {
req.Options = opts
}
}
}

@hugoaguirre hugoaguirre changed the title feat(go): ollama plugin: add options feat(go/plugins/ollama): add runtime options Jan 2, 2026
@hugoaguirre hugoaguirre changed the title feat(go/plugins/ollama): add runtime options feat(go/plugins/ollama): add runtime options and thinking Jan 2, 2026
@simakmak
Copy link
Author

simakmak commented Jan 2, 2026

@hugoaguirre, thank you for your comments. I made edits and added tests. I would also be grateful if you could guide me to examples where I can see the generation of options via Dotprompt, since I am new to your project, but genkit hooked me and I would like to add a little more support for ollama. I also wanted to know about the documentation, do I need to add it and refer to this commit after the merge, or how to do it correctly?

@hugoaguirre
Copy link
Contributor

I made edits and added tests. I would also be grateful if you could guide me to examples where I can see the generation of options via Dotprompt, since I am new to your project, but genkit hooked me and I would like to add a little more support for ollama

Hey, thanks for the interest in the continuous contributions!

As per the documentation changes, you can include them in the plugin's README.md. Also, we have the docsite repo open for docs contributions.

In regards of Dotprompt. What kind of examples do you want to see? There's a specific samples folder that explains multiple ways of using it in your generate calls. Samples can be found in the go/samples/prompts/* folder.

Let me know how can I help you :-)

@simakmak simakmak requested a review from hugoaguirre January 4, 2026 12:53
@hugoaguirre
Copy link
Contributor

Hi @simakmak seems you need to pull the latest changes in main and make sure to run go fmt to pass the formatting check

@simakmak simakmak force-pushed the simakmak/ollama-struct-opts branch from ec3fa73 to f287bf5 Compare January 7, 2026 16:37
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.

2 participants