Skip to content

Commit

Permalink
feat(api): add message image content (#1405)
Browse files Browse the repository at this point in the history
  • Loading branch information
stainless-bot committed May 9, 2024
1 parent 064a34a commit 79a0b40
Show file tree
Hide file tree
Showing 28 changed files with 295 additions and 64 deletions.
2 changes: 1 addition & 1 deletion .stats.yml
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
configured_endpoints: 64
openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/openai-2e14236d4015bf3b956290ea8b656224a0c7b206a356c6af2a7ae43fdbceb04c.yml
openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/openai-084b8f68408c6b689a55200a78bcf233769bfcd8e999d9fadaeb399152b05bcd.yml
6 changes: 6 additions & 0 deletions api.md
Original file line number Diff line number Diff line change
Expand Up @@ -374,14 +374,20 @@ from openai.types.beta.threads import (
ImageFileContentBlock,
ImageFileDelta,
ImageFileDeltaBlock,
ImageURL,
ImageURLContentBlock,
ImageURLDelta,
ImageURLDeltaBlock,
Message,
MessageContent,
MessageContentDelta,
MessageContentPartParam,
MessageDeleted,
MessageDelta,
MessageDeltaEvent,
Text,
TextContentBlock,
TextContentBlockParam,
TextDelta,
TextDeltaBlock,
)
Expand Down
11 changes: 6 additions & 5 deletions src/openai/resources/beta/threads/messages.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

from __future__ import annotations

from typing import Iterable, Optional
from typing import Union, Iterable, Optional
from typing_extensions import Literal

import httpx
Expand All @@ -24,6 +24,7 @@
from ....types.beta.threads import message_list_params, message_create_params, message_update_params
from ....types.beta.threads.message import Message
from ....types.beta.threads.message_deleted import MessageDeleted
from ....types.beta.threads.message_content_part_param import MessageContentPartParam

__all__ = ["Messages", "AsyncMessages"]

Expand All @@ -41,7 +42,7 @@ def create(
self,
thread_id: str,
*,
content: str,
content: Union[str, Iterable[MessageContentPartParam]],
role: Literal["user", "assistant"],
attachments: Optional[Iterable[message_create_params.Attachment]] | NotGiven = NOT_GIVEN,
metadata: Optional[object] | NotGiven = NOT_GIVEN,
Expand All @@ -56,7 +57,7 @@ def create(
Create a message.
Args:
content: The content of the message.
content: The text contents of the message.
role:
The role of the entity that is creating the message. Allowed values include:
Expand Down Expand Up @@ -304,7 +305,7 @@ async def create(
self,
thread_id: str,
*,
content: str,
content: Union[str, Iterable[MessageContentPartParam]],
role: Literal["user", "assistant"],
attachments: Optional[Iterable[message_create_params.Attachment]] | NotGiven = NOT_GIVEN,
metadata: Optional[object] | NotGiven = NOT_GIVEN,
Expand All @@ -319,7 +320,7 @@ async def create(
Create a message.
Args:
content: The content of the message.
content: The text contents of the message.
role:
The role of the entity that is creating the message. Allowed values include:
Expand Down
6 changes: 4 additions & 2 deletions src/openai/resources/files.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,8 @@ def create(
Use "assistants" for
[Assistants](https://platform.openai.com/docs/api-reference/assistants) and
[Messages](https://platform.openai.com/docs/api-reference/messages), "batch" for
[Message](https://platform.openai.com/docs/api-reference/messages) files,
"vision" for Assistants image file inputs, "batch" for
[Batch API](https://platform.openai.com/docs/guides/batch), and "fine-tune" for
[Fine-tuning](https://platform.openai.com/docs/api-reference/fine-tuning).
Expand Down Expand Up @@ -353,7 +354,8 @@ async def create(
Use "assistants" for
[Assistants](https://platform.openai.com/docs/api-reference/assistants) and
[Messages](https://platform.openai.com/docs/api-reference/messages), "batch" for
[Message](https://platform.openai.com/docs/api-reference/messages) files,
"vision" for Assistants image file inputs, "batch" for
[Batch API](https://platform.openai.com/docs/guides/batch), and "fine-tune" for
[Fine-tuning](https://platform.openai.com/docs/api-reference/fine-tuning).
Expand Down
5 changes: 3 additions & 2 deletions src/openai/types/beta/thread_create_and_run_params.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
from .file_search_tool_param import FileSearchToolParam
from .code_interpreter_tool_param import CodeInterpreterToolParam
from .assistant_tool_choice_option_param import AssistantToolChoiceOptionParam
from .threads.message_content_part_param import MessageContentPartParam
from .assistant_response_format_option_param import AssistantResponseFormatOptionParam

__all__ = [
Expand Down Expand Up @@ -184,8 +185,8 @@ class ThreadMessageAttachment(TypedDict, total=False):


class ThreadMessage(TypedDict, total=False):
content: Required[str]
"""The content of the message."""
content: Required[Union[str, Iterable[MessageContentPartParam]]]
"""The text contents of the message."""

role: Required[Literal["user", "assistant"]]
"""The role of the entity that is creating the message. Allowed values include:
Expand Down
5 changes: 3 additions & 2 deletions src/openai/types/beta/thread_create_params.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

from .file_search_tool_param import FileSearchToolParam
from .code_interpreter_tool_param import CodeInterpreterToolParam
from .threads.message_content_part_param import MessageContentPartParam

__all__ = [
"ThreadCreateParams",
Expand Down Expand Up @@ -56,8 +57,8 @@ class MessageAttachment(TypedDict, total=False):


class Message(TypedDict, total=False):
content: Required[str]
"""The content of the message."""
content: Required[Union[str, Iterable[MessageContentPartParam]]]
"""The text contents of the message."""

role: Required[Literal["user", "assistant"]]
"""The role of the entity that is creating the message. Allowed values include:
Expand Down
10 changes: 10 additions & 0 deletions src/openai/types/beta/threads/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,30 +5,40 @@
from .run import Run as Run
from .text import Text as Text
from .message import Message as Message
from .image_url import ImageURL as ImageURL
from .annotation import Annotation as Annotation
from .image_file import ImageFile as ImageFile
from .run_status import RunStatus as RunStatus
from .text_delta import TextDelta as TextDelta
from .message_delta import MessageDelta as MessageDelta
from .image_url_delta import ImageURLDelta as ImageURLDelta
from .image_url_param import ImageURLParam as ImageURLParam
from .message_content import MessageContent as MessageContent
from .message_deleted import MessageDeleted as MessageDeleted
from .run_list_params import RunListParams as RunListParams
from .annotation_delta import AnnotationDelta as AnnotationDelta
from .image_file_delta import ImageFileDelta as ImageFileDelta
from .image_file_param import ImageFileParam as ImageFileParam
from .text_delta_block import TextDeltaBlock as TextDeltaBlock
from .run_create_params import RunCreateParams as RunCreateParams
from .run_update_params import RunUpdateParams as RunUpdateParams
from .text_content_block import TextContentBlock as TextContentBlock
from .message_delta_event import MessageDeltaEvent as MessageDeltaEvent
from .message_list_params import MessageListParams as MessageListParams
from .file_path_annotation import FilePathAnnotation as FilePathAnnotation
from .image_url_delta_block import ImageURLDeltaBlock as ImageURLDeltaBlock
from .message_content_delta import MessageContentDelta as MessageContentDelta
from .message_create_params import MessageCreateParams as MessageCreateParams
from .message_update_params import MessageUpdateParams as MessageUpdateParams
from .image_file_delta_block import ImageFileDeltaBlock as ImageFileDeltaBlock
from .image_url_content_block import ImageURLContentBlock as ImageURLContentBlock
from .file_citation_annotation import FileCitationAnnotation as FileCitationAnnotation
from .image_file_content_block import ImageFileContentBlock as ImageFileContentBlock
from .text_content_block_param import TextContentBlockParam as TextContentBlockParam
from .file_path_delta_annotation import FilePathDeltaAnnotation as FilePathDeltaAnnotation
from .message_content_part_param import MessageContentPartParam as MessageContentPartParam
from .image_url_content_block_param import ImageURLContentBlockParam as ImageURLContentBlockParam
from .file_citation_delta_annotation import FileCitationDeltaAnnotation as FileCitationDeltaAnnotation
from .image_file_content_block_param import ImageFileContentBlockParam as ImageFileContentBlockParam
from .run_submit_tool_outputs_params import RunSubmitToolOutputsParams as RunSubmitToolOutputsParams
from .required_action_function_tool_call import RequiredActionFunctionToolCall as RequiredActionFunctionToolCall
12 changes: 10 additions & 2 deletions src/openai/types/beta/threads/image_file.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.


from typing import Optional
from typing_extensions import Literal

from ...._models import BaseModel

Expand All @@ -11,5 +12,12 @@ class ImageFile(BaseModel):
file_id: str
"""
The [File](https://platform.openai.com/docs/api-reference/files) ID of the image
in the message content.
in the message content. Set `purpose="vision"` when uploading the File if you
need to later display the file content.
"""

detail: Optional[Literal["auto", "low", "high"]] = None
"""Specifies the detail level of the image if specified by the user.
`low` uses fewer tokens, you can opt in to high resolution using `high`.
"""
16 changes: 16 additions & 0 deletions src/openai/types/beta/threads/image_file_content_block_param.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.

from __future__ import annotations

from typing_extensions import Literal, Required, TypedDict

from .image_file_param import ImageFileParam

__all__ = ["ImageFileContentBlockParam"]


class ImageFileContentBlockParam(TypedDict, total=False):
image_file: Required[ImageFileParam]

type: Required[Literal["image_file"]]
"""Always `image_file`."""
10 changes: 9 additions & 1 deletion src/openai/types/beta/threads/image_file_delta.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,23 @@
# File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.

from typing import Optional
from typing_extensions import Literal

from ...._models import BaseModel

__all__ = ["ImageFileDelta"]


class ImageFileDelta(BaseModel):
detail: Optional[Literal["auto", "low", "high"]] = None
"""Specifies the detail level of the image if specified by the user.
`low` uses fewer tokens, you can opt in to high resolution using `high`.
"""

file_id: Optional[str] = None
"""
The [File](https://platform.openai.com/docs/api-reference/files) ID of the image
in the message content.
in the message content. Set `purpose="vision"` when uploading the File if you
need to later display the file content.
"""
22 changes: 22 additions & 0 deletions src/openai/types/beta/threads/image_file_param.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.

from __future__ import annotations

from typing_extensions import Literal, Required, TypedDict

__all__ = ["ImageFileParam"]


class ImageFileParam(TypedDict, total=False):
file_id: Required[str]
"""
The [File](https://platform.openai.com/docs/api-reference/files) ID of the image
in the message content. Set `purpose="vision"` when uploading the File if you
need to later display the file content.
"""

detail: Literal["auto", "low", "high"]
"""Specifies the detail level of the image if specified by the user.
`low` uses fewer tokens, you can opt in to high resolution using `high`.
"""
23 changes: 23 additions & 0 deletions src/openai/types/beta/threads/image_url.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.

from typing import Optional
from typing_extensions import Literal

from ...._models import BaseModel

__all__ = ["ImageURL"]


class ImageURL(BaseModel):
url: str
"""
The external URL of the image, must be a supported image types: jpeg, jpg, png,
gif, webp.
"""

detail: Optional[Literal["auto", "low", "high"]] = None
"""Specifies the detail level of the image.
`low` uses fewer tokens, you can opt in to high resolution using `high`. Default
value is `auto`
"""
15 changes: 15 additions & 0 deletions src/openai/types/beta/threads/image_url_content_block.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.

from typing_extensions import Literal

from .image_url import ImageURL
from ...._models import BaseModel

__all__ = ["ImageURLContentBlock"]


class ImageURLContentBlock(BaseModel):
image_url: ImageURL

type: Literal["image_url"]
"""The type of the content part."""
16 changes: 16 additions & 0 deletions src/openai/types/beta/threads/image_url_content_block_param.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.

from __future__ import annotations

from typing_extensions import Literal, Required, TypedDict

from .image_url_param import ImageURLParam

__all__ = ["ImageURLContentBlockParam"]


class ImageURLContentBlockParam(TypedDict, total=False):
image_url: Required[ImageURLParam]

type: Required[Literal["image_url"]]
"""The type of the content part."""
22 changes: 22 additions & 0 deletions src/openai/types/beta/threads/image_url_delta.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.

from typing import Optional
from typing_extensions import Literal

from ...._models import BaseModel

__all__ = ["ImageURLDelta"]


class ImageURLDelta(BaseModel):
detail: Optional[Literal["auto", "low", "high"]] = None
"""Specifies the detail level of the image.
`low` uses fewer tokens, you can opt in to high resolution using `high`.
"""

url: Optional[str] = None
"""
The URL of the image, must be a supported image types: jpeg, jpg, png, gif,
webp.
"""
19 changes: 19 additions & 0 deletions src/openai/types/beta/threads/image_url_delta_block.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.

from typing import Optional
from typing_extensions import Literal

from ...._models import BaseModel
from .image_url_delta import ImageURLDelta

__all__ = ["ImageURLDeltaBlock"]


class ImageURLDeltaBlock(BaseModel):
index: int
"""The index of the content part in the message."""

type: Literal["image_url"]
"""Always `image_url`."""

image_url: Optional[ImageURLDelta] = None
22 changes: 22 additions & 0 deletions src/openai/types/beta/threads/image_url_param.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.

from __future__ import annotations

from typing_extensions import Literal, Required, TypedDict

__all__ = ["ImageURLParam"]


class ImageURLParam(TypedDict, total=False):
url: Required[str]
"""
The external URL of the image, must be a supported image types: jpeg, jpg, png,
gif, webp.
"""

detail: Literal["auto", "low", "high"]
"""Specifies the detail level of the image.
`low` uses fewer tokens, you can opt in to high resolution using `high`. Default
value is `auto`
"""
Loading

0 comments on commit 79a0b40

Please sign in to comment.