Skip to content

Commit b1851dc

Browse files
committed
feat: add reasoning and reasoning_content fields to OpenAI message types
Add support for reasoning fields in OpenAI-compatible chat completion messages to enable compatibility with vLLM reasoning parsers. Changes: - Add `reasoning_content` and `reasoning` fields to OpenAIAssistantMessageParam - Add `reasoning` field to OpenAIChoiceDelta (reasoning_content already existed) Both field names are supported for maximum compatibility: - `reasoning_content`: Used by vLLM ≤ v0.8.4 - `reasoning`: New field name in vLLM ≥ v0.9.x vLLM documentation recommends migrating to the shorter `reasoning` field name, but maintains backward compatibility with `reasoning_content`. These fields allow reasoning models to return their chain-of-thought process alongside the final answer, which is crucial for transparency and debugging with reasoning models. References: - vLLM Reasoning Outputs: https://docs.vllm.ai/en/stable/features/reasoning_outputs/ - vLLM Issue #12468: vllm-project/vllm#12468 Signed-off-by: Charlie Doern <[email protected]>
1 parent 618c034 commit b1851dc

File tree

6 files changed

+162
-1
lines changed

6 files changed

+162
-1
lines changed

client-sdks/stainless/openapi.yml

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4151,6 +4151,16 @@ components:
41514151
type: array
41524152
- type: 'null'
41534153
nullable: true
4154+
reasoning_content:
4155+
anyOf:
4156+
- type: string
4157+
- type: 'null'
4158+
nullable: true
4159+
reasoning:
4160+
anyOf:
4161+
- type: string
4162+
- type: 'null'
4163+
nullable: true
41544164
title: OpenAIAssistantMessageParam
41554165
type: object
41564166
OpenAIChatCompletionContentPartImageParam:
@@ -4880,6 +4890,11 @@ components:
48804890
- type: string
48814891
- type: 'null'
48824892
nullable: true
4893+
reasoning:
4894+
anyOf:
4895+
- type: string
4896+
- type: 'null'
4897+
nullable: true
48834898
title: OpenAIChoiceDelta
48844899
type: object
48854900
OpenAIChunkChoice:
@@ -11747,6 +11762,14 @@ components:
1174711762
$ref: '#/components/schemas/OpenAIChatCompletionToolCall'
1174811763
type: array
1174911764
- type: 'null'
11765+
reasoning_content:
11766+
anyOf:
11767+
- type: string
11768+
- type: 'null'
11769+
reasoning:
11770+
anyOf:
11771+
- type: string
11772+
- type: 'null'
1175011773
type: object
1175111774
title: OpenAIAssistantMessageParam
1175211775
description: A message containing the model's (assistant) response in an OpenAI-compatible chat completion request.
@@ -11776,6 +11799,14 @@ components:
1177611799
$ref: '#/components/schemas/OpenAIChatCompletionToolCall'
1177711800
type: array
1177811801
- type: 'null'
11802+
reasoning_content:
11803+
anyOf:
11804+
- type: string
11805+
- type: 'null'
11806+
reasoning:
11807+
anyOf:
11808+
- type: string
11809+
- type: 'null'
1177911810
type: object
1178011811
title: OpenAIAssistantMessageParam
1178111812
description: A message containing the model's (assistant) response in an OpenAI-compatible chat completion request.

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

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -994,6 +994,16 @@ components:
994994
type: array
995995
- type: 'null'
996996
nullable: true
997+
reasoning_content:
998+
anyOf:
999+
- type: string
1000+
- type: 'null'
1001+
nullable: true
1002+
reasoning:
1003+
anyOf:
1004+
- type: string
1005+
- type: 'null'
1006+
nullable: true
9971007
title: OpenAIAssistantMessageParam
9981008
type: object
9991009
OpenAIChatCompletionContentPartImageParam:
@@ -1723,6 +1733,11 @@ components:
17231733
- type: string
17241734
- type: 'null'
17251735
nullable: true
1736+
reasoning:
1737+
anyOf:
1738+
- type: string
1739+
- type: 'null'
1740+
nullable: true
17261741
title: OpenAIChoiceDelta
17271742
type: object
17281743
OpenAIChunkChoice:
@@ -8590,6 +8605,14 @@ components:
85908605
$ref: '#/components/schemas/OpenAIChatCompletionToolCall'
85918606
type: array
85928607
- type: 'null'
8608+
reasoning_content:
8609+
anyOf:
8610+
- type: string
8611+
- type: 'null'
8612+
reasoning:
8613+
anyOf:
8614+
- type: string
8615+
- type: 'null'
85938616
type: object
85948617
title: OpenAIAssistantMessageParam
85958618
description: A message containing the model's (assistant) response in an OpenAI-compatible chat completion request.
@@ -8619,6 +8642,14 @@ components:
86198642
$ref: '#/components/schemas/OpenAIChatCompletionToolCall'
86208643
type: array
86218644
- type: 'null'
8645+
reasoning_content:
8646+
anyOf:
8647+
- type: string
8648+
- type: 'null'
8649+
reasoning:
8650+
anyOf:
8651+
- type: string
8652+
- type: 'null'
86228653
type: object
86238654
title: OpenAIAssistantMessageParam
86248655
description: A message containing the model's (assistant) response in an OpenAI-compatible chat completion request.

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

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -859,6 +859,16 @@ components:
859859
type: array
860860
- type: 'null'
861861
nullable: true
862+
reasoning_content:
863+
anyOf:
864+
- type: string
865+
- type: 'null'
866+
nullable: true
867+
reasoning:
868+
anyOf:
869+
- type: string
870+
- type: 'null'
871+
nullable: true
862872
title: OpenAIAssistantMessageParam
863873
type: object
864874
OpenAIChatCompletionContentPartImageParam:
@@ -1588,6 +1598,11 @@ components:
15881598
- type: string
15891599
- type: 'null'
15901600
nullable: true
1601+
reasoning:
1602+
anyOf:
1603+
- type: string
1604+
- type: 'null'
1605+
nullable: true
15911606
title: OpenAIChoiceDelta
15921607
type: object
15931608
OpenAIChunkChoice:
@@ -7582,6 +7597,14 @@ components:
75827597
$ref: '#/components/schemas/OpenAIChatCompletionToolCall'
75837598
type: array
75847599
- type: 'null'
7600+
reasoning_content:
7601+
anyOf:
7602+
- type: string
7603+
- type: 'null'
7604+
reasoning:
7605+
anyOf:
7606+
- type: string
7607+
- type: 'null'
75857608
type: object
75867609
title: OpenAIAssistantMessageParam
75877610
description: A message containing the model's (assistant) response in an OpenAI-compatible chat completion request.
@@ -7611,6 +7634,14 @@ components:
76117634
$ref: '#/components/schemas/OpenAIChatCompletionToolCall'
76127635
type: array
76137636
- type: 'null'
7637+
reasoning_content:
7638+
anyOf:
7639+
- type: string
7640+
- type: 'null'
7641+
reasoning:
7642+
anyOf:
7643+
- type: string
7644+
- type: 'null'
76147645
type: object
76157646
title: OpenAIAssistantMessageParam
76167647
description: A message containing the model's (assistant) response in an OpenAI-compatible chat completion request.

