Skip to content

feat: add ollama provider#156

Open
shenqidebaozi wants to merge 1 commit into
mainfrom
provider/ollama
Open

feat: add ollama provider#156
shenqidebaozi wants to merge 1 commit into
mainfrom
provider/ollama

Conversation

@shenqidebaozi

Copy link
Copy Markdown
Member

No description provided.

Copilot AI review requested due to automatic review settings November 18, 2025 13:58

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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.

Comment thread contrib/ollama/chat.go
Comment on lines +386 to +403
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)
}

Copilot AI Nov 18, 2025

Copy link

Choose a reason for hiding this comment

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

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.

Copilot uses AI. Check for mistakes.
Comment thread contrib/ollama/README.md
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")

Copilot AI Nov 18, 2025

Copy link

Choose a reason for hiding this comment

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

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.

Suggested change
Think *string // Enable thinking mode ("true", "false", "high", "medium", "low")
Think string // Enable thinking mode ("true", "false", "high", "medium", "low")

Copilot uses AI. Check for mistakes.
Comment thread contrib/ollama/README.md
```go
think := "high" // "true", "false", "high", "medium", "low"
model := ollama.NewModel("llama3.2", ollama.Config{
Think: &think,

Copilot AI Nov 18, 2025

Copy link

Choose a reason for hiding this comment

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

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.

Suggested change
Think: &think,
Think: think,

Copilot uses AI. Check for mistakes.
Comment thread contrib/ollama/chat.go

baseURLParsed, err := url.Parse(baseURL)
if err != nil {
log.Fatalf("Invalid Ollama base URL: %v", err)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

return nil, err

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.

3 participants