Skip to content

Commit f0a2d8d

Browse files
committed
feat(api): add message image content (openai#834)
1 parent 579edb5 commit f0a2d8d

File tree

11 files changed

+171
-44
lines changed

11 files changed

+171
-44
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
@@ -349,14 +349,20 @@ Types:
349349
- <code><a href="./src/resources/beta/threads/messages.ts">ImageFileContentBlock</a></code>
350350
- <code><a href="./src/resources/beta/threads/messages.ts">ImageFileDelta</a></code>
351351
- <code><a href="./src/resources/beta/threads/messages.ts">ImageFileDeltaBlock</a></code>
352+
- <code><a href="./src/resources/beta/threads/messages.ts">ImageURL</a></code>
353+
- <code><a href="./src/resources/beta/threads/messages.ts">ImageURLContentBlock</a></code>
354+
- <code><a href="./src/resources/beta/threads/messages.ts">ImageURLDelta</a></code>
355+
- <code><a href="./src/resources/beta/threads/messages.ts">ImageURLDeltaBlock</a></code>
352356
- <code><a href="./src/resources/beta/threads/messages.ts">Message</a></code>
353357
- <code><a href="./src/resources/beta/threads/messages.ts">MessageContent</a></code>
354358
- <code><a href="./src/resources/beta/threads/messages.ts">MessageContentDelta</a></code>
359+
- <code><a href="./src/resources/beta/threads/messages.ts">MessageContentPartParam</a></code>
355360
- <code><a href="./src/resources/beta/threads/messages.ts">MessageDeleted</a></code>
356361
- <code><a href="./src/resources/beta/threads/messages.ts">MessageDelta</a></code>
357362
- <code><a href="./src/resources/beta/threads/messages.ts">MessageDeltaEvent</a></code>
358363
- <code><a href="./src/resources/beta/threads/messages.ts">Text</a></code>
359364
- <code><a href="./src/resources/beta/threads/messages.ts">TextContentBlock</a></code>
365+
- <code><a href="./src/resources/beta/threads/messages.ts">TextContentBlockParam</a></code>
360366
- <code><a href="./src/resources/beta/threads/messages.ts">TextDelta</a></code>
361367
- <code><a href="./src/resources/beta/threads/messages.ts">TextDeltaBlock</a></code>
362368

src/lib/AssistantStream.ts

+5-6
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import {
77
ImageFile,
88
TextDelta,
99
Messages,
10+
MessageContent,
1011
} from 'openai/resources/beta/threads/messages';
1112
import * as Core from 'openai/core';
1213
import { RequestOptions } from 'openai/core';
@@ -87,7 +88,7 @@ export class AssistantStream
8788
#messageSnapshot: Message | undefined;
8889
#finalRun: Run | undefined;
8990
#currentContentIndex: number | undefined;
90-
#currentContent: TextContentBlock | ImageFileContentBlock | undefined;
91+
#currentContent: MessageContent | undefined;
9192
#currentToolCallIndex: number | undefined;
9293
#currentToolCall: ToolCall | undefined;
9394

@@ -624,10 +625,8 @@ export class AssistantStream
624625
currentContent,
625626
);
626627
} else {
627-
snapshot.content[contentElement.index] = contentElement as
628-
| TextContentBlock
629-
| ImageFileContentBlock;
630-
//This is a new element
628+
snapshot.content[contentElement.index] = contentElement as MessageContent;
629+
// This is a new element
631630
newContent.push(contentElement);
632631
}
633632
}
@@ -650,7 +649,7 @@ export class AssistantStream
650649

