-
Notifications
You must be signed in to change notification settings - Fork 0
/
json.go
98 lines (90 loc) · 3.55 KB
/
json.go
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
91
92
93
94
95
96
97
98
package goai
// ChatCompletionRequest represents the request structure for OpenAI's chat completion API.
type ChatCompletionRequest struct {
Model string `json:"model"`
Messages []Message `json:"messages"`
MaxTokens *int `json:"max_tokens,omitempty"`
Temperature *float64 `json:"temperature,omitempty"`
TopP *float64 `json:"top_p,omitempty"`
N *int `json:"n,omitempty"`
Stream bool `json:"stream"`
PresencePenalty *float64 `json:"presence_penalty,omitempty"`
FrequencyPenalty *float64 `json:"frequency_penalty,omitempty"`
Stop []string `json:"stop,omitempty"`
User string `json:"user,omitempty"`
}
// ChatCompletionResponse represents the response structure from OpenAI's chat completion API.
type ChatCompletionResponse struct {
ID string `json:"id"`
Object string `json:"object"`
Created int `json:"created"`
Model string `json:"model"`
SystemFingerprint string `json:"system_fingerprint"`
Choices []struct {
Index int `json:"index"`
Message struct {
Role string `json:"role"`
Content string `json:"content"`
} `json:"message"`
Logprobs interface{} `json:"logprobs"`
FinishReason string `json:"finish_reason"`
} `json:"choices"`
Usage struct {
PromptTokens int `json:"prompt_tokens"`
CompletionTokens int `json:"completion_tokens"`
TotalTokens int `json:"total_tokens"`
CompletionTokensDetails struct {
ReasoningTokens int `json:"reasoning_tokens"`
AcceptedPredictionTokens int `json:"accepted_prediction_tokens"`
RejectedPredictionTokens int `json:"rejected_prediction_tokens"`
} `json:"completion_tokens_details"`
} `json:"usage"`
}
// Message represents a single message in the conversation history.
type Message struct {
Role string `json:"role"` // "system", "assistant", or "user"
Content string `json:"content"` // The text content of the message
}
// ImageRequest represents the request structure for OpenAI's image generation API.
type ImageRequest struct {
Prompt string `json:"prompt"`
N int `json:"n"`
Size string `json:"size"`
ResponseFormat string `json:"response_format"`
User string `json:"user"`
Model string `json:"model"`
}
// ImageEditRequest represents the request structure for editing images using OpenAI's API.
type ImageEditRequest struct {
Prompt string `json:"prompt"`
N int `json:"n"`
Size string `json:"size"`
ResponseFormat string `json:"response_format"`
User string `json:"user"`
Image *string `json:"image,omitempty"`
Mask *string `json:"mask,omitempty"`
}
// ImageResponse represents the response structure for OpenAI's image generation/editing APIs.
type ImageResponse struct {
Created int64 `json:"created"`
Data []struct {
URL string `json:"url"`
} `json:"data"`
}
// ErrorResponse represents the structure of an error response from OpenAI's API.
type ErrorResponse struct {
Error struct {
Message string `json:"message"`
Type string `json:"type"`
Param string `json:"param"`
Code string `json:"code"`
} `json:"error"`
}
// TTSRequest represents the request structure for OpenAI's text-to-speech API.
type TTSRequest struct {
Model string `json:"model"`
Input string `json:"input"`
Voice string `json:"voice"`
ResponseFormat string `json:"response_format"`
Speed float64 `json:"speed"`
}