Skip to content

Commit f18b5eb

Browse files
authored
fix: Avoid BadRequestError due to invalid max_tokens (#3667)
This patch ensures if max tokens is not defined, then is set to None instead of 0 when calling openai_chat_completion. This way some providers (like gemini) that cannot handle the `max_tokens = 0` will not fail Issue: #3666
1 parent 00d8414 commit f18b5eb

File tree

171 files changed

+12728
-8
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

171 files changed

+12728
-8
lines changed

client-sdks/stainless/openapi.yml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11600,7 +11600,6 @@ components:
1160011600
description: The sampling strategy.
1160111601
max_tokens:
1160211602
type: integer
11603-
default: 0
1160411603
description: >-
1160511604
The maximum number of tokens that can be generated in the completion.
1160611605
The token count of your prompt plus max_tokens cannot exceed the model's

docs/static/deprecated-llama-stack-spec.html

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3901,7 +3901,6 @@
39013901
},
39023902
"max_tokens": {
39033903
"type": "integer",
3904-
"default": 0,
39053904
"description": "The maximum number of tokens that can be generated in the completion. The token count of your prompt plus max_tokens cannot exceed the model's context length."
39063905
},
39073906
"repetition_penalty": {

docs/static/deprecated-llama-stack-spec.yaml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2862,7 +2862,6 @@ components:
28622862
description: The sampling strategy.
28632863
max_tokens:
28642864
type: integer
2865-
default: 0
28662865
description: >-
28672866
The maximum number of tokens that can be generated in the completion.
28682867
The token count of your prompt plus max_tokens cannot exceed the model's

docs/static/experimental-llama-stack-spec.html

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2376,7 +2376,6 @@
23762376
},
23772377
"max_tokens": {
23782378
"type": "integer",
2379-
"default": 0,
23802379
"description": "The maximum number of tokens that can be generated in the completion. The token count of your prompt plus max_tokens cannot exceed the model's context length."
23812380
},
23822381
"repetition_penalty": {

docs/static/experimental-llama-stack-spec.yaml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1695,7 +1695,6 @@ components:
16951695
description: The sampling strategy.
16961696
max_tokens:
16971697
type: integer
1698-
default: 0
16991698
description: >-
17001699
The maximum number of tokens that can be generated in the completion.
17011700
The token count of your prompt plus max_tokens cannot exceed the model's

docs/static/stainless-llama-stack-spec.html

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15452,7 +15452,6 @@
1545215452
},
1545315453
"max_tokens": {
1545415454
"type": "integer",
15455-
"default": 0,
1545615455
"description": "The maximum number of tokens that can be generated in the completion. The token count of your prompt plus max_tokens cannot exceed the model's context length."
1545715456
},
1545815457
"repetition_penalty": {

docs/static/stainless-llama-stack-spec.yaml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11600,7 +11600,6 @@ components:
1160011600
description: The sampling strategy.
1160111601
max_tokens:
1160211602
type: integer
11603-
default: 0
1160411603
description: >-
1160511604
The maximum number of tokens that can be generated in the completion.
1160611605
The token count of your prompt plus max_tokens cannot exceed the model's

llama_stack/apis/inference/inference.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ class SamplingParams(BaseModel):
9797

9898
strategy: SamplingStrategy = Field(default_factory=GreedySamplingStrategy)
9999

100-
max_tokens: int | None = 0
100+
max_tokens: int | None = None
101101
repetition_penalty: float | None = 1.0
102102
stop: list[str] | None = None
103103

tests/integration/agents/recordings/007a9180a7aa38e17c1135ebf1f75e0d5ce1ea58e2261deba8c41e51196078ec.json

Lines changed: 59 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

tests/integration/agents/recordings/0275b5b0278c3188f5530957d25d7eb8ab8a9a14c0b9b31d9a70ad342b02353d.json

Lines changed: 59 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)