651650
#accumulateContent(
652651
contentElement: MessageContentDelta,
653-
currentContent: TextContentBlock | ImageFileContentBlock | undefined,
652+
currentContent: MessageContent | undefined,
654653
): TextContentBlock | ImageFileContentBlock {
655654
return AssistantStream.accumulateDelta(currentContent as unknown as Record<any, any>, contentElement) as
656655
| TextContentBlock

src/resources/beta/threads/index.ts

+6
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,20 @@ export {
1111
ImageFileContentBlock,
1212
ImageFileDelta,
1313
ImageFileDeltaBlock,
14+
ImageURL,
15+
ImageURLContentBlock,
16+
ImageURLDelta,
17+
ImageURLDeltaBlock,
1418
Message,
1519
MessageContent,
1620
MessageContentDelta,
21+
MessageContentPartParam,
1722
MessageDeleted,
1823
MessageDelta,
1924
MessageDeltaEvent,
2025
Text,
2126
TextContentBlock,
27+
TextContentBlockParam,
2228
TextDelta,
2329
TextDeltaBlock,
2430
MessageCreateParams,

src/resources/beta/threads/messages.ts

+104-6
Original file line numberDiff line numberDiff line change
@@ -249,9 +249,16 @@ export namespace FilePathDeltaAnnotation {
249249
export interface ImageFile {
250250
/**
251251
* The [File](https://platform.openai.com/docs/api-reference/files) ID of the image
252-
* in the message content.
252+
* in the message content. Set `purpose="vision"` when uploading the File if you
253+
* need to later display the file content.
253254
*/
254255
file_id: string;
256+
257+
/**
258+
* Specifies the detail level of the image if specified by the user. `low` uses
259+
* fewer tokens, you can opt in to high resolution using `high`.
260+
*/
261+
detail?: 'auto' | 'low' | 'high';
255262
}
256263

257264
/**
@@ -268,9 +275,16 @@ export interface ImageFileContentBlock {
268275
}
269276

270277
export interface ImageFileDelta {
278+
/**
279+
* Specifies the detail level of the image if specified by the user. `low` uses
280+
* fewer tokens, you can opt in to high resolution using `high`.
281+
*/
282+
detail?: 'auto' | 'low' | 'high';
283+
271284
/**
272285
* The [File](https://platform.openai.com/docs/api-reference/files) ID of the image
273-
* in the message content.
286+
* in the message content. Set `purpose="vision"` when uploading the File if you
287+
* need to later display the file content.
274288
*/
275289
file_id?: string;
276290
}
@@ -293,6 +307,63 @@ export interface ImageFileDeltaBlock {
293307
image_file?: ImageFileDelta;
294308
}
295309

310+
export interface ImageURL {
311+
/**
312+
* The external URL of the image, must be a supported image types: jpeg, jpg, png,
313+
* gif, webp.
314+
*/
315+
url: string;
316+
317+
/**
318+
* Specifies the detail level of the image. `low` uses fewer tokens, you can opt in
319+
* to high resolution using `high`. Default value is `auto`
320+
*/
321+
detail?: 'auto' | 'low' | 'high';
322+
}
323+
324+
/**
325+
* References an image URL in the content of a message.
326+
*/
327+
export interface ImageURLContentBlock {
328+
image_url: ImageURL;
329+
330+
/**
331+
* The type of the content part.
332+
*/
333+
type: 'image_url';
334+
}
335+
336+
export interface ImageURLDelta {
337+
/**
338+
* Specifies the detail level of the image. `low` uses fewer tokens, you can opt in
339+
* to high resolution using `high`.
340+
*/
341+
detail?: 'auto' | 'low' | 'high';
342+
343+
/**
344+
* The URL of the image, must be a supported image types: jpeg, jpg, png, gif,
345+
* webp.
346+
*/
347+
url?: string;
348+
}
349+
350+
/**
351+
* References an image URL in the content of a message.
352+
*/
353+
export interface ImageURLDeltaBlock {
354+
/**
355+
* The index of the content part in the message.
356+
*/
357+
index: number;
358+
359+
/**
360+
* Always `image_url`.
361+
*/
362+
type: 'image_url';
363+
364+
image_url?: ImageURLDelta;
365+
}
366+
296367
/**
297368
* Represents a message within a
298369
* [thread](https://platform.openai.com/docs/api-reference/threads).
@@ -406,13 +477,19 @@ export namespace Message {
406477
* References an image [File](https://platform.openai.com/docs/api-reference/files)
407478
* in the content of a message.
408479
*/
409-
export type MessageContent = ImageFileContentBlock | TextContentBlock;
480+
export type MessageContent = ImageFileContentBlock | ImageURLContentBlock | TextContentBlock;
481+
482+
/**
483+
* References an image [File](https://platform.openai.com/docs/api-reference/files)
484+
* in the content of a message.
485+
*/
486+
export type MessageContentDelta = ImageFileDeltaBlock | TextDeltaBlock | ImageURLDeltaBlock;
410487

411488
/**
412489
* References an image [File](https://platform.openai.com/docs/api-reference/files)
413490
* in the content of a message.
414491
*/
415-
export type MessageContentDelta = ImageFileDeltaBlock | TextDeltaBlock;
492+
export type MessageContentPartParam = ImageFileContentBlock | ImageURLContentBlock | TextContentBlockParam;
416493

417494
export interface MessageDeleted {
418495
id: string;
@@ -479,6 +556,21 @@ export interface TextContentBlock {
479556
type: 'text';
480557
}
481558

559+
/**
560+
* The text content that is part of a message.
561+
*/
562+
export interface TextContentBlockParam {
563+
/**
564+
* Text content to be sent to the model
565+
*/
566+
text: string;
567+
568+
/**
569+
* Always `text`.
570+
*/
571+
type: 'text';
572+
}
573+
482574
export interface TextDelta {
483575
annotations?: Array<AnnotationDelta>;
484576

@@ -507,9 +599,9 @@ export interface TextDeltaBlock {
507599

508600
export interface MessageCreateParams {
509601
/**
510-
* The content of the message.
602+
* The text contents of the message.
511603
*/
512-
content: string;
604+
content: string | Array<MessageContentPartParam>;
513605

514606
/**
515607
* The role of the entity that is creating the message. Allowed values include:
@@ -591,14 +683,20 @@ export namespace Messages {
591683
export import ImageFileContentBlock = MessagesAPI.ImageFileContentBlock;
592684
export import ImageFileDelta = MessagesAPI.ImageFileDelta;
593685
export import ImageFileDeltaBlock = MessagesAPI.ImageFileDeltaBlock;
686+
export import ImageURL = MessagesAPI.ImageURL;
687+
export import ImageURLContentBlock = MessagesAPI.ImageURLContentBlock;
688+
export import ImageURLDelta = MessagesAPI.ImageURLDelta;
689+
export import ImageURLDeltaBlock = MessagesAPI.ImageURLDeltaBlock;
594690
export import Message = MessagesAPI.Message;
595691
export import MessageContent = MessagesAPI.MessageContent;
596692
export import MessageContentDelta = MessagesAPI.MessageContentDelta;
693+
export import MessageContentPartParam = MessagesAPI.MessageContentPartParam;
597694
export import MessageDeleted = MessagesAPI.MessageDeleted;
598695
export import MessageDelta = MessagesAPI.MessageDelta;
599696
export import MessageDeltaEvent = MessagesAPI.MessageDeltaEvent;
600697
export import Text = MessagesAPI.Text;
601698
export import TextContentBlock = MessagesAPI.TextContentBlock;
699+
export import TextContentBlockParam = MessagesAPI.TextContentBlockParam;
602700
export import TextDelta = MessagesAPI.TextDelta;
603701
export import TextDeltaBlock = MessagesAPI.TextDeltaBlock;
604702
export import MessagesPage = MessagesAPI.MessagesPage;

src/resources/beta/threads/runs/runs.ts

+9-8
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import { sleep } from 'openai/core';
99
import { RunSubmitToolOutputsParamsStream } from 'openai/lib/AssistantStream';
1010
import * as RunsAPI from 'openai/resources/beta/threads/runs/runs';
1111
import * as AssistantsAPI from 'openai/resources/beta/assistants';
12+
import * as MessagesAPI from 'openai/resources/beta/threads/messages';
1213
import * as ThreadsAPI from 'openai/resources/beta/threads/threads';
1314
import * as StepsAPI from 'openai/resources/beta/threads/runs/steps';
1415
import { CursorPage, type CursorPageParams } from 'openai/pagination';
@@ -747,9 +748,9 @@ export interface RunCreateParamsBase {
747748
export namespace RunCreateParams {
748749
export interface AdditionalMessage {
749750
/**
750-
* The content of the message.
751+
* The text contents of the message.
751752
*/
752-
content: string;
753+
content: string | Array<MessagesAPI.MessageContentPartParam>;
753754

754755
/**
755756
* The role of the entity that is creating the message. Allowed values include:
@@ -999,9 +1000,9 @@ export interface RunCreateAndPollParams {
9991000
export namespace RunCreateAndPollParams {
10001001
export interface AdditionalMessage {
10011002
/**
1002-
* The content of the message.
1003+
* The text contents of the message.
10031004
*/
1004-
content: string;
1005+
content: string | Array<MessagesAPI.MessageContentPartParam>;
10051006

10061007
/**
10071008
* The role of the entity that is creating the message. Allowed values include:
@@ -1204,9 +1205,9 @@ export interface RunCreateAndStreamParams {
12041205
export namespace RunCreateAndStreamParams {
12051206
export interface AdditionalMessage {
12061207
/**
1207-
* The content of the message.
1208+
* The text contents of the message.
12081209
*/
1209-
content: string;
1210+
content: string | Array<MessagesAPI.MessageContentPartParam>;
12101211

12111212
/**
12121213
* The role of the entity that is creating the message. Allowed values include:
@@ -1409,9 +1410,9 @@ export interface RunStreamParams {
14091410
export namespace RunStreamParams {
14101411
export interface AdditionalMessage {
14111412
/**
1412-
* The content of the message.
1413+
* The text contents of the message.
14131414
*/
1414-
content: string;
1415+
content: string | Array<MessagesAPI.MessageContentPartParam>;
14151416

14161417
/**
14171418
* The role of the entity that is creating the message. Allowed values include:

src/resources/beta/threads/threads.ts

+14-8
Original file line numberDiff line numberDiff line change
@@ -284,9 +284,9 @@ export interface ThreadCreateParams {
284284
export namespace ThreadCreateParams {
285285
export interface Message {
286286
/**
287-
* The content of the message.
287+
* The text contents of the message.
288288
*/
289-
content: string;
289+
content: string | Array<MessagesAPI.MessageContentPartParam>;
290290

291291
/**
292292
* The role of the entity that is creating the message. Allowed values include:
@@ -623,9 +623,9 @@ export namespace ThreadCreateAndRunParams {
623623
export namespace Thread {
624624
export interface Message {
625625
/**
626-
* The content of the message.
626+
* The text contents of the message.
627627
*/
628-
content: string;
628+
content: string | Array<MessagesAPI.MessageContentPartParam>;
629629

630630
/**
631631
* The role of the entity that is creating the message. Allowed values include:
@@ -973,9 +973,9 @@ export namespace ThreadCreateAndRunPollParams {
973973
export namespace Thread {
974974
export interface Message {
975975
/**
976-
* The content of the message.
976+
* The text contents of the message.
977977
*/
978-
content: string;
978+
content: string | Array<MessagesAPI.MessageContentPartParam>;
979979

980980
/**
981981
* The role of the entity that is creating the message. Allowed values include:
@@ -1302,9 +1302,9 @@ export namespace ThreadCreateAndRunStreamParams {
13021302
export namespace Thread {
13031303
export interface Message {
13041304
/**
1305-
* The content of the message.
1305+
* The text contents of the message.
13061306
*/
1307-
content: string;
1307+
content: string | Array<MessagesAPI.MessageContentPartParam>;
13081308

13091309
/**
13101310
* The role of the entity that is creating the message. Allowed values include:
@@ -1503,14 +1503,20 @@ export namespace Threads {
15031503
export import ImageFileContentBlock = MessagesAPI.ImageFileContentBlock;
15041504
export import ImageFileDelta = MessagesAPI.ImageFileDelta;
15051505
export import ImageFileDeltaBlock = MessagesAPI.ImageFileDeltaBlock;
1506+
export import ImageURL = MessagesAPI.ImageURL;
1507+
export import ImageURLContentBlock = MessagesAPI.ImageURLContentBlock;
1508+
export import ImageURLDelta = MessagesAPI.ImageURLDelta;
1509+
export import ImageURLDeltaBlock = MessagesAPI.ImageURLDeltaBlock;
15061510
export import Message = MessagesAPI.Message;
15071511
export import MessageContent = MessagesAPI.MessageContent;
15081512
export import MessageContentDelta = MessagesAPI.MessageContentDelta;
1513+
export import MessageContentPartParam = MessagesAPI.MessageContentPartParam;
15091514
export import MessageDeleted = MessagesAPI.MessageDeleted;
15101515
export import MessageDelta = MessagesAPI.MessageDelta;
15111516
export import MessageDeltaEvent = MessagesAPI.MessageDeltaEvent;
15121517
export import Text = MessagesAPI.Text;
15131518
export import TextContentBlock = MessagesAPI.TextContentBlock;
1519+
export import TextContentBlockParam = MessagesAPI.TextContentBlockParam;
15141520
export import TextDelta = MessagesAPI.TextDelta;
15151521
export import TextDeltaBlock = MessagesAPI.TextDeltaBlock;
15161522
export import MessagesPage = MessagesAPI.MessagesPage;

0 commit comments

Comments
 (0)