1
1
package goai
2
2
3
+ // ChatCompletionRequest represents the request structure for OpenAI's chat completion API.
4
+ type ChatCompletionRequest struct {
5
+ Model string `json:"model"`
6
+ Messages []Message `json:"messages"`
7
+ MaxTokens * int `json:"max_tokens,omitempty"`
8
+ Temperature * float64 `json:"temperature,omitempty"`
9
+ TopP * float64 `json:"top_p,omitempty"`
10
+ N * int `json:"n,omitempty"`
11
+ Stream bool `json:"stream"`
12
+ PresencePenalty * float64 `json:"presence_penalty,omitempty"`
13
+ FrequencyPenalty * float64 `json:"frequency_penalty,omitempty"`
14
+ Stop []string `json:"stop,omitempty"`
15
+ User string `json:"user,omitempty"`
16
+ }
17
+
18
+ // ChatCompletionResponse represents the response structure from OpenAI's chat completion API.
19
+ type ChatCompletionResponse struct {
20
+ ID string `json:"id"`
21
+ Object string `json:"object"`
22
+ Created int `json:"created"`
23
+ Model string `json:"model"`
24
+ SystemFingerprint string `json:"system_fingerprint"`
25
+ Choices []struct {
26
+ Index int `json:"index"`
27
+ Message struct {
28
+ Role string `json:"role"`
29
+ Content string `json:"content"`
30
+ } `json:"message"`
31
+ Logprobs interface {} `json:"logprobs"`
32
+ FinishReason string `json:"finish_reason"`
33
+ } `json:"choices"`
34
+ Usage struct {
35
+ PromptTokens int `json:"prompt_tokens"`
36
+ CompletionTokens int `json:"completion_tokens"`
37
+ TotalTokens int `json:"total_tokens"`
38
+ CompletionTokensDetails struct {
39
+ ReasoningTokens int `json:"reasoning_tokens"`
40
+ AcceptedPredictionTokens int `json:"accepted_prediction_tokens"`
41
+ RejectedPredictionTokens int `json:"rejected_prediction_tokens"`
42
+ } `json:"completion_tokens_details"`
43
+ } `json:"usage"`
44
+ }
45
+
46
+ // Message represents a single message in the conversation history.
47
+ type Message struct {
48
+ Role string `json:"role"` // "system", "assistant", or "user"
49
+ Content string `json:"content"` // The text content of the message
50
+ }
51
+
52
+ // ImageRequest represents the request structure for OpenAI's image generation API.
3
53
type ImageRequest struct {
4
54
Prompt string `json:"prompt"`
5
55
N int `json:"n"`
@@ -9,23 +59,26 @@ type ImageRequest struct {
9
59
Model string `json:"model"`
10
60
}
11
61
62
+ // ImageEditRequest represents the request structure for editing images using OpenAI's API.
12
63
type ImageEditRequest struct {
13
- Prompt string `json:"prompt"`
14
- N int `json:"n"`
15
- Size string `json:"size"`
16
- ResponseFormat string `json:"response_format"`
17
- User string `json:"user"`
18
- Image string `json:"image"`
19
- Mask string `json:"mask"`
64
+ Prompt string `json:"prompt"`
65
+ N int `json:"n"`
66
+ Size string `json:"size"`
67
+ ResponseFormat string `json:"response_format"`
68
+ User string `json:"user"`
69
+ Image * string `json:"image,omitempty "`
70
+ Mask * string `json:"mask,omitempty "`
20
71
}
21
72
73
+ // ImageResponse represents the response structure for OpenAI's image generation/editing APIs.
22
74
type ImageResponse struct {
23
75
Created int64 `json:"created"`
24
76
Data []struct {
25
77
URL string `json:"url"`
26
78
} `json:"data"`
27
79
}
28
80
81
+ // ErrorResponse represents the structure of an error response from OpenAI's API.
29
82
type ErrorResponse struct {
30
83
Error struct {
31
84
Message string `json:"message"`
@@ -35,43 +88,44 @@ type ErrorResponse struct {
35
88
} `json:"error"`
36
89
}
37
90
38
- type ChatCompletionResponse struct {
39
- ID string `json:"id"`
40
- Object string `json:"object"`
41
- Created int `json:"created"`
42
- Choices []Choice `json:"choices"`
43
- Usage map [string ]int `json:"usage"`
44
- }
45
-
46
- type Choice struct {
47
- Index int `json:"index"`
48
- Message Message `json:"message"`
49
- FinishReason string `json:"finish_reason"`
50
- }
51
-
52
- type Message struct {
53
- Role string `json:"role"`
54
- Content string `json:"content"`
55
- }
56
-
57
- type ChatCompletionRequest struct {
58
- Model string `json:"model"`
59
- Messages []Message `json:"messages"`
60
- MaxTokens int `json:"max_tokens"`
61
- Temperature float64 `json:"temperature"`
62
- TopP float64 `json:"top_p"`
63
- N int `json:"n"`
64
- Stream bool `json:"stream"`
65
- PresencePenalty float64 `json:"presence_penalty"`
66
- FrequencyPenalty float64 `json:"frequency_penalty"`
67
- Stop []string `json:"stop"`
68
- User string `json:"user"`
69
- }
70
-
91
+ // TTSRequest represents the request structure for OpenAI's text-to-speech API.
71
92
type TTSRequest struct {
72
93
Model string `json:"model"`
73
94
Input string `json:"input"`
74
95
Voice string `json:"voice"`
75
96
ResponseFormat string `json:"response_format"`
76
97
Speed float64 `json:"speed"`
77
98
}
99
+
100
+ // CompletionRequest represents a request for text completions (non-chat).
101
+ type CompletionRequest struct {
102
+ Model string `json:"model"`
103
+ Prompt string `json:"prompt"`
104
+ MaxTokens * int `json:"max_tokens,omitempty"`
105
+ Temperature * float64 `json:"temperature,omitempty"`
106
+ TopP * float64 `json:"top_p,omitempty"`
107
+ N * int `json:"n,omitempty"`
108
+ Stop []string `json:"stop,omitempty"`
109
+ PresencePenalty * float64 `json:"presence_penalty,omitempty"`
110
+ FrequencyPenalty * float64 `json:"frequency_penalty,omitempty"`
111
+ User string `json:"user,omitempty"`
112
+ }
113
+
114
+ // CompletionResponse represents the response structure for text completions (non-chat).
115
+ type CompletionResponse struct {
116
+ ID string `json:"id"`
117
+ Object string `json:"object"`
118
+ Created int `json:"created"`
119
+ Model string `json:"model"`
120
+ Choices []struct {
121
+ Text string `json:"text"`
122
+ Index int `json:"index"`
123
+ Logprobs interface {} `json:"logprobs"`
124
+ FinishReason string `json:"finish_reason"`
125
+ } `json:"choices"`
126
+ Usage struct {
127
+ PromptTokens int `json:"prompt_tokens"`
128
+ CompletionTokens int `json:"completion_tokens"`
129
+ TotalTokens int `json:"total_tokens"`
130
+ } `json:"usage"`
131
+ }
0 commit comments