Skip to content

Commit a115de6

Browse files
feat(api): add message image content (#1405)
1 parent 064a34a commit a115de6

28 files changed

+295
-64
lines changed

.stats.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
configured_endpoints: 64
2-
openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/openai-2e14236d4015bf3b956290ea8b656224a0c7b206a356c6af2a7ae43fdbceb04c.yml
2+
openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/openai-084b8f68408c6b689a55200a78bcf233769bfcd8e999d9fadaeb399152b05bcd.yml

api.md

+6
Original file line numberDiff line numberDiff line change
@@ -374,14 +374,20 @@ from openai.types.beta.threads import (
374374
ImageFileContentBlock,
375375
ImageFileDelta,
376376
ImageFileDeltaBlock,
377+
ImageURL,
378+
ImageURLContentBlock,
379+
ImageURLDelta,
380+
ImageURLDeltaBlock,
377381
Message,
378382
MessageContent,
379383
MessageContentDelta,
384+
MessageContentPartParam,
380385
MessageDeleted,
381386
MessageDelta,
382387
MessageDeltaEvent,
383388
Text,
384389
TextContentBlock,
390+
TextContentBlockParam,
385391
TextDelta,
386392
TextDeltaBlock,
387393
)

src/openai/resources/beta/threads/messages.py

+6-5
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
from __future__ import annotations
44

5-
from typing import Iterable, Optional
5+
from typing import Union, Iterable, Optional
66
from typing_extensions import Literal
77

88
import httpx
@@ -24,6 +24,7 @@
2424
from ....types.beta.threads import message_list_params, message_create_params, message_update_params
2525
from ....types.beta.threads.message import Message
2626
from ....types.beta.threads.message_deleted import MessageDeleted
27+
from ....types.beta.threads.message_content_part_param import MessageContentPartParam
2728

2829
__all__ = ["Messages", "AsyncMessages"]
2930

@@ -41,7 +42,7 @@ def create(
4142
self,
4243
thread_id: str,
4344
*,
44-
content: str,
45+
content: Union[str, Iterable[MessageContentPartParam]],
4546
role: Literal["user", "assistant"],
4647
attachments: Optional[Iterable[message_create_params.Attachment]] | NotGiven = NOT_GIVEN,
4748
metadata: Optional[object] | NotGiven = NOT_GIVEN,
@@ -56,7 +57,7 @@ def create(
5657
Create a message.
5758
5859
Args:
59-
content: The content of the message.
60+
content: The text contents of the message.
6061
6162
role:
6263
The role of the entity that is creating the message. Allowed values include:
@@ -304,7 +305,7 @@ async def create(
304305
self,
305306
thread_id: str,
306307
*,
307-
content: str,
308+
content: Union[str, Iterable[MessageContentPartParam]],
308309
role: Literal["user", "assistant"],
309310
attachments: Optional[Iterable[message_create_params.Attachment]] | NotGiven = NOT_GIVEN,
310311
metadata: Optional[object] | NotGiven = NOT_GIVEN,
@@ -319,7 +320,7 @@ async def create(
319320
Create a message.
320321
321322
Args:
322-
content: The content of the message.
323+
content: The text contents of the message.
323324
324325
role:
325326
The role of the entity that is creating the message. Allowed values include:

src/openai/resources/files.py

+4-2
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,8 @@ def create(
8181
8282
Use "assistants" for
8383
[Assistants](https://platform.openai.com/docs/api-reference/assistants) and
84-
[Messages](https://platform.openai.com/docs/api-reference/messages), "batch" for
84+
[Message](https://platform.openai.com/docs/api-reference/messages) files,
85+
"vision" for Assistants image file inputs, "batch" for
8586
[Batch API](https://platform.openai.com/docs/guides/batch), and "fine-tune" for
8687
[Fine-tuning](https://platform.openai.com/docs/api-reference/fine-tuning).
8788
@@ -353,7 +354,8 @@ async def create(
353354
354355
Use "assistants" for
355356
[Assistants](https://platform.openai.com/docs/api-reference/assistants) and
356-
[Messages](https://platform.openai.com/docs/api-reference/messages), "batch" for
357+
[Message](https://platform.openai.com/docs/api-reference/messages) files,
358+
"vision" for Assistants image file inputs, "batch" for
357359
[Batch API](https://platform.openai.com/docs/guides/batch), and "fine-tune" for
358360
[Fine-tuning](https://platform.openai.com/docs/api-reference/fine-tuning).
359361

src/openai/types/beta/thread_create_and_run_params.py

+3-2
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
from .file_search_tool_param import FileSearchToolParam
1010
from .code_interpreter_tool_param import CodeInterpreterToolParam
1111
from .assistant_tool_choice_option_param import AssistantToolChoiceOptionParam
12+
from .threads.message_content_part_param import MessageContentPartParam
1213
from .assistant_response_format_option_param import AssistantResponseFormatOptionParam
1314

1415
__all__ = [
@@ -184,8 +185,8 @@ class ThreadMessageAttachment(TypedDict, total=False):
184185

185186

186187
class ThreadMessage(TypedDict, total=False):
187-
content: Required[str]
188-
"""The content of the message."""
188+
content: Required[Union[str, Iterable[MessageContentPartParam]]]
189+
"""The text contents of the message."""
189190

190191
role: Required[Literal["user", "assistant"]]
191192
"""The role of the entity that is creating the message. Allowed values include:

src/openai/types/beta/thread_create_params.py

+3-2
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77

88
from .file_search_tool_param import FileSearchToolParam
99
from .code_interpreter_tool_param import CodeInterpreterToolParam
10+
from .threads.message_content_part_param import MessageContentPartParam
1011

1112
__all__ = [
1213
"ThreadCreateParams",
@@ -56,8 +57,8 @@ class MessageAttachment(TypedDict, total=False):
5657

5758

5859
class Message(TypedDict, total=False):
59-
content: Required[str]
60-
"""The content of the message."""
60+
content: Required[Union[str, Iterable[MessageContentPartParam]]]
61+
"""The text contents of the message."""
6162

6263
role: Required[Literal["user", "assistant"]]
6364
"""The role of the entity that is creating the message. Allowed values include:

src/openai/types/beta/threads/__init__.py

+10
Original file line numberDiff line numberDiff line change
@@ -5,30 +5,40 @@
55
from .run import Run as Run
66
from .text import Text as Text
77
from .message import Message as Message
8+
from .image_url import ImageURL as ImageURL
89
from .annotation import Annotation as Annotation
910
from .image_file import ImageFile as ImageFile
1011
from .run_status import RunStatus as RunStatus
1112
from .text_delta import TextDelta as TextDelta
1213
from .message_delta import MessageDelta as MessageDelta
14+
from .image_url_delta import ImageURLDelta as ImageURLDelta
15+
from .image_url_param import ImageURLParam as ImageURLParam
1316
from .message_content import MessageContent as MessageContent
1417
from .message_deleted import MessageDeleted as MessageDeleted
1518
from .run_list_params import RunListParams as RunListParams
1619
from .annotation_delta import AnnotationDelta as AnnotationDelta
1720
from .image_file_delta import ImageFileDelta as ImageFileDelta
21+
from .image_file_param import ImageFileParam as ImageFileParam
1822
from .text_delta_block import TextDeltaBlock as TextDeltaBlock
1923
from .run_create_params import RunCreateParams as RunCreateParams
2024
from .run_update_params import RunUpdateParams as RunUpdateParams
2125
from .text_content_block import TextContentBlock as TextContentBlock
2226
from .message_delta_event import MessageDeltaEvent as MessageDeltaEvent
2327
from .message_list_params import MessageListParams as MessageListParams
2428
from .file_path_annotation import FilePathAnnotation as FilePathAnnotation
29+
from .image_url_delta_block import ImageURLDeltaBlock as ImageURLDeltaBlock
2530
from .message_content_delta import MessageContentDelta as MessageContentDelta
2631
from .message_create_params import MessageCreateParams as MessageCreateParams
2732
from .message_update_params import MessageUpdateParams as MessageUpdateParams
2833
from .image_file_delta_block import ImageFileDeltaBlock as ImageFileDeltaBlock
34+
from .image_url_content_block import ImageURLContentBlock as ImageURLContentBlock
2935
from .file_citation_annotation import FileCitationAnnotation as FileCitationAnnotation
3036
from .image_file_content_block import ImageFileContentBlock as ImageFileContentBlock
37+
from .text_content_block_param import TextContentBlockParam as TextContentBlockParam
3138
from .file_path_delta_annotation import FilePathDeltaAnnotation as FilePathDeltaAnnotation
39+
from .message_content_part_param import MessageContentPartParam as MessageContentPartParam
40+
from .image_url_content_block_param import ImageURLContentBlockParam as ImageURLContentBlockParam
3241
from .file_citation_delta_annotation import FileCitationDeltaAnnotation as FileCitationDeltaAnnotation
42+
from .image_file_content_block_param import ImageFileContentBlockParam as ImageFileContentBlockParam
3343
from .run_submit_tool_outputs_params import RunSubmitToolOutputsParams as RunSubmitToolOutputsParams
3444
from .required_action_function_tool_call import RequiredActionFunctionToolCall as RequiredActionFunctionToolCall

src/openai/types/beta/threads/image_file.py

+10-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
# File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
22

3-
3+
from typing import Optional
4+
from typing_extensions import Literal
45

56
from ...._models import BaseModel
67

@@ -11,5 +12,12 @@ class ImageFile(BaseModel):
1112
file_id: str
1213
"""
1314
The [File](https://platform.openai.com/docs/api-reference/files) ID of the image
14-
in the message content.
15+
in the message content. Set `purpose="vision"` when uploading the File if you
16+
need to later display the file content.
17+
"""
18+
19+
detail: Optional[Literal["auto", "low", "high"]] = None
20+
"""Specifies the detail level of the image if specified by the user.
21+
22+
`low` uses fewer tokens, you can opt in to high resolution using `high`.
1523
"""
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
# File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
2+
3+
from __future__ import annotations
4+
5+
from typing_extensions import Literal, Required, TypedDict
6+
7+
from .image_file_param import ImageFileParam
8+
9+
__all__ = ["ImageFileContentBlockParam"]
10+
11+
12+
class ImageFileContentBlockParam(TypedDict, total=False):
13+
image_file: Required[ImageFileParam]
14+
15+
type: Required[Literal["image_file"]]
16+
"""Always `image_file`."""
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,23 @@
11
# File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
22

33
from typing import Optional
4+
from typing_extensions import Literal
45

56
from ...._models import BaseModel
67

78
__all__ = ["ImageFileDelta"]
89

910

1011
class ImageFileDelta(BaseModel):
12+
detail: Optional[Literal["auto", "low", "high"]] = None
13+
"""Specifies the detail level of the image if specified by the user.
14+
15+
`low` uses fewer tokens, you can opt in to high resolution using `high`.
16+
"""
17+
1118
file_id: Optional[str] = None
1219
"""
1320
The [File](https://platform.openai.com/docs/api-reference/files) ID of the image
14-
in the message content.
21+
in the message content. Set `purpose="vision"` when uploading the File if you
22+
need to later display the file content.
1523
"""
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
# File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
2+
3+
from __future__ import annotations
4+
5+
from typing_extensions import Literal, Required, TypedDict
6+
7+
__all__ = ["ImageFileParam"]
8+
9+
10+
class ImageFileParam(TypedDict, total=False):
11+
file_id: Required[str]
12+
"""
13+
The [File](https://platform.openai.com/docs/api-reference/files) ID of the image
14+
in the message content. Set `purpose="vision"` when uploading the File if you
15+
need to later display the file content.
16+
"""
17+
18+
detail: Literal["auto", "low", "high"]
19+
"""Specifies the detail level of the image if specified by the user.
20+
21+
`low` uses fewer tokens, you can opt in to high resolution using `high`.
22+
"""
+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
# File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
2+
3+
from typing import Optional
4+
from typing_extensions import Literal
5+
6+
from ...._models import BaseModel
7+
8+
__all__ = ["ImageURL"]
9+
10+
11+
class ImageURL(BaseModel):
12+
url: str
13+
"""
14+
The external URL of the image, must be a supported image types: jpeg, jpg, png,
15+
gif, webp.
16+
"""
17+
18+
detail: Optional[Literal["auto", "low", "high"]] = None
19+
"""Specifies the detail level of the image.
20+
21+
`low` uses fewer tokens, you can opt in to high resolution using `high`. Default
22+
value is `auto`
23+
"""
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
# File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
2+
3+
from typing_extensions import Literal
4+
5+
from .image_url import ImageURL
6+
from ...._models import BaseModel
7+
8+
__all__ = ["ImageURLContentBlock"]
9+
10+
11+
class ImageURLContentBlock(BaseModel):
12+
image_url: ImageURL
13+
14+
type: Literal["image_url"]
15+
"""The type of the content part."""
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
# File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
2+
3+
from __future__ import annotations
4+
5+
from typing_extensions import Literal, Required, TypedDict
6+
7+
from .image_url_param import ImageURLParam
8+
9+
__all__ = ["ImageURLContentBlockParam"]
10+
11+
12+
class ImageURLContentBlockParam(TypedDict, total=False):
13+
image_url: Required[ImageURLParam]
14+
15+
type: Required[Literal["image_url"]]
16+
"""The type of the content part."""
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
# File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
2+
3+
from typing import Optional
4+
from typing_extensions import Literal
5+
6+
from ...._models import BaseModel
7+
8+
__all__ = ["ImageURLDelta"]
9+
10+
11+
class ImageURLDelta(BaseModel):
12+
detail: Optional[Literal["auto", "low", "high"]] = None
13+
"""Specifies the detail level of the image.
14+
15+
`low` uses fewer tokens, you can opt in to high resolution using `high`.
16+
"""
17+
18+
url: Optional[str] = None
19+
"""
20+
The URL of the image, must be a supported image types: jpeg, jpg, png, gif,
21+
webp.
22+
"""
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
# File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
2+
3+
from typing import Optional
4+
from typing_extensions import Literal
5+
6+
from ...._models import BaseModel
7+
from .image_url_delta import ImageURLDelta
8+
9+
__all__ = ["ImageURLDeltaBlock"]
10+
11+
12+
class ImageURLDeltaBlock(BaseModel):
13+
index: int
14+
"""The index of the content part in the message."""
15+
16+
type: Literal["image_url"]
17+
"""Always `image_url`."""
18+
19+
image_url: Optional[ImageURLDelta] = None
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
# File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
2+
3+
from __future__ import annotations
4+
5+
from typing_extensions import Literal, Required, TypedDict
6+
7+
__all__ = ["ImageURLParam"]
8+
9+
10+
class ImageURLParam(TypedDict, total=False):
11+
url: Required[str]
12+
"""
13+
The external URL of the image, must be a supported image types: jpeg, jpg, png,
14+
gif, webp.
15+
"""
16+
17+
detail: Literal["auto", "low", "high"]
18+
"""Specifies the detail level of the image.
19+
20+
`low` uses fewer tokens, you can opt in to high resolution using `high`. Default
21+
value is `auto`
22+
"""

0 commit comments

Comments
 (0)