-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathprovider.go
More file actions
90 lines (77 loc) · 2.46 KB
/
Copy pathprovider.go
File metadata and controls
90 lines (77 loc) · 2.46 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
package connector
import (
"context"
"fmt"
)
// LLMProvider implements a specific AI provider's chat completion API.
type LLMProvider interface {
ChatCompletion(ctx context.Context, req *ChatRequest) (*ChatResponse, error)
}
// EmbeddingProvider implements a specific provider's text-embeddings API.
type EmbeddingProvider interface {
Embeddings(ctx context.Context, req *EmbeddingRequest) (*EmbeddingResponse, error)
}
// EmbeddingRequest is the provider-agnostic embeddings request format.
type EmbeddingRequest struct {
Model string
Inputs []string
Dimensions int // 0 = provider default
InputType string // provider-specific hint (Cohere: search_document/search_query/...); "" = provider default
Credential map[string]string
}
// EmbeddingResponse is the provider-agnostic embeddings response format.
// Embeddings are returned in the same order as EmbeddingRequest.Inputs.
type EmbeddingResponse struct {
Embeddings [][]float64
Model string
Usage ChatUsage // PromptTokens / TotalTokens are meaningful for embeddings
}
// ChatRequest is the provider-agnostic request format.
type ChatRequest struct {
Model string
Messages []ChatMessage
Tools []ChatTool
OutputSchema map[string]any
MaxTokens int
Credential map[string]string
}
// ChatMessage represents a single message in the conversation.
// Valid Role values: "system", "user", "assistant", "tool".
// For "tool" messages (tool results), set ToolCallID to match the original call.
// Note: "tool" role maps to ConversationRoleUser in Bedrock (tool results are user messages).
type ChatMessage struct {
Role string
Content string
ToolCalls []ToolCall // reuses existing ToolCall type from ai.go
ToolCallID string
}
// ChatTool defines a tool the model can invoke.
type ChatTool struct {
Name string
Description string
InputSchema map[string]any
}
// ChatResponse is the provider-agnostic response format.
type ChatResponse struct {
Text string
ToolCalls []ToolCall
FinishReason string // "stop" or "tool_calls"
Usage ChatUsage
Model string
}
// ChatUsage tracks token consumption.
type ChatUsage struct {
PromptTokens int
CompletionTokens int
TotalTokens int
}
// RetryableError wraps an error to indicate the caller should retry.
type RetryableError struct {
Err error
}
func (e *RetryableError) Error() string {
return fmt.Sprintf("retryable: %v", e.Err)
}
func (e *RetryableError) Unwrap() error {
return e.Err
}