Repo iniciado

This commit is contained in:
2026-03-03 23:19:23 +00:00
commit c126187c5a
32 changed files with 2719 additions and 0 deletions
+25
View File
@@ -0,0 +1,25 @@
package llm
import "strings"
// Route maps a model string to its provider. Pure function.
func Route(model string) ProviderID {
switch {
case strings.HasPrefix(model, "claude"):
return ProviderAnthropic
case strings.HasPrefix(model, "gpt"), strings.HasPrefix(model, "o1"), strings.HasPrefix(model, "o3"):
return ProviderOpenAI
case strings.HasPrefix(model, "ollama/"):
return ProviderOllama
default:
return ProviderOpenAI
}
}
// ModelName strips the provider prefix from a model string.
func ModelName(model string) string {
if after, ok := strings.CutPrefix(model, "ollama/"); ok {
return after
}
return model
}
+68
View File
@@ -0,0 +1,68 @@
// Package llm defines pure types for LLM provider communication.
// No side effects — only data and transformations.
package llm
import "context"
type Role string
const (
RoleSystem Role = "system"
RoleUser Role = "user"
RoleAssistant Role = "assistant"
RoleTool Role = "tool"
)
type ProviderID string
const (
ProviderAnthropic ProviderID = "anthropic"
ProviderOpenAI ProviderID = "openai"
ProviderOllama ProviderID = "ollama"
)
type Message struct {
Role Role
Content string
ToolCallID string
ToolCalls []ToolCall
}
type ToolCall struct {
ID string
Name string
Arguments string // JSON-encoded
}
type ToolSpec struct {
Name string
Description string
InputSchema map[string]any
}
type CompletionRequest struct {
Model string
Messages []Message
Tools []ToolSpec
MaxTokens int
Temperature float64
Stream bool
SystemPrompt string
}
type TokenUsage struct {
InputTokens int
OutputTokens int
TotalTokens int
}
type CompletionResponse struct {
Content string
ToolCalls []ToolCall
Usage TokenUsage
FinishReason string
}
// CompleteFunc is the single contract for LLM providers.
// Implementations live in shell/llm/.
type CompleteFunc func(ctx context.Context, req CompletionRequest) (CompletionResponse, error)