Skip to content

Commit a1dcfe2

Browse files
extrasmall0lesebclaude
authored
fix: change logprobs type from bool to int in Completions endpoint (#5343)
Fixes #5253 The `logprobs` field in `OpenAICompletionRequestWithExtraBody` was typed as `bool` but the OpenAI Completions API expects an integer (0–5) indicating how many top log probabilities to include per output token. This caused a 400 error when callers passed an int: ``` openai.BadRequestError: ... 'Input should be a valid boolean, unable to interpret input' ``` Changes: - `models.py`: `logprobs: bool | None` → `logprobs: int | None` with `ge=0, le=5` - `llama-stack-spec.yaml`: matching schema update (`boolean` → `integer` with min/max) The Chat Completions model (`OpenAIChatCompletionRequestWithExtraBody`) is unchanged — its `logprobs` is correctly a boolean there. --------- Signed-off-by: Extra Small <littleshuai.bot@gmail.com> Signed-off-by: Sébastien Han <seb@redhat.com> Co-authored-by: Sébastien Han <seb@redhat.com> Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent 729a3ee commit a1dcfe2

8 files changed

Lines changed: 33 additions & 17 deletions

File tree

client-sdks/stainless/openapi.yml

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5008,9 +5008,11 @@ components:
50085008
description: The logit bias to use.
50095009
logprobs:
50105010
anyOf:
5011-
- type: boolean
5011+
- type: integer
5012+
maximum: 5.0
5013+
minimum: 0.0
50125014
- type: 'null'
5013-
description: The log probabilities to use.
5015+
description: Include the log probabilities on the logprobs most likely output tokens.
50145016
max_tokens:
50155017
anyOf:
50165018
- type: integer

docs/static/deprecated-ogx-spec.yaml

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1311,9 +1311,11 @@ components:
13111311
description: The logit bias to use.
13121312
logprobs:
13131313
anyOf:
1314-
- type: boolean
1314+
- type: integer
1315+
maximum: 5.0
1316+
minimum: 0.0
13151317
- type: 'null'
1316-
description: The log probabilities to use.
1318+
description: Include the log probabilities on the logprobs most likely output tokens.
13171319
max_tokens:
13181320
anyOf:
13191321
- type: integer

docs/static/experimental-ogx-spec.yaml

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1752,9 +1752,11 @@ components:
17521752
description: The logit bias to use.
17531753
logprobs:
17541754
anyOf:
1755-
- type: boolean
1755+
- type: integer
1756+
maximum: 5.0
1757+
minimum: 0.0
17561758
- type: 'null'
1757-
description: The log probabilities to use.
1759+
description: Include the log probabilities on the logprobs most likely output tokens.
17581760
max_tokens:
17591761
anyOf:
17601762
- type: integer

docs/static/ogx-spec.yaml

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4565,9 +4565,11 @@ components:
45654565
description: The logit bias to use.
45664566
logprobs:
45674567
anyOf:
4568-
- type: boolean
4568+
- type: integer
4569+
maximum: 5.0
4570+
minimum: 0.0
45694571
- type: 'null'
4570-
description: The log probabilities to use.
4572+
description: Include the log probabilities on the logprobs most likely output tokens.
45714573
max_tokens:
45724574
anyOf:
45734575
- type: integer

docs/static/stainless-ogx-spec.yaml

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5008,9 +5008,11 @@ components:
50085008
description: The logit bias to use.
50095009
logprobs:
50105010
anyOf:
5011-
- type: boolean
5011+
- type: integer
5012+
maximum: 5.0
5013+
minimum: 0.0
50125014
- type: 'null'
5013-
description: The log probabilities to use.
5015+
description: Include the log probabilities on the logprobs most likely output tokens.
50145016
max_tokens:
50155017
anyOf:
50165018
- type: integer

src/ogx/providers/remote/inference/vertexai/vertexai.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ def from_openai_params(cls, params: OpenAICompletionRequestWithExtraBody) -> Gem
132132
candidate_count=params.n,
133133
max_output_tokens=params.max_tokens,
134134
stop_sequences=stop_sequences,
135-
response_logprobs=params.logprobs or None,
135+
response_logprobs=params.logprobs is not None and params.logprobs > 0,
136136
)
137137

138138

src/ogx_api/inference/models.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -948,7 +948,13 @@ class OpenAICompletionRequestWithExtraBody(BaseModel, extra="allow"):
948948
default=None, ge=-2.0, le=2.0, description="The penalty for repeated tokens."
949949
)
950950
logit_bias: dict[str, float] | None = Field(default=None, description="The logit bias to use.")
951-
logprobs: bool | None = Field(default=None, description="The log probabilities to use.")
951+
logprobs: int | None = Field(
952+
default=None,
953+
ge=0,
954+
le=5,
955+
strict=True,
956+
description="Include the log probabilities on the logprobs most likely output tokens.",
957+
)
952958
max_tokens: int | None = Field(default=None, ge=1, description="The maximum number of tokens to generate.")
953959
n: int | None = Field(default=None, ge=1, description="The number of completions to generate.")
954960
presence_penalty: float | None = Field(

tests/unit/providers/inference/vertexai/test_adapter_completion.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -164,25 +164,25 @@ async def test_logprobs_param_sets_response_logprobs(self, make_completion_adapt
164164
params = OpenAICompletionRequestWithExtraBody(
165165
model="google/gemini-2.5-flash",
166166
prompt="hi",
167-
logprobs=True,
167+
logprobs=5,
168168
)
169169
await adapter.openai_completion(params)
170170
call_kwargs = fake_client.aio.models.generate_content.call_args.kwargs
171171
config = call_kwargs["config"]
172172
assert config.response_logprobs is True
173173

174-
async def test_logprobs_false_sets_response_logprobs_none(self, make_completion_adapter):
175-
"""Test that logprobs false sets response logprobs none."""
174+
async def test_logprobs_zero_sets_response_logprobs_false(self, make_completion_adapter):
175+
"""Test that logprobs zero sets response logprobs false."""
176176
adapter, fake_client = make_completion_adapter()
177177
params = OpenAICompletionRequestWithExtraBody(
178178
model="google/gemini-2.5-flash",
179179
prompt="hi",
180-
logprobs=False,
180+
logprobs=0,
181181
)
182182
await adapter.openai_completion(params)
183183
call_kwargs = fake_client.aio.models.generate_content.call_args.kwargs
184184
config = call_kwargs["config"]
185-
assert getattr(config, "response_logprobs", None) is None
185+
assert config.response_logprobs is False
186186

187187
async def test_stream_raises_not_implemented_removed(self, monkeypatch):
188188
"""Test that stream raises not implemented removed."""

0 commit comments

Comments
 (0)