Skip to content

Commit 4f38d4d

Browse files
committed
feat(api): add additional messages when creating thread run (#759)
1 parent 4999e9b commit 4f38d4d

File tree

2 files changed

+163
-0
lines changed

2 files changed

+163
-0
lines changed

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

Lines changed: 158 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -529,6 +529,11 @@ export interface RunCreateParamsBase {
529529
*/
530530
additional_instructions?: string | null;
531531

532+
/**
533+
* Adds additional messages to the thread before creating the run.
534+
*/
535+
additional_messages?: Array<RunCreateParams.AdditionalMessage> | null;
536+
532537
/**
533538
* Overrides the
534539
* [instructions](https://platform.openai.com/docs/api-reference/assistants/createAssistant)
@@ -574,6 +579,39 @@ export interface RunCreateParamsBase {
574579
}
575580

576581
export namespace RunCreateParams {
582+
export interface AdditionalMessage {
583+
/**
584+
* The content of the message.
585+
*/
586+
content: string;
587+
588+
/**
589+
* The role of the entity that is creating the message. Allowed values include:
590+
*
591+
* - `user`: Indicates the message is sent by an actual user and should be used in
592+
* most cases to represent user-generated messages.
593+
* - `assistant`: Indicates the message is generated by the assistant. Use this
594+
* value to insert messages from the assistant into the conversation.
595+
*/
596+
role: 'user' | 'assistant';
597+
598+
/**
599+
* A list of [File](https://platform.openai.com/docs/api-reference/files) IDs that
600+
* the message should use. There can be a maximum of 10 files attached to a
601+
* message. Useful for tools like `retrieval` and `code_interpreter` that can
602+
* access and use files.
603+
*/
604+
file_ids?: Array<string>;
605+
606+
/**
607+
* Set of 16 key-value pairs that can be attached to an object. This can be useful
608+
* for storing additional information about the object in a structured format. Keys
609+
* can be a maximum of 64 characters long and values can be a maxium of 512
610+
* characters long.
611+
*/
612+
metadata?: unknown | null;
613+
}
614+
577615
export type RunCreateParamsNonStreaming = RunsAPI.RunCreateParamsNonStreaming;
578616
export type RunCreateParamsStreaming = RunsAPI.RunCreateParamsStreaming;
579617
}
@@ -637,6 +675,11 @@ export interface RunCreateAndPollParams {
637675
*/
638676
additional_instructions?: string | null;
639677

678+
/**
679+
* Adds additional messages to the thread before creating the run.
680+
*/
681+
additional_messages?: Array<RunCreateAndPollParams.AdditionalMessage> | null;
682+
640683
/**
641684
* Overrides the
642685
* [instructions](https://platform.openai.com/docs/api-reference/assistants/createAssistant)
@@ -674,6 +717,41 @@ export interface RunCreateAndPollParams {
674717
tools?: Array<AssistantsAPI.AssistantTool> | null;
675718
}
676719

720+
export namespace RunCreateAndPollParams {
721+
export interface AdditionalMessage {
722+
/**
723+
* The content of the message.
724+
*/
725+
content: string;
726+
727+
/**
728+
* The role of the entity that is creating the message. Allowed values include:
729+
*
730+
* - `user`: Indicates the message is sent by an actual user and should be used in
731+
* most cases to represent user-generated messages.
732+
* - `assistant`: Indicates the message is generated by the assistant. Use this
733+
* value to insert messages from the assistant into the conversation.
734+
*/
735+
role: 'user' | 'assistant';
736+
737+
/**
738+
* A list of [File](https://platform.openai.com/docs/api-reference/files) IDs that
739+
* the message should use. There can be a maximum of 10 files attached to a
740+
* message. Useful for tools like `retrieval` and `code_interpreter` that can
741+
* access and use files.
742+
*/
743+
file_ids?: Array<string>;
744+
745+
/**
746+
* Set of 16 key-value pairs that can be attached to an object. This can be useful
747+
* for storing additional information about the object in a structured format. Keys
748+
* can be a maximum of 64 characters long and values can be a maxium of 512
749+
* characters long.
750+
*/
751+
metadata?: unknown | null;
752+
}
753+
}
754+
677755
export interface RunCreateAndStreamParams {
678756
/**
679757
* The ID of the
@@ -689,6 +767,11 @@ export interface RunCreateAndStreamParams {
689767
*/
690768
additional_instructions?: string | null;
691769

770+
/**
771+
* Adds additional messages to the thread before creating the run.
772+
*/
773+
additional_messages?: Array<RunCreateAndStreamParams.AdditionalMessage> | null;
774+
692775
/**
693776
* Overrides the
694777
* [instructions](https://platform.openai.com/docs/api-reference/assistants/createAssistant)
@@ -726,6 +809,41 @@ export interface RunCreateAndStreamParams {
726809
tools?: Array<AssistantsAPI.AssistantTool> | null;
727810
}
728811

812+
export namespace RunCreateAndStreamParams {
813+
export interface AdditionalMessage {
814+
/**
815+
* The content of the message.
816+
*/
817+
content: string;
818+
819+
/**
820+
* The role of the entity that is creating the message. Allowed values include:
821+
*
822+
* - `user`: Indicates the message is sent by an actual user and should be used in
823+
* most cases to represent user-generated messages.
824+
* - `assistant`: Indicates the message is generated by the assistant. Use this
825+
* value to insert messages from the assistant into the conversation.
826+
*/
827+
role: 'user' | 'assistant';
828+
829+
/**
830+
* A list of [File](https://platform.openai.com/docs/api-reference/files) IDs that
831+
* the message should use. There can be a maximum of 10 files attached to a
832+
* message. Useful for tools like `retrieval` and `code_interpreter` that can
833+
* access and use files.
834+
*/
835+
file_ids?: Array<string>;
836+
837+
/**
838+
* Set of 16 key-value pairs that can be attached to an object. This can be useful
839+
* for storing additional information about the object in a structured format. Keys
840+
* can be a maximum of 64 characters long and values can be a maxium of 512
841+
* characters long.
842+
*/
843+
metadata?: unknown | null;
844+
}
845+
}
846+
729847
export interface RunStreamParams {
730848
/**
731849
* The ID of the
@@ -741,6 +859,11 @@ export interface RunStreamParams {
741859
*/
742860
additional_instructions?: string | null;
743861

862+
/**
863+
* Adds additional messages to the thread before creating the run.
864+
*/
865+
additional_messages?: Array<RunStreamParams.AdditionalMessage> | null;
866+
744867
/**
745868
* Overrides the
746869
* [instructions](https://platform.openai.com/docs/api-reference/assistants/createAssistant)
@@ -778,6 +901,41 @@ export interface RunStreamParams {
778901
tools?: Array<AssistantsAPI.AssistantTool> | null;
779902
}
780903

904+
export namespace RunStreamParams {
905+
export interface AdditionalMessage {
906+
/**
907+
* The content of the message.
908+
*/
909+
content: string;
910+
911+
/**
912+
* The role of the entity that is creating the message. Allowed values include:
913+
*
914+
* - `user`: Indicates the message is sent by an actual user and should be used in
915+
* most cases to represent user-generated messages.
916+
* - `assistant`: Indicates the message is generated by the assistant. Use this
917+
* value to insert messages from the assistant into the conversation.
918+
*/
919+
role: 'user' | 'assistant';
920+
921+
/**
922+
* A list of [File](https://platform.openai.com/docs/api-reference/files) IDs that
923+
* the message should use. There can be a maximum of 10 files attached to a
924+
* message. Useful for tools like `retrieval` and `code_interpreter` that can
925+
* access and use files.
926+
*/
927+
file_ids?: Array<string>;
928+
929+
/**
930+
* Set of 16 key-value pairs that can be attached to an object. This can be useful
931+
* for storing additional information about the object in a structured format. Keys
932+
* can be a maximum of 64 characters long and values can be a maxium of 512
933+
* characters long.
934+
*/
935+
metadata?: unknown | null;
936+
}
937+
}
938+
781939
export type RunSubmitToolOutputsParams =
782940
| RunSubmitToolOutputsParamsNonStreaming
783941
| RunSubmitToolOutputsParamsStreaming;

tests/api-resources/beta/threads/runs/runs.test.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,11 @@ describe('resource runs', () => {
2424
const response = await openai.beta.threads.runs.create('string', {
2525
assistant_id: 'string',
2626
additional_instructions: 'string',
27+
additional_messages: [
28+
{ role: 'user', content: 'x', file_ids: ['string'], metadata: {} },
29+
{ role: 'user', content: 'x', file_ids: ['string'], metadata: {} },
30+
{ role: 'user', content: 'x', file_ids: ['string'], metadata: {} },
31+
],
2732
instructions: 'string',
2833
metadata: {},
2934
model: 'string',

0 commit comments

Comments
 (0)