From 2dd937acbbeb5189e15cb35dd87e9fde95ea2fd4 Mon Sep 17 00:00:00 2001 From: orangetin Date: Wed, 25 Sep 2024 01:07:39 -0500 Subject: [PATCH] update messages[].content type --- src/together/abstract/api_requestor.py | 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/src/together/abstract/api_requestor.py b/src/together/abstract/api_requestor.py index 163443ab..511b0679 100644 --- a/src/together/abstract/api_requestor.py +++ b/src/together/abstract/api_requestor.py @@ -596,7 +596,7 @@ async def arequest_raw( try: result = await session.request( - method=options.method, url=abs_url, **request_kwargs + method=options.method, url=abs_url, **request_kwargs # type: ignore ) utils.log_debug( "Together API response", 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