Skip to content

Commit 2dbd98e

Browse files
committed
feat: add reasoning parameter support for chat completions
1 parent 137b84e commit 2dbd98e

File tree

4 files changed

+32
-0
lines changed

4 files changed

+32
-0
lines changed

src/together/resources/chat/completions.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ def create(
4141
response_format: Dict[str, Any] | None = None,
4242
tools: List[Dict[str, Any]] | None = None,
4343
tool_choice: str | Dict[str, str | Dict[str, str]] | None = None,
44+
reasoning: Dict[str, Any] | None = None,
4445
**kwargs: Any,
4546
) -> ChatCompletionResponse | Iterator[ChatCompletionChunk]:
4647
"""
@@ -103,6 +104,9 @@ def create(
103104
via {"type": "function", "function": {"name": "my_function"}} forces the model to call that function.
104105
Sets to `auto` if None.
105106
Defaults to None.
107+
reasoning (Dict[str, Any], optional): Configuration for reasoning models. Should contain "enabled" key.
108+
Can optionally contain "effort" key with values "low", "medium", "high", or "auto".
109+
Defaults to None.
106110
107111
Returns:
108112
ChatCompletionResponse | Iterator[ChatCompletionChunk]: Object containing the completions
@@ -135,6 +139,7 @@ def create(
135139
response_format=response_format,
136140
tools=tools,
137141
tool_choice=tool_choice,
142+
reasoning=reasoning,
138143
**kwargs,
139144
).model_dump(exclude_none=True)
140145

@@ -183,6 +188,7 @@ async def create(
183188
response_format: Dict[str, Any] | None = None,
184189
tools: Dict[str, str | Dict[str, str | Dict[str, Any]]] | None = None,
185190
tool_choice: str | Dict[str, str | Dict[str, str]] | None = None,
191+
reasoning: Dict[str, Any] | None = None,
186192
**kwargs: Any,
187193
) -> AsyncGenerator[ChatCompletionChunk, None] | ChatCompletionResponse:
188194
"""
@@ -245,6 +251,9 @@ async def create(
245251
via {"type": "function", "function": {"name": "my_function"}} forces the model to call that function.
246252
Sets to `auto` if None.
247253
Defaults to None.
254+
reasoning (Dict[str, Any], optional): Configuration for reasoning models. Should contain "enabled" key.
255+
Can optionally contain "effort" key with values "low", "medium", "high", or "auto".
256+
Defaults to None.
248257
249258
Returns:
250259
AsyncGenerator[ChatCompletionChunk, None] | ChatCompletionResponse: Object containing the completions
@@ -277,6 +286,7 @@ async def create(
277286
response_format=response_format,
278287
tools=tools,
279288
tool_choice=tool_choice,
289+
reasoning=reasoning,
280290
**kwargs,
281291
).model_dump(exclude_none=True)
282292

src/together/types/__init__.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@
2222
ChatCompletionChunk,
2323
ChatCompletionRequest,
2424
ChatCompletionResponse,
25+
Reasoning,
26+
ReasoningEffort,
2527
)
2628
from together.types.common import TogetherRequest
2729
from together.types.completions import (
@@ -95,6 +97,8 @@
9597
"ChatCompletionChunk",
9698
"ChatCompletionRequest",
9799
"ChatCompletionResponse",
100+
"Reasoning",
101+
"ReasoningEffort",
98102
"EmbeddingRequest",
99103
"EmbeddingResponse",
100104
"FinetuneCheckpoint",

src/together/types/chat_completions.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@ class ChatCompletionMessage(BaseModel):
7373
role: MessageRole
7474
content: str | List[ChatCompletionMessageContent] | None = None
7575
tool_calls: List[ToolCalls] | None = None
76+
reasoning: str | None = None
7677

7778

7879
class ResponseFormat(BaseModel):
@@ -114,6 +115,18 @@ class ToolChoiceEnum(str, Enum):
114115
Required = "required"
115116

116117

118+
class ReasoningEffort(str, Enum):
119+
LOW = "low"
120+
MEDIUM = "medium"
121+
HIGH = "high"
122+
AUTO = "auto"
123+
124+
125+
class Reasoning(BaseModel):
126+
enabled: bool
127+
effort: ReasoningEffort | None = None
128+
129+
117130
class ChatCompletionRequest(BaseModel):
118131
# list of messages
119132
messages: List[ChatCompletionMessage]
@@ -148,6 +161,8 @@ class ChatCompletionRequest(BaseModel):
148161
response_format: ResponseFormat | None = None
149162
tools: List[Tools] | None = None
150163
tool_choice: ToolChoice | ToolChoiceEnum | None = None
164+
# reasoning configuration
165+
reasoning: Reasoning | None = None
151166

152167
# Raise warning if repetition_penalty is used with presence_penalty or frequency_penalty
153168
@model_validator(mode="after")
@@ -183,6 +198,8 @@ class ChatCompletionResponse(BaseModel):
183198
prompt: List[PromptPart] | List[None] | None = None
184199
# token usage data
185200
usage: UsageData | None = None
201+
# metadata (may include weight_version, reasoning stats, etc.)
202+
metadata: Dict[str, Any] | None = None
186203

187204

188205
class ChatCompletionChoicesChunk(BaseModel):

src/together/types/common.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ class PromptPart(BaseModel):
5353

5454
class DeltaContent(BaseModel):
5555
content: str | None = None
56+
reasoning: str | None = None
5657

5758

5859
class TogetherRequest(BaseModel):

0 commit comments

Comments
 (0)