docs/static/llama-stack-spec.yaml

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3172,6 +3172,16 @@ components:
31723172
type: array
31733173
- type: 'null'
31743174
nullable: true
3175+
reasoning_content:
3176+
anyOf:
3177+
- type: string
3178+
- type: 'null'
3179+
nullable: true
3180+
reasoning:
3181+
anyOf:
3182+
- type: string
3183+
- type: 'null'
3184+
nullable: true
31753185
title: OpenAIAssistantMessageParam
31763186
type: object
31773187
OpenAIChatCompletionContentPartImageParam:
@@ -3901,6 +3911,11 @@ components:
39013911
- type: string
39023912
- type: 'null'
39033913
nullable: true
3914+
reasoning:
3915+
anyOf:
3916+
- type: string
3917+
- type: 'null'
3918+
nullable: true
39043919
title: OpenAIChoiceDelta
39053920
type: object
39063921
OpenAIChunkChoice:
@@ -10417,6 +10432,14 @@ components:
1041710432
$ref: '#/components/schemas/OpenAIChatCompletionToolCall'
1041810433
type: array
1041910434
- type: 'null'
10435+
reasoning_content:
10436+
anyOf:
10437+
- type: string
10438+
- type: 'null'
10439+
reasoning:
10440+
anyOf:
10441+
- type: string
10442+
- type: 'null'
1042010443
type: object
1042110444
title: OpenAIAssistantMessageParam
1042210445
description: A message containing the model's (assistant) response in an OpenAI-compatible chat completion request.
@@ -10446,6 +10469,14 @@ components:
1044610469
$ref: '#/components/schemas/OpenAIChatCompletionToolCall'
1044710470
type: array
1044810471
- type: 'null'
10472+
reasoning_content:
10473+
anyOf:
10474+
- type: string
10475+
- type: 'null'
10476+
reasoning:
10477+
anyOf:
10478+
- type: string
10479+
- type: 'null'
1044910480
type: object
1045010481
title: OpenAIAssistantMessageParam
1045110482
description: A message containing the model's (assistant) response in an OpenAI-compatible chat completion request.

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

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4151,6 +4151,16 @@ components:
41514151
type: array
41524152
- type: 'null'
41534153
nullable: true
4154+
reasoning_content:
4155+
anyOf:
4156+
- type: string
4157+
- type: 'null'
4158+
nullable: true
4159+
reasoning:
4160+
anyOf:
4161+
- type: string
4162+
- type: 'null'
4163+
nullable: true
41544164
title: OpenAIAssistantMessageParam
41554165
type: object
41564166
OpenAIChatCompletionContentPartImageParam:
@@ -4880,6 +4890,11 @@ components:
48804890
- type: string
48814891
- type: 'null'
48824892
nullable: true
4893+
reasoning:
4894+
anyOf:
4895+
- type: string
4896+
- type: 'null'
4897+
nullable: true
48834898
title: OpenAIChoiceDelta
48844899
type: object
48854900
OpenAIChunkChoice:
@@ -11747,6 +11762,14 @@ components:
1174711762
$ref: '#/components/schemas/OpenAIChatCompletionToolCall'
1174811763
type: array
1174911764
- type: 'null'
11765+
reasoning_content:
11766+
anyOf:
11767+
- type: string
11768+
- type: 'null'
11769+
reasoning:
11770+
anyOf:
11771+
- type: string
11772+
- type: 'null'
1175011773
type: object
1175111774
title: OpenAIAssistantMessageParam
1175211775
description: A message containing the model's (assistant) response in an OpenAI-compatible chat completion request.
@@ -11776,6 +11799,14 @@ components:
1177611799
$ref: '#/components/schemas/OpenAIChatCompletionToolCall'
1177711800
type: array
1177811801
- type: 'null'
11802+
reasoning_content:
11803+
anyOf:
11804+
- type: string
11805+
- type: 'null'
11806+
reasoning:
11807+
anyOf:
11808+
- type: string
11809+
- type: 'null'
1177911810
type: object
1178011811
title: OpenAIAssistantMessageParam
1178111812
description: A message containing the model's (assistant) response in an OpenAI-compatible chat completion request.

