46 lines
1.4 KiB
Go
46 lines
1.4 KiB
Go
package ai
|
|
|
|
import (
|
|
"context"
|
|
"encoding/json"
|
|
"errors"
|
|
"fmt"
|
|
)
|
|
|
|
// GenOptions permet de contrôler le comportement de génération par appel.
|
|
type GenOptions struct {
|
|
JSONSchema json.RawMessage // native constrained output; scoring only
|
|
RequireComplete bool // reject incomplete provider responses for structured scoring
|
|
MaxOutputTokens int // explicit synthesis output reserve
|
|
JSONMode bool // request structured JSON output when supported
|
|
Think bool // active le mode raisonnement (Qwen3 /think)
|
|
NumCtx int // taille du contexte KV (0 = valeur par défaut du provider)
|
|
}
|
|
|
|
type Provider interface {
|
|
Name() string
|
|
Summarize(ctx context.Context, prompt string, opts GenOptions) (string, error)
|
|
ListModels(ctx context.Context) ([]string, error)
|
|
}
|
|
|
|
func NewProvider(name, apiKey, model, endpoint string) (Provider, error) {
|
|
switch name {
|
|
case "openai":
|
|
return newOpenAI(apiKey, model), nil
|
|
case "anthropic":
|
|
return newAnthropic(apiKey, model), nil
|
|
case "gemini":
|
|
return newGemini(apiKey, model), nil
|
|
case "ollama":
|
|
return newOllama(endpoint, model), nil
|
|
case "claudecode":
|
|
return newClaudeCode(model), nil
|
|
default:
|
|
return nil, fmt.Errorf("unknown provider: %s", name)
|
|
}
|
|
}
|
|
|
|
var errGenerationIncomplete = errors.New("provider response incomplete")
|
|
|
|
var errStructuredOutputUnsupported = errors.New("ranking structured output unsupported")
|