-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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.
Suggested change
Copilot is powered by AI, so mistakes are possible. Review output carefully before use. Positive FeedbackNegative Feedback |
||||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||||
}) | ||||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||
// TestCompletionWithGPT4oModels Tests that GPT4o models are not supported for completion endpoint. | ||||||||||||||||||||||||||||||||||||||||||||
func TestCompletionWithGPT4oModels(t *testing.T) { | ||||||||||||||||||||||||||||||||||||||||||||
config := openai.DefaultConfig("whatever") | ||||||||||||||||||||||||||||||||||||||||||||
config.BaseURL = "http://localhost/v1" | ||||||||||||||||||||||||||||||||||||||||||||
client := openai.NewClientWithConfig(config) | ||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||
models := []string{ | ||||||||||||||||||||||||||||||||||||||||||||
openai.GPT4o, | ||||||||||||||||||||||||||||||||||||||||||||
openai.GPT4o20240513, | ||||||||||||||||||||||||||||||||||||||||||||
openai.GPT4o20240806, | ||||||||||||||||||||||||||||||||||||||||||||
openai.GPT4o20241120, | ||||||||||||||||||||||||||||||||||||||||||||
openai.GPT4oLatest, | ||||||||||||||||||||||||||||||||||||||||||||
openai.GPT4oMini, | ||||||||||||||||||||||||||||||||||||||||||||
openai.GPT4oMini20240718, | ||||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||
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
+253
to
+262
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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.
Suggested change
Copilot is powered by AI, so mistakes are possible. Review output carefully before use. Positive FeedbackNegative Feedback |
||||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||||
}) | ||||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||||
} |
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!