src/llama_stack_api/inference.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -448,12 +448,16 @@ class OpenAIAssistantMessageParam(BaseModel):
448448
:param content: The content of the model's response
449449
:param name: (Optional) The name of the assistant message participant.
450450
:param tool_calls: List of tool calls. Each tool call is an OpenAIChatCompletionToolCall object.
451+
:param reasoning_content: (Optional) The reasoning content from the model (for vLLM ≤ v0.8.4)
452+
:param reasoning: (Optional) The reasoning content from the model (for vLLM ≥ v0.9.x)
451453
"""
452454

453455
role: Literal["assistant"] = "assistant"
454456
content: OpenAIChatCompletionTextOnlyMessageContent | None = None
455457
name: str | None = None
456458
tool_calls: list[OpenAIChatCompletionToolCall] | None = None
459+
reasoning_content: str | None = None
460+
reasoning: str | None = None
457461

458462

459463
@json_schema_type
@@ -605,14 +609,16 @@ class OpenAIChoiceDelta(BaseModel):
605609
:param refusal: (Optional) The refusal of the delta
606610
:param role: (Optional) The role of the delta
607611
:param tool_calls: (Optional) The tool calls of the delta
608-
:param reasoning_content: (Optional) The reasoning content from the model (non-standard, for o1/o3 models)
612+
:param reasoning_content: (Optional) The reasoning content from the model (for vLLM ≤ v0.8.4)
613+
:param reasoning: (Optional) The reasoning content from the model (for vLLM ≥ v0.9.x)
609614
"""
610615

611616
content: str | None = None
612617
refusal: str | None = None
613618
role: str | None = None
614619
tool_calls: list[OpenAIChatCompletionToolCall] | None = None
615620
reasoning_content: str | None = None
621+
reasoning: str | None = None
616622

617623

618624
@json_schema_type

0 commit comments

Comments
 (0)