Skip to content

Commit a0fadd3

Browse files
authored
Response format regex (#332)
* Update completions.py * Update chat_completions.py * fix mypy error * fix formatting error
1 parent 2479615 commit a0fadd3

File tree

2 files changed

+9
-2
lines changed

2 files changed

+9
-2
lines changed

src/together/resources/chat/completions.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ def create(
3838
echo: bool | None = None,
3939
n: int | None = None,
4040
safety_model: str | None = None,
41-
response_format: Dict[str, str | Dict[str, Any]] | None = None,
41+
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,
4444
**kwargs: Any,

src/together/types/chat_completions.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ class MessageRole(str, Enum):
2828
class ResponseFormatType(str, Enum):
2929
JSON_OBJECT = "json_object"
3030
JSON_SCHEMA = "json_schema"
31+
REGEX = "regex"
3132

3233

3334
class FunctionCall(BaseModel):
@@ -71,9 +72,15 @@ class ChatCompletionMessage(BaseModel):
7172
class ResponseFormat(BaseModel):
7273
type: ResponseFormatType
7374
schema_: Dict[str, Any] | None = None
75+
pattern: str | None = None
7476

7577
def to_dict(self) -> Dict[str, Any]:
76-
return {"schema": self.schema_, "type": self.type}
78+
result: Dict[str, Any] = {"type": self.type.value}
79+
if self.schema_ is not None:
80+
result["schema"] = self.schema_
81+
if self.pattern is not None:
82+
result["pattern"] = self.pattern
83+
return result
7784

7885

7986
class FunctionTool(BaseModel):

0 commit comments

Comments
 (0)