mirror of
https://github.com/ollama/ollama.git
synced 2025-11-11 05:07:57 +01:00
* working (other than tool call is the incorrect order) for tool calls and tools * Tests work, other than image tags (tests do not go through server) and tools (not in the correct order, but contents are the same) * testing for qwen3vl parser - toolparser is working * made changes to JSON tool parser, wraps the TollCallFunction with a TollCall object * Working parser for thinking models - assumes state of thinking, emits unambiguous content in thinking, does not call tool call in thinking * changed the parser to start with collecting content * thinking prefill * add hasThinkingSupport parameter to parser * qwen3-vl -> qwen3-vl-instruct for renderer/parser * Add hasThinkingSupport=false to QwenVLParser --------- Co-authored-by: Devon Rifkin <drifkin@drifkin.net>
53 lines
1.5 KiB
Go
53 lines
1.5 KiB
Go
package parsers
|
|
|
|
import (
|
|
"github.com/ollama/ollama/api"
|
|
"github.com/ollama/ollama/harmony"
|
|
)
|
|
|
|
type Parser interface {
|
|
// Init initializes the parser with tools and optional last message for chat prefill
|
|
// Returns processed tools if the parser needs to modify them (e.g., harmony renames them)
|
|
Init(tools []api.Tool, lastMessage *api.Message) []api.Tool
|
|
// Add processes streamed content and returns parsed content, thinking, and tool calls
|
|
// The done flag indicates if this is the last chunk (used for draining accumulators)
|
|
Add(s string, done bool) (content string, thinking string, calls []api.ToolCall, err error)
|
|
HasToolSupport() bool
|
|
HasThinkingSupport() bool
|
|
}
|
|
|
|
func ParserForName(name string) Parser {
|
|
switch name {
|
|
case "qwen3-coder":
|
|
parser := &Qwen3CoderParser{}
|
|
return parser
|
|
case "qwen3-vl-instruct":
|
|
parser := &Qwen3VLParser{hasThinkingSupport: false}
|
|
return parser
|
|
case "passthrough":
|
|
return &PassthroughParser{}
|
|
case "harmony":
|
|
return harmony.NewHarmonyMessageHandler()
|
|
default:
|
|
return nil
|
|
}
|
|
}
|
|
|
|
type PassthroughParser struct{}
|
|
|
|
func (p *PassthroughParser) Init(tools []api.Tool, lastMessage *api.Message) []api.Tool {
|
|
return tools // passthrough doesn't modify tools
|
|
}
|
|
|
|
func (p *PassthroughParser) Add(s string, done bool) (content string, thinking string, calls []api.ToolCall, err error) {
|
|
return s, "", nil, nil
|
|
}
|
|
|
|
func (p *PassthroughParser) HasToolSupport() bool {
|
|
return false
|
|
}
|
|
|
|
func (p *PassthroughParser) HasThinkingSupport() bool {
|
|
return false
|
|
}
|