feat: add ollama provider#156
Conversation
There was a problem hiding this comment.
Pull Request Overview
This PR adds Ollama provider support to the Blades framework, enabling integration with local and remote Ollama models for chat completions, streaming, tool calling, and vision capabilities.
Key changes:
- New Ollama model provider implementation with support for chat completions, streaming, tool calling, and structured outputs
- Example demonstrating basic usage and streaming with Ollama models
- Comprehensive documentation covering features, configuration options, and usage examples
Reviewed Changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
| examples/model-ollama/main.go | Example showing basic chat and streaming with Ollama provider |
| examples/model-ollama/go.mod | Module definition for the example with local blades replacement |
| contrib/ollama/params.go | Helper function to convert messages to prompt strings |
| contrib/ollama/chat.go | Core Ollama provider implementation with chat, streaming, and tool support |
| contrib/ollama/README.md | Comprehensive documentation for the Ollama provider |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| func base64ToImageData(dataURI string) ([]byte, error) { | ||
| // Remove data URL prefix if present | ||
| if len(dataURI) > 5 && dataURI[:5] == "data:" { | ||
| commaIdx := -1 | ||
| for i, c := range dataURI { | ||
| if c == ',' { | ||
| commaIdx = i | ||
| break | ||
| } | ||
| } | ||
| if commaIdx > 0 { | ||
| dataURI = dataURI[commaIdx+1:] | ||
| } | ||
| } | ||
|
|
||
| // Decode base64 | ||
| return json.Marshal(dataURI) | ||
| } |
There was a problem hiding this comment.
The function base64ToImageData is supposed to decode base64 data and return raw bytes, but line 402 calls json.Marshal(dataURI) which returns a JSON-encoded string instead of decoded bytes. This should use base64.StdEncoding.DecodeString(dataURI) from the encoding/base64 package to properly decode the base64 data.
| TopP float64 // Nucleus sampling parameter (0-1) | ||
| StopSequences []string // Sequences that stop generation | ||
| KeepAlive string // How long to keep model loaded (e.g., "5m", "1h") | ||
| Think *string // Enable thinking mode ("true", "false", "high", "medium", "low") |
There was a problem hiding this comment.
The documentation shows Think as type *string, but in the actual Config struct at chat.go line 28, it is defined as string (not a pointer). The documentation should be updated to Think string to match the implementation.
| Think *string // Enable thinking mode ("true", "false", "high", "medium", "low") | |
| Think string // Enable thinking mode ("true", "false", "high", "medium", "low") |
| ```go | ||
| think := "high" // "true", "false", "high", "medium", "low" | ||
| model := ollama.NewModel("llama3.2", ollama.Config{ | ||
| Think: &think, |
There was a problem hiding this comment.
The example code uses Think: &think (taking the address of the variable), but the Config.Think field is defined as string (not *string) in chat.go line 28. This should be Think: think or Think: \"high\" to match the actual field type.
| Think: &think, | |
| Think: think, |
|
|
||
| baseURLParsed, err := url.Parse(baseURL) | ||
| if err != nil { | ||
| log.Fatalf("Invalid Ollama base URL: %v", err) |
No description provided.