Skip to content

Commit 34fbacc

Browse files
chore: move ChatModel type to shared (#250)
1 parent eff15bb commit 34fbacc

16 files changed

+236
-110
lines changed

README.md

+2-1
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ import (
4949

5050
"github.com/openai/openai-go"
5151
"github.com/openai/openai-go/option"
52+
"github.com/openai/openai-go/shared"
5253
)
5354

5455
func main() {
@@ -541,7 +542,7 @@ chatCompletion, err := client.Chat.Completions.New(
541542
Role: openai.F(openai.ChatCompletionUserMessageParamRoleUser),
542543
Content: openai.F([]openai.ChatCompletionContentPartUnionParam{openai.ChatCompletionContentPartTextParam{Text: openai.F("text"), Type: openai.F(openai.ChatCompletionContentPartTextTypeText)}}),
543544
}}),
544-
Model: openai.F(openai.ChatModelO3Mini),
545+
Model: openai.F(shared.ChatModelO3Mini),
545546
},
546547
option.WithResponseInto(&response),
547548
)

aliases.go

+126
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,132 @@ import (
99

1010
type Error = apierror.Error
1111

12+
// This is an alias to an internal type.
13+
type ChatModel = shared.ChatModel
14+
15+
// This is an alias to an internal value.
16+
const ChatModelO3Mini = shared.ChatModelO3Mini
17+
18+
// This is an alias to an internal value.
19+
const ChatModelO3Mini2025_01_31 = shared.ChatModelO3Mini2025_01_31
20+
21+
// This is an alias to an internal value.
22+
const ChatModelO1 = shared.ChatModelO1
23+
24+
// This is an alias to an internal value.
25+
const ChatModelO1_2024_12_17 = shared.ChatModelO1_2024_12_17
26+
27+
// This is an alias to an internal value.
28+
const ChatModelO1Preview = shared.ChatModelO1Preview
29+
30+
// This is an alias to an internal value.
31+
const ChatModelO1Preview2024_09_12 = shared.ChatModelO1Preview2024_09_12
32+
33+
// This is an alias to an internal value.
34+
const ChatModelO1Mini = shared.ChatModelO1Mini
35+
36+
// This is an alias to an internal value.
37+
const ChatModelO1Mini2024_09_12 = shared.ChatModelO1Mini2024_09_12
38+
39+
// This is an alias to an internal value.
40+
const ChatModelGPT4_5Preview = shared.ChatModelGPT4_5Preview
41+
42+
// This is an alias to an internal value.
43+
const ChatModelGPT4_5Preview2025_02_27 = shared.ChatModelGPT4_5Preview2025_02_27
44+
45+
// This is an alias to an internal value.
46+
const ChatModelGPT4o = shared.ChatModelGPT4o
47+
48+
// This is an alias to an internal value.
49+
const ChatModelGPT4o2024_11_20 = shared.ChatModelGPT4o2024_11_20
50+
51+
// This is an alias to an internal value.
52+
const ChatModelGPT4o2024_08_06 = shared.ChatModelGPT4o2024_08_06
53+
54+
// This is an alias to an internal value.
55+
const ChatModelGPT4o2024_05_13 = shared.ChatModelGPT4o2024_05_13
56+
57+
// This is an alias to an internal value.
58+
const ChatModelGPT4oAudioPreview = shared.ChatModelGPT4oAudioPreview
59+
60+
// This is an alias to an internal value.
61+
const ChatModelGPT4oAudioPreview2024_10_01 = shared.ChatModelGPT4oAudioPreview2024_10_01
62+
63+
// This is an alias to an internal value.
64+
const ChatModelGPT4oAudioPreview2024_12_17 = shared.ChatModelGPT4oAudioPreview2024_12_17
65+
66+
// This is an alias to an internal value.
67+
const ChatModelGPT4oMiniAudioPreview = shared.ChatModelGPT4oMiniAudioPreview
68+
69+
// This is an alias to an internal value.
70+
const ChatModelGPT4oMiniAudioPreview2024_12_17 = shared.ChatModelGPT4oMiniAudioPreview2024_12_17
71+
72+
// This is an alias to an internal value.
73+
const ChatModelChatgpt4oLatest = shared.ChatModelChatgpt4oLatest
74+
75+
// This is an alias to an internal value.
76+
const ChatModelGPT4oMini = shared.ChatModelGPT4oMini
77+
78+
// This is an alias to an internal value.
79+
const ChatModelGPT4oMini2024_07_18 = shared.ChatModelGPT4oMini2024_07_18
80+
81+
// This is an alias to an internal value.
82+
const ChatModelGPT4Turbo = shared.ChatModelGPT4Turbo
83+
84+
// This is an alias to an internal value.
85+
const ChatModelGPT4Turbo2024_04_09 = shared.ChatModelGPT4Turbo2024_04_09
86+
87+
// This is an alias to an internal value.
88+
const ChatModelGPT4_0125Preview = shared.ChatModelGPT4_0125Preview
89+
90+
// This is an alias to an internal value.
91+
const ChatModelGPT4TurboPreview = shared.ChatModelGPT4TurboPreview
92+
93+
// This is an alias to an internal value.
94+
const ChatModelGPT4_1106Preview = shared.ChatModelGPT4_1106Preview
95+
96+
// This is an alias to an internal value.
97+
const ChatModelGPT4VisionPreview = shared.ChatModelGPT4VisionPreview
98+
99+
// This is an alias to an internal value.
100+
const ChatModelGPT4 = shared.ChatModelGPT4
101+
102+
// This is an alias to an internal value.
103+
const ChatModelGPT4_0314 = shared.ChatModelGPT4_0314
104+
105+
// This is an alias to an internal value.
106+
const ChatModelGPT4_0613 = shared.ChatModelGPT4_0613
107+
108+
// This is an alias to an internal value.
109+
const ChatModelGPT4_32k = shared.ChatModelGPT4_32k
110+
111+
// This is an alias to an internal value.
112+
const ChatModelGPT4_32k0314 = shared.ChatModelGPT4_32k0314
113+
114+
// This is an alias to an internal value.
115+
const ChatModelGPT4_32k0613 = shared.ChatModelGPT4_32k0613
116+
117+
// This is an alias to an internal value.
118+
const ChatModelGPT3_5Turbo = shared.ChatModelGPT3_5Turbo
119+
120+
// This is an alias to an internal value.
121+
const ChatModelGPT3_5Turbo16k = shared.ChatModelGPT3_5Turbo16k
122+
123+
// This is an alias to an internal value.
124+
const ChatModelGPT3_5Turbo0301 = shared.ChatModelGPT3_5Turbo0301
125+
126+
// This is an alias to an internal value.
127+
const ChatModelGPT3_5Turbo0613 = shared.ChatModelGPT3_5Turbo0613
128+
129+
// This is an alias to an internal value.
130+
const ChatModelGPT3_5Turbo1106 = shared.ChatModelGPT3_5Turbo1106
131+
132+
// This is an alias to an internal value.
133+
const ChatModelGPT3_5Turbo0125 = shared.ChatModelGPT3_5Turbo0125
134+
135+
// This is an alias to an internal value.
136+
const ChatModelGPT3_5Turbo16k0613 = shared.ChatModelGPT3_5Turbo16k0613
137+
12138
// This is an alias to an internal type.
13139
type ErrorObject = shared.ErrorObject
14140

api.md

+1-4
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
# Shared Params Types
22

3+
- <a href="https://pkg.go.dev/github.com/openai/openai-go/shared">shared</a>.<a href="https://pkg.go.dev/github.com/openai/openai-go/shared#ChatModel">ChatModel</a>
34
- <a href="https://pkg.go.dev/github.com/openai/openai-go/shared">shared</a>.<a href="https://pkg.go.dev/github.com/openai/openai-go/shared#FunctionDefinitionParam">FunctionDefinitionParam</a>
45
- <a href="https://pkg.go.dev/github.com/openai/openai-go/shared">shared</a>.<a href="https://pkg.go.dev/github.com/openai/openai-go/shared#FunctionParameters">FunctionParameters</a>
56
- <a href="https://pkg.go.dev/github.com/openai/openai-go/shared">shared</a>.<a href="https://pkg.go.dev/github.com/openai/openai-go/shared#MetadataParam">MetadataParam</a>
@@ -28,10 +29,6 @@ Methods:
2829

2930
# Chat
3031

31-
Params Types:
32-
33-
- <a href="https://pkg.go.dev/github.com/openai/openai-go">openai</a>.<a href="https://pkg.go.dev/github.com/openai/openai-go#ChatModel">ChatModel</a>
34-
3532
## Completions
3633

3734
Params Types:

betaassistant.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -2067,7 +2067,7 @@ type BetaAssistantNewParams struct {
20672067
// see all of your available models, or see our
20682068
// [Model overview](https://platform.openai.com/docs/models) for descriptions of
20692069
// them.
2070-
Model param.Field[ChatModel] `json:"model,required"`
2070+
Model param.Field[shared.ChatModel] `json:"model,required"`
20712071
// The description of the assistant. The maximum length is 512 characters.
20722072
Description param.Field[string] `json:"description"`
20732073
// The system instructions that the assistant uses. The maximum length is 256,000

betaassistant_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ func TestBetaAssistantNewWithOptionalParams(t *testing.T) {
2727
option.WithAPIKey("My API Key"),
2828
)
2929
_, err := client.Beta.Assistants.New(context.TODO(), openai.BetaAssistantNewParams{
30-
Model: openai.F(openai.ChatModelO3Mini),
30+
Model: openai.F(shared.ChatModelO3Mini),
3131
Description: openai.F("description"),
3232
Instructions: openai.F("instructions"),
3333
Metadata: openai.F(shared.MetadataParam{

betathread.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -739,7 +739,7 @@ type BetaThreadNewAndRunParams struct {
739739
// be used to execute this run. If a value is provided here, it will override the
740740
// model associated with the assistant. If not, the model associated with the
741741
// assistant will be used.
742-
Model param.Field[ChatModel] `json:"model"`
742+
Model param.Field[shared.ChatModel] `json:"model"`
743743
// Whether to enable
744744
// [parallel function calling](https://platform.openai.com/docs/guides/function-calling#configuring-parallel-function-calling)
745745
// during tool use.

betathread_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,7 @@ func TestBetaThreadNewAndRunWithOptionalParams(t *testing.T) {
172172
Metadata: openai.F(shared.MetadataParam{
173173
"foo": "string",
174174
}),
175-
Model: openai.F(openai.ChatModelO3Mini),
175+
Model: openai.F(shared.ChatModelO3Mini),
176176
ParallelToolCalls: openai.F(true),
177177
Temperature: openai.F(1.000000),
178178
Thread: openai.F(openai.BetaThreadNewAndRunParamsThread{

betathreadrun.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -731,7 +731,7 @@ type BetaThreadRunNewParams struct {
731731
// be used to execute this run. If a value is provided here, it will override the
732732
// model associated with the assistant. If not, the model associated with the
733733
// assistant will be used.
734-
Model param.Field[ChatModel] `json:"model"`
734+
Model param.Field[shared.ChatModel] `json:"model"`
735735
// Whether to enable
736736
// [parallel function calling](https://platform.openai.com/docs/guides/function-calling#configuring-parallel-function-calling)
737737
// during tool use.

betathreadrun_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ func TestBetaThreadRunNewWithOptionalParams(t *testing.T) {
5252
Metadata: openai.F(shared.MetadataParam{
5353
"foo": "string",
5454
}),
55-
Model: openai.F(openai.ChatModelO3Mini),
55+
Model: openai.F(shared.ChatModelO3Mini),
5656
ParallelToolCalls: openai.F(true),
5757
ReasoningEffort: openai.F(openai.BetaThreadRunNewParamsReasoningEffortLow),
5858
Temperature: openai.F(1.000000),

chat.go

-46
Original file line numberDiff line numberDiff line change
@@ -26,49 +26,3 @@ func NewChatService(opts ...option.RequestOption) (r *ChatService) {
2626
r.Completions = NewChatCompletionService(opts...)
2727
return
2828
}
29-
30-
type ChatModel = string
31-
32-
const (
33-
ChatModelO3Mini ChatModel = "o3-mini"
34-
ChatModelO3Mini2025_01_31 ChatModel = "o3-mini-2025-01-31"
35-
ChatModelO1 ChatModel = "o1"
36-
ChatModelO1_2024_12_17 ChatModel = "o1-2024-12-17"
37-
ChatModelO1Preview ChatModel = "o1-preview"
38-
ChatModelO1Preview2024_09_12 ChatModel = "o1-preview-2024-09-12"
39-
ChatModelO1Mini ChatModel = "o1-mini"
40-
ChatModelO1Mini2024_09_12 ChatModel = "o1-mini-2024-09-12"
41-
ChatModelGPT4_5Preview ChatModel = "gpt-4.5-preview"
42-
ChatModelGPT4_5Preview2025_02_27 ChatModel = "gpt-4.5-preview-2025-02-27"
43-
ChatModelGPT4o ChatModel = "gpt-4o"
44-
ChatModelGPT4o2024_11_20 ChatModel = "gpt-4o-2024-11-20"
45-
ChatModelGPT4o2024_08_06 ChatModel = "gpt-4o-2024-08-06"
46-
ChatModelGPT4o2024_05_13 ChatModel = "gpt-4o-2024-05-13"
47-
ChatModelGPT4oAudioPreview ChatModel = "gpt-4o-audio-preview"
48-
ChatModelGPT4oAudioPreview2024_10_01 ChatModel = "gpt-4o-audio-preview-2024-10-01"
49-
ChatModelGPT4oAudioPreview2024_12_17 ChatModel = "gpt-4o-audio-preview-2024-12-17"
50-
ChatModelGPT4oMiniAudioPreview ChatModel = "gpt-4o-mini-audio-preview"
51-
ChatModelGPT4oMiniAudioPreview2024_12_17 ChatModel = "gpt-4o-mini-audio-preview-2024-12-17"
52-
ChatModelChatgpt4oLatest ChatModel = "chatgpt-4o-latest"
53-
ChatModelGPT4oMini ChatModel = "gpt-4o-mini"
54-
ChatModelGPT4oMini2024_07_18 ChatModel = "gpt-4o-mini-2024-07-18"
55-
ChatModelGPT4Turbo ChatModel = "gpt-4-turbo"
56-
ChatModelGPT4Turbo2024_04_09 ChatModel = "gpt-4-turbo-2024-04-09"
57-
ChatModelGPT4_0125Preview ChatModel = "gpt-4-0125-preview"
58-
ChatModelGPT4TurboPreview ChatModel = "gpt-4-turbo-preview"
59-
ChatModelGPT4_1106Preview ChatModel = "gpt-4-1106-preview"
60-
ChatModelGPT4VisionPreview ChatModel = "gpt-4-vision-preview"
61-
ChatModelGPT4 ChatModel = "gpt-4"
62-
ChatModelGPT4_0314 ChatModel = "gpt-4-0314"
63-
ChatModelGPT4_0613 ChatModel = "gpt-4-0613"
64-
ChatModelGPT4_32k ChatModel = "gpt-4-32k"
65-
ChatModelGPT4_32k0314 ChatModel = "gpt-4-32k-0314"
66-
ChatModelGPT4_32k0613 ChatModel = "gpt-4-32k-0613"
67-
ChatModelGPT3_5Turbo ChatModel = "gpt-3.5-turbo"
68-
ChatModelGPT3_5Turbo16k ChatModel = "gpt-3.5-turbo-16k"
69-
ChatModelGPT3_5Turbo0301 ChatModel = "gpt-3.5-turbo-0301"
70-
ChatModelGPT3_5Turbo0613 ChatModel = "gpt-3.5-turbo-0613"
71-
ChatModelGPT3_5Turbo1106 ChatModel = "gpt-3.5-turbo-1106"
72-
ChatModelGPT3_5Turbo0125 ChatModel = "gpt-3.5-turbo-0125"
73-
ChatModelGPT3_5Turbo16k0613 ChatModel = "gpt-3.5-turbo-16k-0613"
74-
)

chatcompletion.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -1924,7 +1924,7 @@ type ChatCompletionNewParams struct {
19241924
// ID of the model to use. See the
19251925
// [model endpoint compatibility](https://platform.openai.com/docs/models#model-endpoint-compatibility)
19261926
// table for details on which models work with the Chat API.
1927-
Model param.Field[ChatModel] `json:"model,required"`
1927+
Model param.Field[shared.ChatModel] `json:"model,required"`
19281928
// Parameters for audio output. Required when audio output is requested with
19291929
// `modalities: ["audio"]`.
19301930
// [Learn more](https://platform.openai.com/docs/guides/audio).

chatcompletion_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ func TestChatCompletionNewWithOptionalParams(t *testing.T) {
3232
Role: openai.F(openai.ChatCompletionDeveloperMessageParamRoleDeveloper),
3333
Name: openai.F("name"),
3434
}}),
35-
Model: openai.F(openai.ChatModelO3Mini),
35+
Model: openai.F(shared.ChatModelO3Mini),
3636
Audio: openai.F(openai.ChatCompletionAudioParam{
3737
Format: openai.F(openai.ChatCompletionAudioParamFormatWAV),
3838
Voice: openai.F(openai.ChatCompletionAudioParamVoiceAlloy),

client_test.go

+11-10
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import (
1414
"github.com/openai/openai-go"
1515
"github.com/openai/openai-go/internal"
1616
"github.com/openai/openai-go/option"
17+
"github.com/openai/openai-go/shared"
1718
)
1819

1920
type closureTransport struct {
@@ -43,7 +44,7 @@ func TestUserAgentHeader(t *testing.T) {
4344
Role: openai.F(openai.ChatCompletionUserMessageParamRoleUser),
4445
Content: openai.F([]openai.ChatCompletionContentPartUnionParam{openai.ChatCompletionContentPartTextParam{Text: openai.F("text"), Type: openai.F(openai.ChatCompletionContentPartTextTypeText)}}),
4546
}}),
46-
Model: openai.F(openai.ChatModelO3Mini),
47+
Model: openai.F(shared.ChatModelO3Mini),
4748
})
4849
if userAgent != fmt.Sprintf("OpenAI/Go %s", internal.PackageVersion) {
4950
t.Errorf("Expected User-Agent to be correct, but got: %#v", userAgent)
@@ -72,7 +73,7 @@ func TestRetryAfter(t *testing.T) {
7273
Role: openai.F(openai.ChatCompletionUserMessageParamRoleUser),
7374
Content: openai.F([]openai.ChatCompletionContentPartUnionParam{openai.ChatCompletionContentPartTextParam{Text: openai.F("text"), Type: openai.F(openai.ChatCompletionContentPartTextTypeText)}}),
7475
}}),
75-
Model: openai.F(openai.ChatModelO3Mini),
76+
Model: openai.F(shared.ChatModelO3Mini),
7677
})
7778
if err == nil {
7879
t.Error("Expected there to be a cancel error")
@@ -112,7 +113,7 @@ func TestDeleteRetryCountHeader(t *testing.T) {
112113
Role: openai.F(openai.ChatCompletionUserMessageParamRoleUser),
113114
Content: openai.F([]openai.ChatCompletionContentPartUnionParam{openai.ChatCompletionContentPartTextParam{Text: openai.F("text"), Type: openai.F(openai.ChatCompletionContentPartTextTypeText)}}),
114115
}}),
115-
Model: openai.F(openai.ChatModelO3Mini),
116+
Model: openai.F(shared.ChatModelO3Mini),
116117
})
117118
if err == nil {
118119
t.Error("Expected there to be a cancel error")
@@ -147,7 +148,7 @@ func TestOverwriteRetryCountHeader(t *testing.T) {
147148
Role: openai.F(openai.ChatCompletionUserMessageParamRoleUser),
148149
Content: openai.F([]openai.ChatCompletionContentPartUnionParam{openai.ChatCompletionContentPartTextParam{Text: openai.F("text"), Type: openai.F(openai.ChatCompletionContentPartTextTypeText)}}),
149150
}}),
150-
Model: openai.F(openai.ChatModelO3Mini),
151+
Model: openai.F(shared.ChatModelO3Mini),
151152
})
152153
if err == nil {
153154
t.Error("Expected there to be a cancel error")
@@ -181,7 +182,7 @@ func TestRetryAfterMs(t *testing.T) {
181182
Role: openai.F(openai.ChatCompletionUserMessageParamRoleUser),
182183
Content: openai.F([]openai.ChatCompletionContentPartUnionParam{openai.ChatCompletionContentPartTextParam{Text: openai.F("text"), Type: openai.F(openai.ChatCompletionContentPartTextTypeText)}}),
183184
}}),
184-
Model: openai.F(openai.ChatModelO3Mini),
185+
Model: openai.F(shared.ChatModelO3Mini),
185186
})
186187
if err == nil {
187188
t.Error("Expected there to be a cancel error")
@@ -209,7 +210,7 @@ func TestContextCancel(t *testing.T) {
209210
Role: openai.F(openai.ChatCompletionUserMessageParamRoleUser),
210211
Content: openai.F([]openai.ChatCompletionContentPartUnionParam{openai.ChatCompletionContentPartTextParam{Text: openai.F("text"), Type: openai.F(openai.ChatCompletionContentPartTextTypeText)}}),
211212
}}),
212-
Model: openai.F(openai.ChatModelO3Mini),
213+
Model: openai.F(shared.ChatModelO3Mini),
213214
})
214215
if err == nil {
215216
t.Error("Expected there to be a cancel error")
@@ -234,7 +235,7 @@ func TestContextCancelDelay(t *testing.T) {
234235
Role: openai.F(openai.ChatCompletionUserMessageParamRoleUser),
235236
Content: openai.F([]openai.ChatCompletionContentPartUnionParam{openai.ChatCompletionContentPartTextParam{Text: openai.F("text"), Type: openai.F(openai.ChatCompletionContentPartTextTypeText)}}),
236237
}}),
237-
Model: openai.F(openai.ChatModelO3Mini),
238+
Model: openai.F(shared.ChatModelO3Mini),
238239
})
239240
if err == nil {
240241
t.Error("expected there to be a cancel error")
@@ -265,7 +266,7 @@ func TestContextDeadline(t *testing.T) {
265266
Role: openai.F(openai.ChatCompletionUserMessageParamRoleUser),
266267
Content: openai.F([]openai.ChatCompletionContentPartUnionParam{openai.ChatCompletionContentPartTextParam{Text: openai.F("text"), Type: openai.F(openai.ChatCompletionContentPartTextTypeText)}}),
267268
}}),
268-
Model: openai.F(openai.ChatModelO3Mini),
269+
Model: openai.F(shared.ChatModelO3Mini),
269270
})
270271
if err == nil {
271272
t.Error("expected there to be a deadline error")
@@ -315,7 +316,7 @@ func TestContextDeadlineStreaming(t *testing.T) {
315316
Content: openai.F([]openai.ChatCompletionContentPartTextParam{{Text: openai.F("text"), Type: openai.F(openai.ChatCompletionContentPartTextTypeText)}}),
316317
Role: openai.F(openai.ChatCompletionDeveloperMessageParamRoleDeveloper),
317318
}}),
318-
Model: openai.F(openai.ChatModelO3Mini),
319+
Model: openai.F(shared.ChatModelO3Mini),
319320
})
320321
for stream.Next() {
321322
_ = stream.Current()
@@ -367,7 +368,7 @@ func TestContextDeadlineStreamingWithRequestTimeout(t *testing.T) {
367368
Content: openai.F([]openai.ChatCompletionContentPartTextParam{{Text: openai.F("text"), Type: openai.F(openai.ChatCompletionContentPartTextTypeText)}}),
368369
Role: openai.F(openai.ChatCompletionDeveloperMessageParamRoleDeveloper),
369370
}}),
370-
Model: openai.F(openai.ChatModelO3Mini),
371+
Model: openai.F(shared.ChatModelO3Mini),
371372
},
372373
option.WithRequestTimeout((100 * time.Millisecond)),
373374
)

0 commit comments

Comments
 (0)