-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
feat: add new GPT-4.1 model variants to completion.go #966
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -181,3 +181,86 @@ func getCompletionBody(r *http.Request) (openai.CompletionRequest, error) { | |||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||
| return completion, nil | ||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||
| // TestCompletionWithO1Model Tests that O1 model is not supported for completion endpoint. | ||||||||||||||||||||||||||||||||||||||||||||
| func TestCompletionWithO1Model(t *testing.T) { | ||||||||||||||||||||||||||||||||||||||||||||
| config := openai.DefaultConfig("whatever") | ||||||||||||||||||||||||||||||||||||||||||||
| config.BaseURL = "http://localhost/v1" | ||||||||||||||||||||||||||||||||||||||||||||
| client := openai.NewClientWithConfig(config) | ||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||
| _, err := client.CreateCompletion( | ||||||||||||||||||||||||||||||||||||||||||||
| context.Background(), | ||||||||||||||||||||||||||||||||||||||||||||
| openai.CompletionRequest{ | ||||||||||||||||||||||||||||||||||||||||||||
| MaxTokens: 5, | ||||||||||||||||||||||||||||||||||||||||||||
| Model: openai.O1, | ||||||||||||||||||||||||||||||||||||||||||||
| }, | ||||||||||||||||||||||||||||||||||||||||||||
| ) | ||||||||||||||||||||||||||||||||||||||||||||
| if !errors.Is(err, openai.ErrCompletionUnsupportedModel) { | ||||||||||||||||||||||||||||||||||||||||||||
| t.Fatalf("CreateCompletion should return ErrCompletionUnsupportedModel for O1 model, but returned: %v", err) | ||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||
| // TestCompletionWithGPT4DotModels Tests that newer GPT4 models are not supported for completion endpoint. | ||||||||||||||||||||||||||||||||||||||||||||
| func TestCompletionWithGPT4DotModels(t *testing.T) { | ||||||||||||||||||||||||||||||||||||||||||||
| config := openai.DefaultConfig("whatever") | ||||||||||||||||||||||||||||||||||||||||||||
| config.BaseURL = "http://localhost/v1" | ||||||||||||||||||||||||||||||||||||||||||||
| client := openai.NewClientWithConfig(config) | ||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||
| models := []string{ | ||||||||||||||||||||||||||||||||||||||||||||
| openai.GPT4Dot1, | ||||||||||||||||||||||||||||||||||||||||||||
| openai.GPT4Dot120250414, | ||||||||||||||||||||||||||||||||||||||||||||
| openai.GPT4Dot1Mini, | ||||||||||||||||||||||||||||||||||||||||||||
| openai.GPT4Dot1Mini20250414, | ||||||||||||||||||||||||||||||||||||||||||||
| openai.GPT4Dot1Nano, | ||||||||||||||||||||||||||||||||||||||||||||
| openai.GPT4Dot1Nano20250414, | ||||||||||||||||||||||||||||||||||||||||||||
| openai.GPT4Dot5Preview, | ||||||||||||||||||||||||||||||||||||||||||||
| openai.GPT4Dot5Preview20250227, | ||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||
| for _, model := range models { | ||||||||||||||||||||||||||||||||||||||||||||
| t.Run(model, func(t *testing.T) { | ||||||||||||||||||||||||||||||||||||||||||||
| _, err := client.CreateCompletion( | ||||||||||||||||||||||||||||||||||||||||||||
| context.Background(), | ||||||||||||||||||||||||||||||||||||||||||||
| openai.CompletionRequest{ | ||||||||||||||||||||||||||||||||||||||||||||
| MaxTokens: 5, | ||||||||||||||||||||||||||||||||||||||||||||
| Model: model, | ||||||||||||||||||||||||||||||||||||||||||||
| }, | ||||||||||||||||||||||||||||||||||||||||||||
| ) | ||||||||||||||||||||||||||||||||||||||||||||
| if !errors.Is(err, openai.ErrCompletionUnsupportedModel) { | ||||||||||||||||||||||||||||||||||||||||||||
| t.Fatalf("CreateCompletion should return ErrCompletionUnsupportedModel for %s model, but returned: %v", model, err) | ||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+221
to
+230
|
||||||||||||||||||||||||||||||||||||||||||||
| t.Run(model, func(t *testing.T) { | |
| _, err := client.CreateCompletion( | |
| context.Background(), | |
| openai.CompletionRequest{ | |
| MaxTokens: 5, | |
| Model: model, | |
| }, | |
| ) | |
| if !errors.Is(err, openai.ErrCompletionUnsupportedModel) { | |
| t.Fatalf("CreateCompletion should return ErrCompletionUnsupportedModel for %s model, but returned: %v", model, err) | |
| m := model // Create a new local variable to capture the current value of model | |
| t.Run(m, func(t *testing.T) { | |
| _, err := client.CreateCompletion( | |
| context.Background(), | |
| openai.CompletionRequest{ | |
| MaxTokens: 5, | |
| Model: m, | |
| }, | |
| ) | |
| if !errors.Is(err, openai.ErrCompletionUnsupportedModel) { | |
| t.Fatalf("CreateCompletion should return ErrCompletionUnsupportedModel for %s model, but returned: %v", m, err) |
Copilot
AI
Apr 23, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When using t.Run inside a loop, the loop variable 'model' may be captured by reference, which could lead to unexpected behavior. Consider assigning the loop variable to a local variable (e.g., 'm := model') before invoking t.Run.
| t.Run(model, func(t *testing.T) { | |
| _, err := client.CreateCompletion( | |
| context.Background(), | |
| openai.CompletionRequest{ | |
| MaxTokens: 5, | |
| Model: model, | |
| }, | |
| ) | |
| if !errors.Is(err, openai.ErrCompletionUnsupportedModel) { | |
| t.Fatalf("CreateCompletion should return ErrCompletionUnsupportedModel for %s model, but returned: %v", model, err) | |
| m := model // Assign loop variable to a local variable | |
| t.Run(m, func(t *testing.T) { | |
| _, err := client.CreateCompletion( | |
| context.Background(), | |
| openai.CompletionRequest{ | |
| MaxTokens: 5, | |
| Model: m, | |
| }, | |
| ) | |
| if !errors.Is(err, openai.ErrCompletionUnsupportedModel) { | |
| t.Fatalf("CreateCompletion should return ErrCompletionUnsupportedModel for %s model, but returned: %v", m, err) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we should flip this mapping to an inverse one, most of the models are not enabled for completion endpoint!