From ec0772b5ebf6a0285afb2cd92caf95cbd9688a38 Mon Sep 17 00:00:00 2001 From: orangetin <126978607+orangetin@users.noreply.github.com> Date: Wed, 25 Sep 2024 06:16:03 -0700 Subject: [PATCH] update messages[].content type (#193) * update messages[].content type * remove type ignore * Bump to version 1.2.13 --- pyproject.toml | 2 +- src/together/resources/chat/completions.py | 4 ++-- src/together/types/chat_completions.py | 17 ++++++++++++++++- 3 files changed, 19 insertions(+), 4 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index 15111604..d8fcfc10 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -12,7 +12,7 @@ build-backend = "poetry.masonry.api" [tool.poetry] name = "together" -version = "1.2.12" +version = "1.2.13" authors = [ "Together AI " ] diff --git a/src/together/resources/chat/completions.py b/src/together/resources/chat/completions.py index f688c333..5e4b44b0 100644 --- a/src/together/resources/chat/completions.py +++ b/src/together/resources/chat/completions.py @@ -20,7 +20,7 @@ def __init__(self, client: TogetherClient) -> None: def create( self, *, - messages: List[Dict[str, str]], + messages: List[Dict[str, Any]], model: str, max_tokens: int | None = None, stop: List[str] | None = None, @@ -39,7 +39,7 @@ def create( n: int | None = None, safety_model: str | None = None, response_format: Dict[str, str | Dict[str, Any]] | None = None, - tools: Dict[str, str | Dict[str, Any]] | None = None, + tools: List[Dict[str, Any]] | None = None, tool_choice: str | Dict[str, str | Dict[str, str]] | None = None, **kwargs: Any, ) -> ChatCompletionResponse | Iterator[ChatCompletionChunk]: diff --git a/src/together/types/chat_completions.py b/src/together/types/chat_completions.py index 4a14b778..7f4159f8 100644 --- a/src/together/types/chat_completions.py +++ b/src/together/types/chat_completions.py @@ -40,9 +40,24 @@ class ToolCalls(BaseModel): function: FunctionCall | None = None +class ChatCompletionMessageContentType(str, Enum): + TEXT = "text" + IMAGE_URL = "image_url" + + +class ChatCompletionMessageContentImageURL(BaseModel): + url: str + + +class ChatCompletionMessageContent(BaseModel): + type: ChatCompletionMessageContentType + text: str | None = None + image_url: ChatCompletionMessageContentImageURL | None = None + + class ChatCompletionMessage(BaseModel): role: MessageRole - content: str | None = None + content: str | List[ChatCompletionMessageContent] | None = None tool_calls: List[ToolCalls] | None = None