Skip to content

obsolete max_tokens on GPT-5 models #100

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,20 @@ public class CompletionRequest {
* The maximum number of tokens to generate.
* Requests can use up to 2048 tokens shared between prompt and completion.
* (One token is roughly 4 characters for normal English text)
*
* @deprecated use {@link #maxCompletionTokens} on models after GPT-4.
*/
@Deprecated
@JsonProperty("max_tokens")
Integer maxTokens;

/**
* The maximum number of tokens to generate in the completion.
* This is the replacement for {@link #maxTokens} with the new models.
*/
@JsonProperty("max_completion_tokens")
Integer maxCompletionTokens;

/**
* What sampling temperature to use. Higher values means the model will take more risks.
* Try 0.9 for more creative applications, and 0 (argmax sampling) for ones with a well-defined answer.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,10 +81,20 @@ public class ChatCompletionRequest {
/**
* The maximum number of tokens allowed for the generated answer. By default, the number of tokens the model can return will
* be (4096 - prompt tokens).
*
* @deprecated use {@link #maxCompletionTokens} on models after GPT-4.
*/
@Deprecated
@JsonProperty("max_tokens")
Integer maxTokens;

/**
* The maximum number of tokens to generate in the completion.
* This is the replacement for {@link #maxTokens} with the new models.
*/
@JsonProperty("max_completion_tokens")
Integer maxCompletionTokens;

/**
* Number between -2.0 and 2.0. Positive values penalize new tokens based on whether they appear in the text so far,
* increasing the model's likelihood to talk about new topics.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ void createChatCompletion() {
.model("gpt-4o-mini")
.messages(messages)
.n(5)
.maxTokens(50)
.maxCompletionTokens(50)
.logitBias(new HashMap<>())
.build();

Expand All @@ -61,7 +61,7 @@ void streamChatCompletion() {
.model("gpt-4o-mini")
.messages(messages)
.n(1)
.maxTokens(50)
.maxCompletionTokens(50)
.logitBias(new HashMap<>())
.stream(true)
.build();
Expand All @@ -83,7 +83,7 @@ void streamOptionsChatCompletion() {
.model("gpt-4o-mini")
.messages(messages)
.n(1)
.maxTokens(50)
.maxCompletionTokens(50)
.logitBias(new HashMap<>())
.stream(true)
.streamOptions(StreamOption.INCLUDE)
Expand All @@ -108,7 +108,7 @@ void createChatCompletionWithJsonMode() {
.model("gpt-4o-mini")
.messages(messages)
.responseFormat(ChatResponseFormat.JSON_OBJECT)
.maxTokens(50)
.maxCompletionTokens(50)
.logitBias(new HashMap<>())
.build();

Expand Down Expand Up @@ -137,7 +137,7 @@ void createChatCompletionWithJsonSchema() throws JsonProcessingException {
.model("gpt-4o-2024-08-06")
.messages(messages)
.responseFormat(responseFormat)
.maxTokens(1000)
.maxCompletionTokens(1000)
.build();

ChatCompletionChoice choice = service.createChatCompletion(chatCompletionRequest).getChoices().get(0);
Expand Down Expand Up @@ -180,7 +180,7 @@ void createChatCompletionWithFunctions() {
.messages(messages)
.functions(functions)
.n(1)
.maxTokens(100)
.maxCompletionTokens(100)
.logitBias(new HashMap<>())
.build();

Expand Down Expand Up @@ -212,7 +212,7 @@ void createChatCompletionWithFunctions() {
.messages(messages)
.functions(functions)
.n(1)
.maxTokens(100)
.maxCompletionTokens(100)
.logitBias(new HashMap<>())
.build();

Expand Down Expand Up @@ -254,7 +254,7 @@ void createChatCompletionWithDynamicFunctions() {
.messages(messages)
.functions(Collections.singletonList(function))
.n(1)
.maxTokens(100)
.maxCompletionTokens(100)
.logitBias(new HashMap<>())
.build();

Expand All @@ -281,7 +281,7 @@ void zeroArgStreamFunctionTest() {
.messages(messages)
.functions(Collections.singletonList(FunctionDefinition.builder().name("get_today").description("Get the current date").executor((o) -> LocalDate.now()).build()))
.n(1)
.maxTokens(100)
.maxCompletionTokens(100)
.logitBias(new HashMap<>())
.build();
AssistantMessage accumulatedMessage = service.mapStreamToAccumulator(service.streamChatCompletion(chatCompletionRequest))
Expand All @@ -308,7 +308,7 @@ void zeroArgStreamToolTest() {
new ChatTool(FunctionDefinition.builder().name("get_today").description("Get the current date").executor((o) -> LocalDate.now()).build())
))
.n(1)
.maxTokens(100)
.maxCompletionTokens(100)
.logitBias(new HashMap<>())
.streamOptions(StreamOption.INCLUDE)
.build();
Expand Down Expand Up @@ -342,7 +342,7 @@ void streamChatCompletionWithFunctions() {
.messages(messages)
.functions(functions)
.n(1)
.maxTokens(100)
.maxCompletionTokens(100)
.logitBias(new HashMap<>())
.build();

Expand Down Expand Up @@ -376,7 +376,7 @@ void streamChatCompletionWithFunctions() {
.messages(messages)
.functions(functions)
.n(1)
.maxTokens(100)
.maxCompletionTokens(100)
.logitBias(new HashMap<>())
.build();

Expand Down Expand Up @@ -418,7 +418,7 @@ void streamChatCompletionWithDynamicFunctions() {
.messages(messages)
.functions(Collections.singletonList(function))
.n(1)
.maxTokens(100)
.maxCompletionTokens(100)
.logitBias(new HashMap<>())
.build();

Expand Down Expand Up @@ -451,7 +451,7 @@ void createChatCompletionWithToolFunctions() {
.tools(Arrays.asList(tool))
.toolChoice(ToolChoice.AUTO)
.n(1)
.maxTokens(100)
.maxCompletionTokens(100)
.build();

ChatCompletionChoice choice = service.createChatCompletion(chatCompletionRequest).getChoices().get(0);
Expand Down Expand Up @@ -485,7 +485,7 @@ void createChatCompletionWithToolFunctions() {
.tools(Arrays.asList(tool))
.toolChoice(ToolChoice.AUTO)
.n(1)
.maxTokens(100)
.maxCompletionTokens(100)
.logitBias(new HashMap<>())
.build();

Expand Down Expand Up @@ -539,7 +539,7 @@ void createChatCompletionWithMultipleToolCalls() {
.tools(tools)
.toolChoice(ToolChoice.AUTO)
.n(1)
.maxTokens(100)
.maxCompletionTokens(100)
.logitBias(new HashMap<>())
.build();

Expand Down Expand Up @@ -574,7 +574,7 @@ void createChatCompletionWithMultipleToolCalls() {
.tools(tools)
.toolChoice(ToolChoice.AUTO)
.n(1)
.maxTokens(100)
.maxCompletionTokens(100)
.logitBias(new HashMap<>())
.build();

Expand Down Expand Up @@ -602,7 +602,7 @@ void createChatCompletionWithMultipleToolCalls() {
.tools(tools)
.toolChoice(ToolChoice.AUTO)
.n(1)
.maxTokens(100)
.maxCompletionTokens(100)
.logitBias(new HashMap<>())
.build();

Expand Down Expand Up @@ -631,7 +631,7 @@ void createImageChatCompletion() {
.model("gpt-4o")
.messages(messages)
.n(1)
.maxTokens(200)
.maxCompletionTokens(200)
.build();

ChatCompletionChoice choice = service.createChatCompletion(chatCompletionRequest).getChoices().get(0);
Expand All @@ -652,7 +652,7 @@ void createLocalImageChatCompletion() throws URISyntaxException {
.model("gpt-4o-mini")
.messages(messages)
.n(1)
.maxTokens(200)
.maxCompletionTokens(200)
.build();

ChatCompletionChoice choice = service.createChatCompletion(chatCompletionRequest).getChoices().get(0);
Expand All @@ -673,7 +673,7 @@ void createInputAudioChatCompletion() throws URISyntaxException {
.model("gpt-4o-audio-preview")
.messages(messages)
.n(1)
.maxTokens(200)
.maxCompletionTokens(200)
.modalities(Arrays.asList("text", "audio"))
.audio(new Audio("alloy", "wav"))
.build();
Expand Down Expand Up @@ -728,7 +728,7 @@ void streamChatMultipleToolCalls() {
.tools(tools)
.toolChoice(ToolChoice.AUTO)
.n(1)
.maxTokens(200)
.maxCompletionTokens(200)
.build();

AssistantMessage accumulatedMessage = service.mapStreamToAccumulator(service.streamChatCompletion(chatCompletionRequest))
Expand Down Expand Up @@ -765,7 +765,7 @@ void streamChatMultipleToolCalls() {
.tools(tools)
.toolChoice(ToolChoice.AUTO)
.n(1)
.maxTokens(100)
.maxCompletionTokens(100)
.logitBias(new HashMap<>())
.build();

Expand Down Expand Up @@ -795,7 +795,7 @@ void streamChatMultipleToolCalls() {
.tools(tools)
.toolChoice(ToolChoice.AUTO)
.n(1)
.maxTokens(100)
.maxCompletionTokens(100)
.logitBias(new HashMap<>())
.build();

Expand Down