diff --git a/src/together/resources/chat/completions.py b/src/together/resources/chat/completions.py index f291e91..ee806e6 100644 --- a/src/together/resources/chat/completions.py +++ b/src/together/resources/chat/completions.py @@ -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]: """ @@ -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 @@ -135,6 +139,7 @@ def create( response_format=response_format, tools=tools, tool_choice=tool_choice, + reasoning=reasoning, **kwargs, ).model_dump(exclude_none=True) @@ -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: """ @@ -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 @@ -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) diff --git a/src/together/types/__init__.py b/src/together/types/__init__.py index 61c054a..36b9c84 100644 --- a/src/together/types/__init__.py +++ b/src/together/types/__init__.py @@ -22,6 +22,8 @@ ChatCompletionChunk, ChatCompletionRequest, ChatCompletionResponse, + Reasoning, + ReasoningEffort, ) from together.types.common import TogetherRequest from together.types.completions import ( @@ -95,6 +97,8 @@ "ChatCompletionChunk", "ChatCompletionRequest", "ChatCompletionResponse", + "Reasoning", + "ReasoningEffort", "EmbeddingRequest", "EmbeddingResponse", "FinetuneCheckpoint", diff --git a/src/together/types/chat_completions.py b/src/together/types/chat_completions.py index 0efd34f..44ec8d5 100644 --- a/src/together/types/chat_completions.py +++ b/src/together/types/chat_completions.py @@ -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): @@ -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] @@ -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") @@ -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): diff --git a/src/together/types/common.py b/src/together/types/common.py index e7ffa29..b6bc1d1 100644 --- a/src/together/types/common.py +++ b/src/together/types/common.py @@ -53,6 +53,7 @@ class PromptPart(BaseModel): class DeltaContent(BaseModel): content: str | None = None + reasoning: str | None = None class TogetherRequest(BaseModel):