Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions src/together/resources/chat/completions.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ def create(
response_format: Dict[str, Any] | None = None,
tools: List[Dict[str, Any]] | None = None,
tool_choice: str | Dict[str, str | Dict[str, str]] | None = None,
reasoning: Dict[str, Any] | None = None,
**kwargs: Any,
) -> ChatCompletionResponse | Iterator[ChatCompletionChunk]:
"""
Expand Down Expand Up @@ -103,6 +104,9 @@ def create(
via {"type": "function", "function": {"name": "my_function"}} forces the model to call that function.
Sets to `auto` if None.
Defaults to None.
reasoning (Dict[str, Any], optional): Configuration for reasoning models. Should contain "enabled" key.
Can optionally contain "effort" key with values "low", "medium", "high", or "auto".
Defaults to None.

Returns:
ChatCompletionResponse | Iterator[ChatCompletionChunk]: Object containing the completions
Expand Down Expand Up @@ -135,6 +139,7 @@ def create(
response_format=response_format,
tools=tools,
tool_choice=tool_choice,
reasoning=reasoning,
**kwargs,
).model_dump(exclude_none=True)

Expand Down Expand Up @@ -183,6 +188,7 @@ async def create(
response_format: Dict[str, Any] | None = None,
tools: Dict[str, str | Dict[str, str | Dict[str, Any]]] | None = None,
tool_choice: str | Dict[str, str | Dict[str, str]] | None = None,
reasoning: Dict[str, Any] | None = None,
**kwargs: Any,
) -> AsyncGenerator[ChatCompletionChunk, None] | ChatCompletionResponse:
"""
Expand Down Expand Up @@ -245,6 +251,9 @@ async def create(
via {"type": "function", "function": {"name": "my_function"}} forces the model to call that function.
Sets to `auto` if None.
Defaults to None.
reasoning (Dict[str, Any], optional): Configuration for reasoning models. Should contain "enabled" key.
Can optionally contain "effort" key with values "low", "medium", "high", or "auto".
Defaults to None.

Returns:
AsyncGenerator[ChatCompletionChunk, None] | ChatCompletionResponse: Object containing the completions
Expand Down Expand Up @@ -277,6 +286,7 @@ async def create(
response_format=response_format,
tools=tools,
tool_choice=tool_choice,
reasoning=reasoning,
**kwargs,
).model_dump(exclude_none=True)

Expand Down
4 changes: 4 additions & 0 deletions src/together/types/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@
ChatCompletionChunk,
ChatCompletionRequest,
ChatCompletionResponse,
Reasoning,
ReasoningEffort,
)
from together.types.common import TogetherRequest
from together.types.completions import (
Expand Down Expand Up @@ -95,6 +97,8 @@
"ChatCompletionChunk",
"ChatCompletionRequest",
"ChatCompletionResponse",
"Reasoning",
"ReasoningEffort",
"EmbeddingRequest",
"EmbeddingResponse",
"FinetuneCheckpoint",
Expand Down
17 changes: 17 additions & 0 deletions src/together/types/chat_completions.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ class ChatCompletionMessage(BaseModel):
role: MessageRole
content: str | List[ChatCompletionMessageContent] | None = None
tool_calls: List[ToolCalls] | None = None
reasoning: str | None = None


class ResponseFormat(BaseModel):
Expand Down Expand Up @@ -114,6 +115,18 @@ class ToolChoiceEnum(str, Enum):
Required = "required"


class ReasoningEffort(str, Enum):
LOW = "low"
MEDIUM = "medium"
HIGH = "high"
AUTO = "auto"


class Reasoning(BaseModel):
enabled: bool
effort: ReasoningEffort | None = None


class ChatCompletionRequest(BaseModel):
# list of messages
messages: List[ChatCompletionMessage]
Expand Down Expand Up @@ -148,6 +161,8 @@ class ChatCompletionRequest(BaseModel):
response_format: ResponseFormat | None = None
tools: List[Tools] | None = None
tool_choice: ToolChoice | ToolChoiceEnum | None = None
# reasoning configuration
reasoning: Reasoning | None = None

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


class ChatCompletionChoicesChunk(BaseModel):
Expand Down
1 change: 1 addition & 0 deletions src/together/types/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ class PromptPart(BaseModel):

class DeltaContent(BaseModel):
content: str | None = None
reasoning: str | None = None


class TogetherRequest(BaseModel):
Expand Down