-
Notifications
You must be signed in to change notification settings - Fork 630
feat(go/plugins/ollama): add runtime options and thinking #4028
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
Summary of ChangesHello @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
🧠 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 AssistThe 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
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 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
|
There was a problem hiding this 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.
|
/gemini review |
There was a problem hiding this 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.
|
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 |
go/plugins/ollama/ollama.go
Outdated
| } | ||
|
|
||
| switch cfg := cfg.(type) { | ||
| case GenerateContentConfig: |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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 thereq.Optionsfield, 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.
| 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, 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? |
Hey, thanks for the interest in the continuous contributions! As per the documentation changes, you can include them in the plugin's 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 Let me know how can I help you :-) |
|
Hi @simakmak seems you need to pull the latest changes in main and make sure to run |
ec3fa73 to
f287bf5
Compare
Description
Add support for runtime generation options and thinking modes in Ollama integration.
Introduces
GenerateContentConfigwith:Think(Ollama:true/false; GPT-OSS:"low" | "medium" | "high")Temperature,TopK,TopP,MinP,Stop,NumCtx,NumPredictKeepAliveAdds
applyGenerateConfigToOllamato map config intoollamaChatRequest(Think+Options)Ensures
Thinkingcontent from model is mapped intoai.ReasoningPartExample usage:
Checklist