Skip to content

Commit 495c905

Browse files
committed
Final nits
1 parent e61a78d commit 495c905

File tree

3 files changed

+61
-34
lines changed

3 files changed

+61
-34
lines changed

chat_stream_test.go

+25
Original file line numberDiff line numberDiff line change
@@ -934,6 +934,31 @@ func TestCreateChatCompletionStreamWithReasoningModel(t *testing.T) {
934934
}
935935
}
936936

937+
func TestCreateChatCompletionStreamReasoningValidatorFails(t *testing.T) {
938+
client, _, _ := setupOpenAITestServer()
939+
940+
stream, err := client.CreateChatCompletionStream(context.Background(), openai.ChatCompletionRequest{
941+
MaxTokens: 100, // This will trigger the validator to fail
942+
Model: openai.O3Mini,
943+
Messages: []openai.ChatCompletionMessage{
944+
{
945+
Role: openai.ChatMessageRoleUser,
946+
Content: "Hello!",
947+
},
948+
},
949+
Stream: true,
950+
})
951+
952+
if stream != nil {
953+
t.Error("Expected nil stream when validation fails")
954+
stream.Close()
955+
}
956+
957+
if !errors.Is(err, openai.ErrReasoningModelMaxTokensDeprecated) {
958+
t.Errorf("Expected ErrReasoningModelMaxTokensDeprecated, got: %v", err)
959+
}
960+
}
961+
937962
func compareChatStreamResponseChoices(c1, c2 openai.ChatCompletionStreamChoice) bool {
938963
if c1.Index != c2.Index {
939964
return false

completion.go

-33
Original file line numberDiff line numberDiff line change
@@ -2,33 +2,9 @@ package openai
22

33
import (
44
"context"
5-
"errors"
65
"net/http"
76
)
87

9-
var (
10-
// Deprecated: use ErrReasoningModelMaxTokensDeprecated instead.
11-
ErrO1MaxTokensDeprecated = errors.New("this model is not supported MaxTokens, please use MaxCompletionTokens") //nolint:lll
12-
ErrCompletionUnsupportedModel = errors.New("this model is not supported with this method, please use CreateChatCompletion client method instead") //nolint:lll
13-
ErrCompletionStreamNotSupported = errors.New("streaming is not supported with this method, please use CreateCompletionStream") //nolint:lll
14-
ErrCompletionRequestPromptTypeNotSupported = errors.New("the type of CompletionRequest.Prompt only supports string and []string") //nolint:lll
15-
)
16-
17-
var (
18-
ErrO1BetaLimitationsMessageTypes = errors.New("this model has beta-limitations, user and assistant messages only, system messages are not supported") //nolint:lll
19-
ErrO1BetaLimitationsTools = errors.New("this model has beta-limitations, tools, function calling, and response format parameters are not supported") //nolint:lll
20-
// Deprecated: use ErrReasoningModelLimitations* instead.
21-
ErrO1BetaLimitationsLogprobs = errors.New("this model has beta-limitations, logprobs not supported") //nolint:lll
22-
ErrO1BetaLimitationsOther = errors.New("this model has beta-limitations, temperature, top_p and n are fixed at 1, while presence_penalty and frequency_penalty are fixed at 0") //nolint:lll
23-
)
24-
25-
var (
26-
//nolint:lll
27-
ErrReasoningModelMaxTokensDeprecated = errors.New("this model is not supported MaxTokens, please use MaxCompletionTokens")
28-
ErrReasoningModelLimitationsLogprobs = errors.New("this model has beta-limitations, logprobs not supported") //nolint:lll
29-
ErrReasoningModelLimitationsOther = errors.New("this model has beta-limitations, temperature, top_p and n are fixed at 1, while presence_penalty and frequency_penalty are fixed at 0") //nolint:lll
30-
)
31-
328
// GPT3 Defines the models provided by OpenAI to use when generating
339
// completions from OpenAI.
3410
// GPT3 Models are designed for text-based tasks. For code-specific
@@ -187,15 +163,6 @@ func checkPromptType(prompt any) bool {
187163
return true // all items in the slice are string, so it is []string
188164
}
189165

190-
var unsupportedToolsForO1Models = map[ToolType]struct{}{
191-
ToolTypeFunction: {},
192-
}
193-
194-
var availableMessageRoleForO1Models = map[string]struct{}{
195-
ChatMessageRoleUser: {},
196-
ChatMessageRoleAssistant: {},
197-
}
198-
199166
// CompletionRequest represents a request structure for completion API.
200167
type CompletionRequest struct {
201168
Model string `json:"model"`

reasoning_validator.go

+36-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,41 @@
11
package openai
22

3-
import "strings"
3+
import (
4+
"errors"
5+
"strings"
6+
)
7+
8+
var (
9+
// Deprecated: use ErrReasoningModelMaxTokensDeprecated instead.
10+
ErrO1MaxTokensDeprecated = errors.New("this model is not supported MaxTokens, please use MaxCompletionTokens") //nolint:lll
11+
ErrCompletionUnsupportedModel = errors.New("this model is not supported with this method, please use CreateChatCompletion client method instead") //nolint:lll
12+
ErrCompletionStreamNotSupported = errors.New("streaming is not supported with this method, please use CreateCompletionStream") //nolint:lll
13+
ErrCompletionRequestPromptTypeNotSupported = errors.New("the type of CompletionRequest.Prompt only supports string and []string") //nolint:lll
14+
)
15+
16+
var (
17+
ErrO1BetaLimitationsMessageTypes = errors.New("this model has beta-limitations, user and assistant messages only, system messages are not supported") //nolint:lll
18+
ErrO1BetaLimitationsTools = errors.New("this model has beta-limitations, tools, function calling, and response format parameters are not supported") //nolint:lll
19+
// Deprecated: use ErrReasoningModelLimitations* instead.
20+
ErrO1BetaLimitationsLogprobs = errors.New("this model has beta-limitations, logprobs not supported") //nolint:lll
21+
ErrO1BetaLimitationsOther = errors.New("this model has beta-limitations, temperature, top_p and n are fixed at 1, while presence_penalty and frequency_penalty are fixed at 0") //nolint:lll
22+
)
23+
24+
var (
25+
//nolint:lll
26+
ErrReasoningModelMaxTokensDeprecated = errors.New("this model is not supported MaxTokens, please use MaxCompletionTokens")
27+
ErrReasoningModelLimitationsLogprobs = errors.New("this model has beta-limitations, logprobs not supported") //nolint:lll
28+
ErrReasoningModelLimitationsOther = errors.New("this model has beta-limitations, temperature, top_p and n are fixed at 1, while presence_penalty and frequency_penalty are fixed at 0") //nolint:lll
29+
)
30+
31+
var unsupportedToolsForO1Models = map[ToolType]struct{}{
32+
ToolTypeFunction: {},
33+
}
34+
35+
var availableMessageRoleForO1Models = map[string]struct{}{
36+
ChatMessageRoleUser: {},
37+
ChatMessageRoleAssistant: {},
38+
}
439

540
// ReasoningValidator handles validation for o-series model requests.
641
type ReasoningValidator struct {

0 commit comments

Comments
 (0)