-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathtypes.go
More file actions
84 lines (70 loc) · 3.61 KB
/
types.go
File metadata and controls
84 lines (70 loc) · 3.61 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
package mockllm
import (
"github.com/anthropics/anthropic-sdk-go"
"github.com/openai/openai-go/v3"
"github.com/openai/openai-go/v3/responses"
)
// Very simple mock configuration - just maps requests to responses using official SDK types
// Config holds all the mock responses
type Config struct {
OpenAI []OpenAIMock `json:"openai,omitempty"`
OpenAIResponse []OpenAIResponseMock `json:"openai_response,omitempty"`
OpenAIEmbeddings []OpenAIEmbeddingMock `json:"openai_embeddings,omitempty"`
Anthropic []AnthropicMock `json:"anthropic,omitempty"`
// ListenAddr is the address to listen on. Defaults to 0.0.0.0:0 (any IP address and ephemeral port)
ListenAddr string `json:"listen_addr,omitempty"`
}
type MatchType string
const (
MatchTypeExact MatchType = "exact"
MatchTypeContains MatchType = "contains"
)
type HeaderMatch struct {
Name string `json:"name"` // Header name (case-insensitive per HTTP spec)
Value string `json:"value"` // Value to match against
MatchType MatchType `json:"match_type,omitempty"` // "exact" (default) or "contains"
}
type OpenAIRequestMatch struct {
MatchType MatchType `json:"match_type"`
Message openai.ChatCompletionMessageParamUnion `json:"message"`
Headers []HeaderMatch `json:"headers,omitempty"`
}
// OpenAIMock maps an OpenAI request to a response using official SDK types
type OpenAIMock struct {
Name string `json:"name"` // identifier for this mock
Match OpenAIRequestMatch `json:"match"` // Match type and value
Response openai.ChatCompletion `json:"response"` // OpenAI response to return (ChatCompletion or ChatCompletionChunk)
}
type OpenAIResponseRequestMatch struct {
MatchType MatchType `json:"match_type"`
Input responses.ResponseNewParamsInputUnion `json:"input"` // Input to match against (typically OfString)
Headers []HeaderMatch `json:"headers,omitempty"`
}
// OpenAIResponseMock maps an OpenAI Responses API request to a response using official SDK types
type OpenAIResponseMock struct {
Name string `json:"name"` // identifier for this mock
Match OpenAIResponseRequestMatch `json:"match"` // Match type and value
Response responses.Response `json:"response"` // OpenAI Responses API response to return
}
type AnthropicRequestMatch struct {
MatchType MatchType `json:"match_type"`
Message anthropic.MessageParam `json:"message"`
Headers []HeaderMatch `json:"headers,omitempty"`
}
// AnthropicMock maps an Anthropic request to a response using official SDK types
type AnthropicMock struct {
Name string `json:"name"` // identifier for this mock
Match AnthropicRequestMatch `json:"match"` // Match type and value
Response anthropic.Message `json:"response"` // Anthropic response to return (Message or streaming event)
}
type OpenAIEmbeddingRequestMatch struct {
MatchType MatchType `json:"match_type"`
Input openai.EmbeddingNewParamsInputUnion `json:"input"`
Headers []HeaderMatch `json:"headers,omitempty"`
}
// OpenAIEmbeddingMock maps an OpenAI embeddings request to a response using official SDK types
type OpenAIEmbeddingMock struct {
Name string `json:"name"` // identifier for this mock
Match OpenAIEmbeddingRequestMatch `json:"match"` // Match type and value
Response openai.CreateEmbeddingResponse `json:"response"` // OpenAI embeddings response to return
}