Changeset 0.10.0 (#56)
This commit is contained in:
@@ -3,10 +3,15 @@ package providers
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"errors"
|
||||
|
||||
"git.gobha.me/xcaliber/chat-switchboard/models"
|
||||
)
|
||||
|
||||
// ── Errors ─────────────────────────────────
|
||||
|
||||
var ErrNotSupported = errors.New("operation not supported by this provider")
|
||||
|
||||
// ── Provider Interface ──────────────────────
|
||||
|
||||
// Provider is the contract for LLM API adapters.
|
||||
@@ -23,6 +28,10 @@ type Provider interface {
|
||||
|
||||
// ListModels returns available models from this provider.
|
||||
ListModels(ctx context.Context, cfg ProviderConfig) ([]Model, error)
|
||||
|
||||
// Embed generates embeddings for the given input texts.
|
||||
// Returns ErrNotSupported if the provider has no embedding endpoint.
|
||||
Embed(ctx context.Context, cfg ProviderConfig, req EmbeddingRequest) (*EmbeddingResponse, error)
|
||||
}
|
||||
|
||||
// ── Configuration ───────────────────────────
|
||||
@@ -88,23 +97,44 @@ type CompletionRequest struct {
|
||||
|
||||
// CompletionResponse is the normalized non-streaming response.
|
||||
type CompletionResponse struct {
|
||||
Content string `json:"content"`
|
||||
Model string `json:"model"`
|
||||
FinishReason string `json:"finish_reason"`
|
||||
InputTokens int `json:"input_tokens"`
|
||||
OutputTokens int `json:"output_tokens"`
|
||||
ToolCalls []ToolCall `json:"tool_calls,omitempty"` // set when finish_reason is "tool_calls"
|
||||
Content string `json:"content"`
|
||||
Model string `json:"model"`
|
||||
FinishReason string `json:"finish_reason"`
|
||||
InputTokens int `json:"input_tokens"`
|
||||
OutputTokens int `json:"output_tokens"`
|
||||
CacheCreationTokens int `json:"cache_creation_tokens,omitempty"`
|
||||
CacheReadTokens int `json:"cache_read_tokens,omitempty"`
|
||||
ToolCalls []ToolCall `json:"tool_calls,omitempty"` // set when finish_reason is "tool_calls"
|
||||
}
|
||||
|
||||
// StreamEvent is a single chunk from a streaming response.
|
||||
type StreamEvent struct {
|
||||
Delta string `json:"delta,omitempty"`
|
||||
Reasoning string `json:"reasoning,omitempty"`
|
||||
Done bool `json:"done,omitempty"`
|
||||
FinishReason string `json:"finish_reason,omitempty"`
|
||||
ToolCalls []ToolCall `json:"tool_calls,omitempty"`
|
||||
Model string `json:"model,omitempty"`
|
||||
Error error `json:"-"`
|
||||
Delta string `json:"delta,omitempty"`
|
||||
Reasoning string `json:"reasoning,omitempty"`
|
||||
Done bool `json:"done,omitempty"`
|
||||
FinishReason string `json:"finish_reason,omitempty"`
|
||||
ToolCalls []ToolCall `json:"tool_calls,omitempty"`
|
||||
Model string `json:"model,omitempty"`
|
||||
Error error `json:"-"`
|
||||
InputTokens int `json:"input_tokens,omitempty"`
|
||||
OutputTokens int `json:"output_tokens,omitempty"`
|
||||
CacheCreationTokens int `json:"cache_creation_tokens,omitempty"`
|
||||
CacheReadTokens int `json:"cache_read_tokens,omitempty"`
|
||||
}
|
||||
|
||||
// ── Embedding Types ────────────────────────
|
||||
|
||||
// EmbeddingRequest is the normalized embedding request.
|
||||
type EmbeddingRequest struct {
|
||||
Model string `json:"model"`
|
||||
Input []string `json:"input"` // batch of texts to embed
|
||||
}
|
||||
|
||||
// EmbeddingResponse is the normalized embedding response.
|
||||
type EmbeddingResponse struct {
|
||||
Embeddings [][]float64 `json:"embeddings"`
|
||||
Model string `json:"model"`
|
||||
InputTokens int `json:"input_tokens"`
|
||||
}
|
||||
|
||||
// Model represents an available model from a provider, with capabilities.
|
||||
|
||||
Reference in New Issue
Block a user