Skip to content

Commit 4b90869

Browse files
feat: extract out ImageModel, AudioModel, SpeechModel (#3)
1 parent 103d454 commit 4b90869

18 files changed

+95
-226
lines changed

api.md

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,10 @@ Methods:
8787

8888
# Images
8989

90+
Params Types:
91+
92+
- <a href="https://pkg.go.dev/github.com/openai/openai-go">openai</a>.<a href="https://pkg.go.dev/github.com/openai/openai-go#ImageModel">ImageModel</a>
93+
9094
Response Types:
9195

9296
- <a href="https://pkg.go.dev/github.com/openai/openai-go">openai</a>.<a href="https://pkg.go.dev/github.com/openai/openai-go#Image">Image</a>
@@ -100,6 +104,10 @@ Methods:
100104

101105
# Audio
102106

107+
Params Types:
108+
109+
- <a href="https://pkg.go.dev/github.com/openai/openai-go">openai</a>.<a href="https://pkg.go.dev/github.com/openai/openai-go#AudioModel">AudioModel</a>
110+
103111
## Transcriptions
104112

105113
Response Types:
@@ -122,12 +130,20 @@ Methods:
122130

123131
## Speech
124132

133+
Params Types:
134+
135+
- <a href="https://pkg.go.dev/github.com/openai/openai-go">openai</a>.<a href="https://pkg.go.dev/github.com/openai/openai-go#SpeechModel">SpeechModel</a>
136+
125137
Methods:
126138

127139
- <code title="post /audio/speech">client.Audio.Speech.<a href="https://pkg.go.dev/github.com/openai/openai-go#AudioSpeechService.New">New</a>(ctx <a href="https://pkg.go.dev/context">context</a>.<a href="https://pkg.go.dev/context#Context">Context</a>, body <a href="https://pkg.go.dev/github.com/openai/openai-go">openai</a>.<a href="https://pkg.go.dev/github.com/openai/openai-go#AudioSpeechNewParams">AudioSpeechNewParams</a>) (http.Response, <a href="https://pkg.go.dev/builtin#error">error</a>)</code>
128140

129141
# Moderations
130142

143+
Params Types:
144+
145+
- <a href="https://pkg.go.dev/github.com/openai/openai-go">openai</a>.<a href="https://pkg.go.dev/github.com/openai/openai-go#ModerationModel">ModerationModel</a>
146+
131147
Response Types:
132148

133149
- <a href="https://pkg.go.dev/github.com/openai/openai-go">openai</a>.<a href="https://pkg.go.dev/github.com/openai/openai-go#Moderation">Moderation</a>

audio.go

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,3 +30,17 @@ func NewAudioService(opts ...option.RequestOption) (r *AudioService) {
3030
r.Speech = NewAudioSpeechService(opts...)
3131
return
3232
}
33+
34+
type AudioModel string
35+
36+
const (
37+
AudioModelWhisper1 AudioModel = "whisper-1"
38+
)
39+
40+
func (r AudioModel) IsKnown() bool {
41+
switch r {
42+
case AudioModelWhisper1:
43+
return true
44+
}
45+
return false
46+
}

audiospeech.go

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -40,12 +40,27 @@ func (r *AudioSpeechService) New(ctx context.Context, body AudioSpeechNewParams,
4040
return
4141
}
4242

43+
type SpeechModel string
44+
45+
const (
46+
SpeechModelTTS1 SpeechModel = "tts-1"
47+
SpeechModelTTS1HD SpeechModel = "tts-1-hd"
48+
)
49+
50+
func (r SpeechModel) IsKnown() bool {
51+
switch r {
52+
case SpeechModelTTS1, SpeechModelTTS1HD:
53+
return true
54+
}
55+
return false
56+
}
57+
4358
type AudioSpeechNewParams struct {
4459
// The text to generate audio for. The maximum length is 4096 characters.
4560
Input param.Field[string] `json:"input,required"`
4661
// One of the available [TTS models](https://platform.openai.com/docs/models/tts):
4762
// `tts-1` or `tts-1-hd`
48-
Model param.Field[AudioSpeechNewParamsModel] `json:"model,required"`
63+
Model param.Field[SpeechModel] `json:"model,required"`
4964
// The voice to use when generating the audio. Supported voices are `alloy`,
5065
// `echo`, `fable`, `onyx`, `nova`, and `shimmer`. Previews of the voices are
5166
// available in the
@@ -63,21 +78,6 @@ func (r AudioSpeechNewParams) MarshalJSON() (data []byte, err error) {
6378
return apijson.MarshalRoot(r)
6479
}
6580

66-
type AudioSpeechNewParamsModel string
67-
68-
const (
69-
AudioSpeechNewParamsModelTTS1 AudioSpeechNewParamsModel = "tts-1"
70-
AudioSpeechNewParamsModelTTS1HD AudioSpeechNewParamsModel = "tts-1-hd"
71-
)
72-
73-
func (r AudioSpeechNewParamsModel) IsKnown() bool {
74-
switch r {
75-
case AudioSpeechNewParamsModelTTS1, AudioSpeechNewParamsModelTTS1HD:
76-
return true
77-
}
78-
return false
79-
}
80-
8181
// The voice to use when generating the audio. Supported voices are `alloy`,
8282
// `echo`, `fable`, `onyx`, `nova`, and `shimmer`. Previews of the voices are
8383
// available in the

audiospeech_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ func TestAudioSpeechNewWithOptionalParams(t *testing.T) {
2828
)
2929
resp, err := client.Audio.Speech.New(context.TODO(), openai.AudioSpeechNewParams{
3030
Input: openai.F("input"),
31-
Model: openai.F(openai.AudioSpeechNewParamsModelTTS1),
31+
Model: openai.F(openai.SpeechModelTTS1),
3232
Voice: openai.F(openai.AudioSpeechNewParamsVoiceAlloy),
3333
ResponseFormat: openai.F(openai.AudioSpeechNewParamsResponseFormatMP3),
3434
Speed: openai.F(0.250000),

audiotranscription.go

Lines changed: 1 addition & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ type AudioTranscriptionNewParams struct {
7272
File param.Field[io.Reader] `json:"file,required" format:"binary"`
7373
// ID of the model to use. Only `whisper-1` (which is powered by our open source
7474
// Whisper V2 model) is currently available.
75-
Model param.Field[AudioTranscriptionNewParamsModel] `json:"model,required"`
75+
Model param.Field[AudioModel] `json:"model,required"`
7676
// The language of the input audio. Supplying the input language in
7777
// [ISO-639-1](https://en.wikipedia.org/wiki/List_of_ISO_639-1_codes) format will
7878
// improve accuracy and latency.
@@ -114,20 +114,6 @@ func (r AudioTranscriptionNewParams) MarshalMultipart() (data []byte, contentTyp
114114
return buf.Bytes(), writer.FormDataContentType(), nil
115115
}
116116

117-
type AudioTranscriptionNewParamsModel string
118-
119-
const (
120-
AudioTranscriptionNewParamsModelWhisper1 AudioTranscriptionNewParamsModel = "whisper-1"
121-
)
122-
123-
func (r AudioTranscriptionNewParamsModel) IsKnown() bool {
124-
switch r {
125-
case AudioTranscriptionNewParamsModelWhisper1:
126-
return true
127-
}
128-
return false
129-
}
130-
131117
// The format of the transcript output, in one of these options: `json`, `text`,
132118
// `srt`, `verbose_json`, or `vtt`.
133119
type AudioTranscriptionNewParamsResponseFormat string

audiotranscription_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ func TestAudioTranscriptionNewWithOptionalParams(t *testing.T) {
2929
)
3030
_, err := client.Audio.Transcriptions.New(context.TODO(), openai.AudioTranscriptionNewParams{
3131
File: openai.F(io.Reader(bytes.NewBuffer([]byte("some file contents")))),
32-
Model: openai.F(openai.AudioTranscriptionNewParamsModelWhisper1),
32+
Model: openai.F(openai.AudioModelWhisper1),
3333
Language: openai.F("language"),
3434
Prompt: openai.F("prompt"),
3535
ResponseFormat: openai.F(openai.AudioTranscriptionNewParamsResponseFormatJSON),

audiotranslation.go

Lines changed: 1 addition & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ type AudioTranslationNewParams struct {
6969
File param.Field[io.Reader] `json:"file,required" format:"binary"`
7070
// ID of the model to use. Only `whisper-1` (which is powered by our open source
7171
// Whisper V2 model) is currently available.
72-
Model param.Field[AudioTranslationNewParamsModel] `json:"model,required"`
72+
Model param.Field[AudioModel] `json:"model,required"`
7373
// An optional text to guide the model's style or continue a previous audio
7474
// segment. The
7575
// [prompt](https://platform.openai.com/docs/guides/speech-to-text/prompting)
@@ -100,17 +100,3 @@ func (r AudioTranslationNewParams) MarshalMultipart() (data []byte, contentType
100100
}
101101
return buf.Bytes(), writer.FormDataContentType(), nil
102102
}
103-
104-
type AudioTranslationNewParamsModel string
105-
106-
const (
107-
AudioTranslationNewParamsModelWhisper1 AudioTranslationNewParamsModel = "whisper-1"
108-
)
109-
110-
func (r AudioTranslationNewParamsModel) IsKnown() bool {
111-
switch r {
112-
case AudioTranslationNewParamsModelWhisper1:
113-
return true
114-
}
115-
return false
116-
}

audiotranslation_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ func TestAudioTranslationNewWithOptionalParams(t *testing.T) {
2929
)
3030
_, err := client.Audio.Translations.New(context.TODO(), openai.AudioTranslationNewParams{
3131
File: openai.F(io.Reader(bytes.NewBuffer([]byte("some file contents")))),
32-
Model: openai.F(openai.AudioTranslationNewParamsModelWhisper1),
32+
Model: openai.F(openai.AudioModelWhisper1),
3333
Prompt: openai.F("prompt"),
3434
ResponseFormat: openai.F("response_format"),
3535
Temperature: openai.F(0.000000),

betaassistant.go

Lines changed: 1 addition & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1988,7 +1988,7 @@ type BetaAssistantNewParams struct {
19881988
// see all of your available models, or see our
19891989
// [Model overview](https://platform.openai.com/docs/models/overview) for
19901990
// descriptions of them.
1991-
Model param.Field[BetaAssistantNewParamsModel] `json:"model,required"`
1991+
Model param.Field[ChatModel] `json:"model,required"`
19921992
// The description of the assistant. The maximum length is 512 characters.
19931993
Description param.Field[string] `json:"description"`
19941994
// The system instructions that the assistant uses. The maximum length is 256,000
@@ -2042,41 +2042,6 @@ func (r BetaAssistantNewParams) MarshalJSON() (data []byte, err error) {
20422042
return apijson.MarshalRoot(r)
20432043
}
20442044

2045-
type BetaAssistantNewParamsModel string
2046-
2047-
const (
2048-
BetaAssistantNewParamsModelGPT4o BetaAssistantNewParamsModel = "gpt-4o"
2049-
BetaAssistantNewParamsModelGPT4o2024_05_13 BetaAssistantNewParamsModel = "gpt-4o-2024-05-13"
2050-
BetaAssistantNewParamsModelGPT4oMini BetaAssistantNewParamsModel = "gpt-4o-mini"
2051-
BetaAssistantNewParamsModelGPT4oMini2024_07_18 BetaAssistantNewParamsModel = "gpt-4o-mini-2024-07-18"
2052-
BetaAssistantNewParamsModelGPT4Turbo BetaAssistantNewParamsModel = "gpt-4-turbo"
2053-
BetaAssistantNewParamsModelGPT4Turbo2024_04_09 BetaAssistantNewParamsModel = "gpt-4-turbo-2024-04-09"
2054-
BetaAssistantNewParamsModelGPT4_0125Preview BetaAssistantNewParamsModel = "gpt-4-0125-preview"
2055-
BetaAssistantNewParamsModelGPT4TurboPreview BetaAssistantNewParamsModel = "gpt-4-turbo-preview"
2056-
BetaAssistantNewParamsModelGPT4_1106Preview BetaAssistantNewParamsModel = "gpt-4-1106-preview"
2057-
BetaAssistantNewParamsModelGPT4VisionPreview BetaAssistantNewParamsModel = "gpt-4-vision-preview"
2058-
BetaAssistantNewParamsModelGPT4 BetaAssistantNewParamsModel = "gpt-4"
2059-
BetaAssistantNewParamsModelGPT4_0314 BetaAssistantNewParamsModel = "gpt-4-0314"
2060-
BetaAssistantNewParamsModelGPT4_0613 BetaAssistantNewParamsModel = "gpt-4-0613"
2061-
BetaAssistantNewParamsModelGPT4_32k BetaAssistantNewParamsModel = "gpt-4-32k"
2062-
BetaAssistantNewParamsModelGPT4_32k0314 BetaAssistantNewParamsModel = "gpt-4-32k-0314"
2063-
BetaAssistantNewParamsModelGPT4_32k0613 BetaAssistantNewParamsModel = "gpt-4-32k-0613"
2064-
BetaAssistantNewParamsModelGPT3_5Turbo BetaAssistantNewParamsModel = "gpt-3.5-turbo"
2065-
BetaAssistantNewParamsModelGPT3_5Turbo16k BetaAssistantNewParamsModel = "gpt-3.5-turbo-16k"
2066-
BetaAssistantNewParamsModelGPT3_5Turbo0613 BetaAssistantNewParamsModel = "gpt-3.5-turbo-0613"
2067-
BetaAssistantNewParamsModelGPT3_5Turbo1106 BetaAssistantNewParamsModel = "gpt-3.5-turbo-1106"
2068-
BetaAssistantNewParamsModelGPT3_5Turbo0125 BetaAssistantNewParamsModel = "gpt-3.5-turbo-0125"
2069-
BetaAssistantNewParamsModelGPT3_5Turbo16k0613 BetaAssistantNewParamsModel = "gpt-3.5-turbo-16k-0613"
2070-
)
2071-
2072-
func (r BetaAssistantNewParamsModel) IsKnown() bool {
2073-
switch r {
2074-
case BetaAssistantNewParamsModelGPT4o, BetaAssistantNewParamsModelGPT4o2024_05_13, BetaAssistantNewParamsModelGPT4oMini, BetaAssistantNewParamsModelGPT4oMini2024_07_18, BetaAssistantNewParamsModelGPT4Turbo, BetaAssistantNewParamsModelGPT4Turbo2024_04_09, BetaAssistantNewParamsModelGPT4_0125Preview, BetaAssistantNewParamsModelGPT4TurboPreview, BetaAssistantNewParamsModelGPT4_1106Preview, BetaAssistantNewParamsModelGPT4VisionPreview, BetaAssistantNewParamsModelGPT4, BetaAssistantNewParamsModelGPT4_0314, BetaAssistantNewParamsModelGPT4_0613, BetaAssistantNewParamsModelGPT4_32k, BetaAssistantNewParamsModelGPT4_32k0314, BetaAssistantNewParamsModelGPT4_32k0613, BetaAssistantNewParamsModelGPT3_5Turbo, BetaAssistantNewParamsModelGPT3_5Turbo16k, BetaAssistantNewParamsModelGPT3_5Turbo0613, BetaAssistantNewParamsModelGPT3_5Turbo1106, BetaAssistantNewParamsModelGPT3_5Turbo0125, BetaAssistantNewParamsModelGPT3_5Turbo16k0613:
2075-
return true
2076-
}
2077-
return false
2078-
}
2079-
20802045
// A set of resources that are used by the assistant's tools. The resources are
20812046
// specific to the type of tool. For example, the `code_interpreter` tool requires
20822047
// a list of file IDs, while the `file_search` tool requires a list of vector store

betaassistant_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ func TestBetaAssistantNewWithOptionalParams(t *testing.T) {
2626
option.WithAPIKey("My API Key"),
2727
)
2828
_, err := client.Beta.Assistants.New(context.TODO(), openai.BetaAssistantNewParams{
29-
Model: openai.F(openai.BetaAssistantNewParamsModelGPT4o),
29+
Model: openai.F(openai.ChatModelGPT4o),
3030
Description: openai.F("description"),
3131
Instructions: openai.F("instructions"),
3232
Metadata: openai.F[any](map[string]interface{}{}),

0 commit comments

Comments
 (0)