- Added global uses configuration to the assistant, allowing for centralized management of vision, audio, search, and fetch settings. - Updated the Assistant struct and related methods to support the new Uses configuration, improving flexibility in assistant operations. - Refactored the Stream method to utilize the new CompletionResponse type, enhancing response handling. - Introduced new methods for building requests and managing capabilities, streamlining the assistant's interaction with various connectors.
56 lines
1.9 KiB
Go
56 lines
1.9 KiB
Go
package providers
|
|
|
|
import (
|
|
"fmt"
|
|
|
|
"github.com/yaoapp/gou/connector"
|
|
"github.com/yaoapp/yao/agent/context"
|
|
"github.com/yaoapp/yao/agent/llm/providers/legacy"
|
|
"github.com/yaoapp/yao/agent/llm/providers/openai"
|
|
"github.com/yaoapp/yao/agent/llm/providers/reasoning"
|
|
)
|
|
|
|
// LLM interface (copied to avoid import cycle)
|
|
type LLM interface {
|
|
Stream(ctx *context.Context, messages []context.Message, options *context.CompletionOptions, handler context.StreamFunc) (*context.CompletionResponse, error)
|
|
Post(ctx *context.Context, messages []context.Message, options *context.CompletionOptions) (*context.CompletionResponse, error)
|
|
}
|
|
|
|
// SelectProvider select the appropriate provider based on connector and capabilities
|
|
func SelectProvider(conn connector.Connector, options *context.CompletionOptions) (LLM, error) {
|
|
if options == nil || options.Capabilities == nil {
|
|
return nil, fmt.Errorf("options and capabilities are required")
|
|
}
|
|
|
|
capabilities := options.Capabilities
|
|
|
|
// Priority 1: Reasoning models (special response format)
|
|
if capabilities.Reasoning != nil && *capabilities.Reasoning {
|
|
return reasoning.New(conn, capabilities), nil
|
|
}
|
|
|
|
// Priority 2: Check if model supports native tool calls
|
|
if capabilities.ToolCalls != nil && *capabilities.ToolCalls {
|
|
// Use OpenAI-compatible provider (supports tools, vision, streaming)
|
|
return openai.New(conn, capabilities), nil
|
|
}
|
|
|
|
// Priority 3: Legacy models (no native tool support)
|
|
// Will use prompt engineering for tool calls
|
|
return legacy.New(conn, capabilities), nil
|
|
}
|
|
|
|
// DetectProvider detect provider type from connector
|
|
func DetectProvider(conn connector.Connector) string {
|
|
// TODO: Implement provider detection
|
|
// - Check connector type (Is(connector.OPENAI))
|
|
// - Check connector settings
|
|
// - Determine provider type (openai, claude, deepseek, etc.)
|
|
|
|
if conn.Is(connector.OPENAI) {
|
|
return "openai"
|
|
}
|
|
|
|
// Default to OpenAI-compatible
|
|
return "openai"
|
|
}
|