This repository was archived by the owner on Apr 3, 2026. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtypes.go
More file actions
81 lines (64 loc) · 1.83 KB
/
types.go
File metadata and controls
81 lines (64 loc) · 1.83 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
package embedrock
import (
"context"
"fmt"
)
// --- Core interface ---
// Embedder generates embedding vectors from text.
// Implementations handle model-specific request/response formats.
type Embedder interface {
Embed(ctx context.Context, text string) ([]float64, error)
}
// --- OpenAI-compatible request types ---
// EmbeddingRequest is a single-string input request.
type EmbeddingRequest struct {
Input string `json:"input"`
Model string `json:"model"`
}
// EmbeddingRequestBatch is an array input request.
type EmbeddingRequestBatch struct {
Input []string `json:"input"`
Model string `json:"model"`
}
// --- OpenAI-compatible response types ---
// EmbeddingResponse is the top-level response envelope.
type EmbeddingResponse struct {
Object string `json:"object"`
Data []EmbeddingData `json:"data"`
Model string `json:"model"`
Usage Usage `json:"usage"`
}
// EmbeddingData is a single embedding result.
type EmbeddingData struct {
Object string `json:"object"`
Index int `json:"index"`
Embedding []float64 `json:"embedding"`
}
// Usage reports token consumption.
type Usage struct {
PromptTokens int `json:"prompt_tokens"`
TotalTokens int `json:"total_tokens"`
}
// --- API response types ---
// HealthResponse is returned by GET /.
type HealthResponse struct {
Status string `json:"status"`
Model string `json:"model,omitempty"`
}
// ErrorResponse wraps errors in OpenAI-compatible format.
type ErrorResponse struct {
Error ErrorDetail `json:"error"`
}
// ErrorDetail is the error payload.
type ErrorDetail struct {
Message string `json:"message"`
Type string `json:"type"`
}
// --- Errors ---
// EmbedError represents an embedding failure.
type EmbedError struct {
Message string
}
func (e *EmbedError) Error() string {
return fmt.Sprintf("embed error: %s", e.Message)
}