@@ -5,6 +5,11 @@ import (
5
5
"net/http"
6
6
)
7
7
8
+ // Endpoint constants.
9
+ const (
10
+ completionsEndpoint = "/completions"
11
+ )
12
+
8
13
// GPT3 Defines the models provided by OpenAI to use when generating
9
14
// completions from OpenAI.
10
15
// GPT3 Models are designed for text-based tasks. For code-specific
@@ -91,71 +96,61 @@ const (
91
96
CodexCodeDavinci001 = "code-davinci-001"
92
97
)
93
98
94
- var disabledModelsForEndpoints = map [string ]map [string ]bool {
95
- "/completions" : {
96
- O1Mini : true ,
97
- O1Mini20240912 : true ,
98
- O1Preview : true ,
99
- O1Preview20240912 : true ,
100
- O3Mini : true ,
101
- O3Mini20250131 : true ,
102
- GPT3Dot5Turbo : true ,
103
- GPT3Dot5Turbo0301 : true ,
104
- GPT3Dot5Turbo0613 : true ,
105
- GPT3Dot5Turbo1106 : true ,
106
- GPT3Dot5Turbo0125 : true ,
107
- GPT3Dot5Turbo16K : true ,
108
- GPT3Dot5Turbo16K0613 : true ,
109
- GPT4 : true ,
110
- GPT4Dot5Preview : true ,
111
- GPT4Dot5Preview20250227 : true ,
112
- GPT4o : true ,
113
- GPT4o20240513 : true ,
114
- GPT4o20240806 : true ,
115
- GPT4o20241120 : true ,
116
- GPT4oLatest : true ,
117
- GPT4oMini : true ,
118
- GPT4oMini20240718 : true ,
119
- GPT4TurboPreview : true ,
120
- GPT4VisionPreview : true ,
121
- GPT4Turbo1106 : true ,
122
- GPT4Turbo0125 : true ,
123
- GPT4Turbo : true ,
124
- GPT4Turbo20240409 : true ,
125
- GPT40314 : true ,
126
- GPT40613 : true ,
127
- GPT432K : true ,
128
- GPT432K0314 : true ,
129
- GPT432K0613 : true ,
130
- O1 : true ,
131
- GPT4Dot1 : true ,
132
- GPT4Dot120250414 : true ,
133
- GPT4Dot1Mini : true ,
134
- GPT4Dot1Mini20250414 : true ,
135
- GPT4Dot1Nano : true ,
136
- GPT4Dot1Nano20250414 : true ,
137
- },
138
- chatCompletionsSuffix : {
139
- CodexCodeDavinci002 : true ,
140
- CodexCodeCushman001 : true ,
141
- CodexCodeDavinci001 : true ,
142
- GPT3TextDavinci003 : true ,
143
- GPT3TextDavinci002 : true ,
144
- GPT3TextCurie001 : true ,
145
- GPT3TextBabbage001 : true ,
146
- GPT3TextAda001 : true ,
147
- GPT3TextDavinci001 : true ,
148
- GPT3DavinciInstructBeta : true ,
149
- GPT3Davinci : true ,
150
- GPT3CurieInstructBeta : true ,
151
- GPT3Curie : true ,
152
- GPT3Ada : true ,
153
- GPT3Babbage : true ,
154
- },
99
+ // This map lists models that are *not* supported by the chat completions endpoint.
100
+ // We maintain this deny list because most new models *are* supported by chat completions.
101
+ // It is simpler to list the exceptions rather than updating an allow list
102
+ // each time a new model is released and supported.
103
+ var disabledModelsForChatCompletionsEndpoint = map [string ]bool {
104
+ CodexCodeCushman001 : true ,
105
+ CodexCodeDavinci001 : true ,
106
+ CodexCodeDavinci002 : true ,
107
+ GPT3Ada : true ,
108
+ GPT3Babbage : true ,
109
+ GPT3Curie : true ,
110
+ GPT3CurieInstructBeta : true ,
111
+ GPT3Davinci : true ,
112
+ GPT3DavinciInstructBeta : true ,
113
+ GPT3TextAda001 : true ,
114
+ GPT3TextBabbage001 : true ,
115
+ GPT3TextCurie001 : true ,
116
+ GPT3TextDavinci001 : true ,
117
+ GPT3TextDavinci002 : true ,
118
+ GPT3TextDavinci003 : true ,
119
+ }
120
+
121
+ // This map lists models that *are* supported by the deprecated completions endpoint.
122
+ // We maintain this allow list because the completions endpoint is deprecated and most new models
123
+ // are *not* supported by it. It is simpler to list the older models that are supported
124
+ // rather than updating a deny list each time a new model is released and *not* supported.
125
+ var enabledModelsForDeprecatedCompletionsEndpoint = map [string ]bool {
126
+ CodexCodeCushman001 : true ,
127
+ CodexCodeDavinci001 : true ,
128
+ CodexCodeDavinci002 : true ,
129
+ GPT3Ada : true ,
130
+ GPT3Ada002 : true ,
131
+ GPT3Babbage : true ,
132
+ GPT3Babbage002 : true ,
133
+ GPT3Curie : true ,
134
+ GPT3Curie002 : true ,
135
+ GPT3CurieInstructBeta : true ,
136
+ GPT3Davinci : true ,
137
+ GPT3Davinci002 : true ,
138
+ GPT3DavinciInstructBeta : true ,
139
+ GPT3Dot5TurboInstruct : true ,
140
+ GPT3TextAda001 : true ,
141
+ GPT3TextBabbage001 : true ,
142
+ GPT3TextCurie001 : true ,
143
+ GPT3TextDavinci001 : true ,
144
+ GPT3TextDavinci002 : true ,
145
+ GPT3TextDavinci003 : true ,
155
146
}
156
147
157
148
func checkEndpointSupportsModel (endpoint , model string ) bool {
158
- return ! disabledModelsForEndpoints [endpoint ][model ]
149
+ if endpoint == completionsEndpoint {
150
+ return enabledModelsForDeprecatedCompletionsEndpoint [model ]
151
+ }
152
+
153
+ return ! disabledModelsForChatCompletionsEndpoint [model ]
159
154
}
160
155
161
156
func checkPromptType (prompt any ) bool {
@@ -251,7 +246,7 @@ func (c *Client) CreateCompletion(
251
246
return
252
247
}
253
248
254
- urlSuffix := "/completions"
249
+ urlSuffix := completionsEndpoint
255
250
if ! checkEndpointSupportsModel (urlSuffix , request .Model ) {
256
251
err = ErrCompletionUnsupportedModel
257
252
return
0 commit comments