Skip to content

Commit a43b229

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 aac494c commit a43b229

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:
@@ -11729,6 +11744,14 @@ components:
1172911744
$ref: '#/components/schemas/OpenAIChatCompletionToolCall'
1173011745
type: array
1173111746
- type: 'null'
11747+
reasoning_content:
11748+
anyOf:
11749+
- type: string
11750+
- type: 'null'
11751+
reasoning:
11752+
anyOf:
11753+
- type: string
11754+
- type: 'null'
1173211755
type: object
1173311756
title: OpenAIAssistantMessageParam
1173411757
description: A message containing the model's (assistant) response in an OpenAI-compatible chat completion request.
@@ -11758,6 +11781,14 @@ components:
1175811781
$ref: '#/components/schemas/OpenAIChatCompletionToolCall'
1175911782
type: array
1176011783
- type: 'null'
11784+
reasoning_content:
11785+
anyOf:
11786+
- type: string
11787+
- type: 'null'
11788+
reasoning:
11789+
anyOf:
11790+
- type: string
11791+
- type: 'null'
1176111792
type: object
1176211793
title: OpenAIAssistantMessageParam
1176311794
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:
@@ -8572,6 +8587,14 @@ components:
85728587
$ref: '#/components/schemas/OpenAIChatCompletionToolCall'
85738588
type: array
85748589
- type: 'null'
8590+
reasoning_content:
8591+
anyOf:
8592+
- type: string
8593+
- type: 'null'
8594+
reasoning:
8595+
anyOf:
8596+
- type: string
8597+
- type: 'null'
85758598
type: object
85768599
title: OpenAIAssistantMessageParam
85778600
description: A message containing the model's (assistant) response in an OpenAI-compatible chat completion request.
@@ -8601,6 +8624,14 @@ components:
86018624
$ref: '#/components/schemas/OpenAIChatCompletionToolCall'
86028625
type: array
86038626
- type: 'null'
8627+
reasoning_content:
8628+
anyOf:
8629+
- type: string
8630+
- type: 'null'
8631+
reasoning:
8632+
anyOf:
8633+
- type: string
8634+
- type: 'null'
86048635
type: object
86058636
title: OpenAIAssistantMessageParam
86068637
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:
@@ -7570,6 +7585,14 @@ components:
75707585
$ref: '#/components/schemas/OpenAIChatCompletionToolCall'
75717586
type: array
75727587
- type: 'null'
7588+
reasoning_content:
7589+
anyOf:
7590+
- type: string
7591+
- type: 'null'
7592+
reasoning:
7593+
anyOf:
7594+
- type: string
7595+
- type: 'null'
75737596
type: object
75747597
title: OpenAIAssistantMessageParam
75757598
description: A message containing the model's (assistant) response in an OpenAI-compatible chat completion request.
@@ -7599,6 +7622,14 @@ components:
75997622
$ref: '#/components/schemas/OpenAIChatCompletionToolCall'
76007623
type: array
76017624
- type: 'null'
7625+
reasoning_content:
7626+
anyOf:
7627+
- type: string
7628+
- type: 'null'
7629+
reasoning:
7630+
anyOf:
7631+
- type: string
7632+
- type: 'null'
76027633
type: object
76037634
title: OpenAIAssistantMessageParam
76047635
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:
@@ -10399,6 +10414,14 @@ components:
1039910414
$ref: '#/components/schemas/OpenAIChatCompletionToolCall'
1040010415
type: array
1040110416
- type: 'null'
10417+
reasoning_content:
10418+
anyOf:
10419+
- type: string
10420+
- type: 'null'
10421+
reasoning:
10422+
anyOf:
10423+
- type: string
10424+
- type: 'null'
1040210425
type: object
1040310426
title: OpenAIAssistantMessageParam
1040410427
description: A message containing the model's (assistant) response in an OpenAI-compatible chat completion request.
@@ -10428,6 +10451,14 @@ components:
1042810451
$ref: '#/components/schemas/OpenAIChatCompletionToolCall'
1042910452
type: array
1043010453
- type: 'null'
10454+
reasoning_content:
10455+
anyOf:
10456+
- type: string
10457+
- type: 'null'
10458+
reasoning:
10459+
anyOf:
10460+
- type: string
10461+
- type: 'null'
1043110462
type: object
1043210463
title: OpenAIAssistantMessageParam
1043310464
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:
@@ -11729,6 +11744,14 @@ components:
1172911744
$ref: '#/components/schemas/OpenAIChatCompletionToolCall'
1173011745
type: array
1173111746
- type: 'null'
11747+
reasoning_content:
11748+
anyOf:
11749+
- type: string
11750+
- type: 'null'
11751+
reasoning:
11752+
anyOf:
11753+
- type: string
11754+
- type: 'null'
1173211755
type: object
1173311756
title: OpenAIAssistantMessageParam
1173411757
description: A message containing the model's (assistant) response in an OpenAI-compatible chat completion request.
@@ -11758,6 +11781,14 @@ components:
1175811781
$ref: '#/components/schemas/OpenAIChatCompletionToolCall'
1175911782
type: array
1176011783
- type: 'null'
11784+
reasoning_content:
11785+
anyOf:
11786+
- type: string
11787+
- type: 'null'
11788+
reasoning:
11789+
anyOf:
11790+
- type: string
11791+
- type: 'null'
1176111792
type: object
1176211793
title: OpenAIAssistantMessageParam
1176311794
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
@@ -449,12 +449,16 @@ class OpenAIAssistantMessageParam(BaseModel):
449449
:param content: The content of the model's response
450450
:param name: (Optional) The name of the assistant message participant.
451451
:param tool_calls: List of tool calls. Each tool call is an OpenAIChatCompletionToolCall object.
452+
:param reasoning_content: (Optional) The reasoning content from the model (for vLLM ≤ v0.8.4)
453+
:param reasoning: (Optional) The reasoning content from the model (for vLLM ≥ v0.9.x)
452454
"""
453455

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

459463

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

612617
content: str | None = None
613618
refusal: str | None = None
614619
role: str | None = None
615620
tool_calls: list[OpenAIChatCompletionToolCall] | None = None
616621
reasoning_content: str | None = None
622+
reasoning: str | None = None
617623

618624

619625
@json_schema_type

0 commit comments

Comments
 (0)