Skip to content

Commit 70eb081

Browse files
feat(api): add additional messages when creating thread run (#1298)
1 parent 0bdc377 commit 70eb081

File tree

3 files changed

+157
-2
lines changed

3 files changed

+157
-2
lines changed

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

+42
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@ def create(
7575
*,
7676
assistant_id: str,
7777
additional_instructions: Optional[str] | NotGiven = NOT_GIVEN,
78+
additional_messages: Optional[Iterable[run_create_params.AdditionalMessage]] | NotGiven = NOT_GIVEN,
7879
instructions: Optional[str] | NotGiven = NOT_GIVEN,
7980
metadata: Optional[object] | NotGiven = NOT_GIVEN,
8081
model: Optional[str] | NotGiven = NOT_GIVEN,
@@ -100,6 +101,8 @@ def create(
100101
is useful for modifying the behavior on a per-run basis without overriding other
101102
instructions.
102103
104+
additional_messages: Adds additional messages to the thread before creating the run.
105+
103106
instructions: Overrides the
104107
[instructions](https://platform.openai.com/docs/api-reference/assistants/createAssistant)
105108
of the assistant. This is useful for modifying the behavior on a per-run basis.
@@ -143,6 +146,7 @@ def create(
143146
assistant_id: str,
144147
stream: Literal[True],
145148
additional_instructions: Optional[str] | NotGiven = NOT_GIVEN,
149+
additional_messages: Optional[Iterable[run_create_params.AdditionalMessage]] | NotGiven = NOT_GIVEN,
146150
instructions: Optional[str] | NotGiven = NOT_GIVEN,
147151
metadata: Optional[object] | NotGiven = NOT_GIVEN,
148152
model: Optional[str] | NotGiven = NOT_GIVEN,
@@ -171,6 +175,8 @@ def create(
171175
is useful for modifying the behavior on a per-run basis without overriding other
172176
instructions.
173177
178+
additional_messages: Adds additional messages to the thread before creating the run.
179+
174180
instructions: Overrides the
175181
[instructions](https://platform.openai.com/docs/api-reference/assistants/createAssistant)
176182
of the assistant. This is useful for modifying the behavior on a per-run basis.
@@ -210,6 +216,7 @@ def create(
210216
assistant_id: str,
211217
stream: bool,
212218
additional_instructions: Optional[str] | NotGiven = NOT_GIVEN,
219+
additional_messages: Optional[Iterable[run_create_params.AdditionalMessage]] | NotGiven = NOT_GIVEN,
213220
instructions: Optional[str] | NotGiven = NOT_GIVEN,
214221
metadata: Optional[object] | NotGiven = NOT_GIVEN,
215222
model: Optional[str] | NotGiven = NOT_GIVEN,
@@ -238,6 +245,8 @@ def create(
238245
is useful for modifying the behavior on a per-run basis without overriding other
239246
instructions.
240247
248+
additional_messages: Adds additional messages to the thread before creating the run.
249+
241250
instructions: Overrides the
242251
[instructions](https://platform.openai.com/docs/api-reference/assistants/createAssistant)
243252
of the assistant. This is useful for modifying the behavior on a per-run basis.
@@ -276,6 +285,7 @@ def create(
276285
*,
277286
assistant_id: str,
278287
additional_instructions: Optional[str] | NotGiven = NOT_GIVEN,
288+
additional_messages: Optional[Iterable[run_create_params.AdditionalMessage]] | NotGiven = NOT_GIVEN,
279289
instructions: Optional[str] | NotGiven = NOT_GIVEN,
280290
metadata: Optional[object] | NotGiven = NOT_GIVEN,
281291
model: Optional[str] | NotGiven = NOT_GIVEN,
@@ -298,6 +308,7 @@ def create(
298308
{
299309
"assistant_id": assistant_id,
300310
"additional_instructions": additional_instructions,
311+
"additional_messages": additional_messages,
301312
"instructions": instructions,
302313
"metadata": metadata,
303314
"model": model,
@@ -505,6 +516,7 @@ def create_and_poll(
505516
*,
506517
assistant_id: str,
507518
additional_instructions: Optional[str] | NotGiven = NOT_GIVEN,
519+
additional_messages: Optional[Iterable[run_create_params.AdditionalMessage]] | NotGiven = NOT_GIVEN,
508520
instructions: Optional[str] | NotGiven = NOT_GIVEN,
509521
metadata: Optional[object] | NotGiven = NOT_GIVEN,
510522
model: Optional[str] | NotGiven = NOT_GIVEN,
@@ -528,6 +540,7 @@ def create_and_poll(
528540
thread_id=thread_id,
529541
assistant_id=assistant_id,
530542
additional_instructions=additional_instructions,
543+
additional_messages=additional_messages,
531544
instructions=instructions,
532545
metadata=metadata,
533546
model=model,
@@ -557,6 +570,7 @@ def create_and_stream(
557570
*,
558571
assistant_id: str,
559572
additional_instructions: Optional[str] | NotGiven = NOT_GIVEN,
573+
additional_messages: Optional[Iterable[run_create_params.AdditionalMessage]] | NotGiven = NOT_GIVEN,
560574
instructions: Optional[str] | NotGiven = NOT_GIVEN,
561575
metadata: Optional[object] | NotGiven = NOT_GIVEN,
562576
model: Optional[str] | NotGiven = NOT_GIVEN,
@@ -580,6 +594,7 @@ def create_and_stream(
580594
*,
581595
assistant_id: str,
582596
additional_instructions: Optional[str] | NotGiven = NOT_GIVEN,
597+
additional_messages: Optional[Iterable[run_create_params.AdditionalMessage]] | NotGiven = NOT_GIVEN,
583598
instructions: Optional[str] | NotGiven = NOT_GIVEN,
584599
metadata: Optional[object] | NotGiven = NOT_GIVEN,
585600
model: Optional[str] | NotGiven = NOT_GIVEN,
@@ -603,6 +618,7 @@ def create_and_stream(
603618
*,
604619
assistant_id: str,
605620
additional_instructions: Optional[str] | NotGiven = NOT_GIVEN,
621+
additional_messages: Optional[Iterable[run_create_params.AdditionalMessage]] | NotGiven = NOT_GIVEN,
606622
instructions: Optional[str] | NotGiven = NOT_GIVEN,
607623
metadata: Optional[object] | NotGiven = NOT_GIVEN,
608624
model: Optional[str] | NotGiven = NOT_GIVEN,
@@ -634,6 +650,7 @@ def create_and_stream(
634650
{
635651
"assistant_id": assistant_id,
636652
"additional_instructions": additional_instructions,
653+
"additional_messages": additional_messages,
637654
"instructions": instructions,
638655
"metadata": metadata,
639656
"model": model,
@@ -703,6 +720,7 @@ def stream(
703720
*,
704721
assistant_id: str,
705722
additional_instructions: Optional[str] | NotGiven = NOT_GIVEN,
723+
additional_messages: Optional[Iterable[run_create_params.AdditionalMessage]] | NotGiven = NOT_GIVEN,
706724
instructions: Optional[str] | NotGiven = NOT_GIVEN,
707725
metadata: Optional[object] | NotGiven = NOT_GIVEN,
708726
model: Optional[str] | NotGiven = NOT_GIVEN,
@@ -725,6 +743,7 @@ def stream(
725743
*,
726744
assistant_id: str,
727745
additional_instructions: Optional[str] | NotGiven = NOT_GIVEN,
746+
additional_messages: Optional[Iterable[run_create_params.AdditionalMessage]] | NotGiven = NOT_GIVEN,
728747
instructions: Optional[str] | NotGiven = NOT_GIVEN,
729748
metadata: Optional[object] | NotGiven = NOT_GIVEN,
730749
model: Optional[str] | NotGiven = NOT_GIVEN,
@@ -747,6 +766,7 @@ def stream(
747766
*,
748767
assistant_id: str,
749768
additional_instructions: Optional[str] | NotGiven = NOT_GIVEN,
769+
additional_messages: Optional[Iterable[run_create_params.AdditionalMessage]] | NotGiven = NOT_GIVEN,
750770
instructions: Optional[str] | NotGiven = NOT_GIVEN,
751771
metadata: Optional[object] | NotGiven = NOT_GIVEN,
752772
model: Optional[str] | NotGiven = NOT_GIVEN,
@@ -778,6 +798,7 @@ def stream(
778798
{
779799
"assistant_id": assistant_id,
780800
"additional_instructions": additional_instructions,
801+
"additional_messages": additional_messages,
781802
"instructions": instructions,
782803
"metadata": metadata,
783804
"model": model,
@@ -1100,6 +1121,7 @@ async def create(
11001121
*,
11011122
assistant_id: str,
11021123
additional_instructions: Optional[str] | NotGiven = NOT_GIVEN,
1124+
additional_messages: Optional[Iterable[run_create_params.AdditionalMessage]] | NotGiven = NOT_GIVEN,
11031125
instructions: Optional[str] | NotGiven = NOT_GIVEN,
11041126
metadata: Optional[object] | NotGiven = NOT_GIVEN,
11051127
model: Optional[str] | NotGiven = NOT_GIVEN,
@@ -1125,6 +1147,8 @@ async def create(
11251147
is useful for modifying the behavior on a per-run basis without overriding other
11261148
instructions.
11271149
1150+
additional_messages: Adds additional messages to the thread before creating the run.
1151+
11281152
instructions: Overrides the
11291153
[instructions](https://platform.openai.com/docs/api-reference/assistants/createAssistant)
11301154
of the assistant. This is useful for modifying the behavior on a per-run basis.
@@ -1168,6 +1192,7 @@ async def create(
11681192
assistant_id: str,
11691193
stream: Literal[True],
11701194
additional_instructions: Optional[str] | NotGiven = NOT_GIVEN,
1195+
additional_messages: Optional[Iterable[run_create_params.AdditionalMessage]] | NotGiven = NOT_GIVEN,
11711196
instructions: Optional[str] | NotGiven = NOT_GIVEN,
11721197
metadata: Optional[object] | NotGiven = NOT_GIVEN,
11731198
model: Optional[str] | NotGiven = NOT_GIVEN,
@@ -1196,6 +1221,8 @@ async def create(
11961221
is useful for modifying the behavior on a per-run basis without overriding other
11971222
instructions.
11981223
1224+
additional_messages: Adds additional messages to the thread before creating the run.
1225+
11991226
instructions: Overrides the
12001227
[instructions](https://platform.openai.com/docs/api-reference/assistants/createAssistant)
12011228
of the assistant. This is useful for modifying the behavior on a per-run basis.
@@ -1235,6 +1262,7 @@ async def create(
12351262
assistant_id: str,
12361263
stream: bool,
12371264
additional_instructions: Optional[str] | NotGiven = NOT_GIVEN,
1265+
additional_messages: Optional[Iterable[run_create_params.AdditionalMessage]] | NotGiven = NOT_GIVEN,
12381266
instructions: Optional[str] | NotGiven = NOT_GIVEN,
12391267
metadata: Optional[object] | NotGiven = NOT_GIVEN,
12401268
model: Optional[str] | NotGiven = NOT_GIVEN,
@@ -1263,6 +1291,8 @@ async def create(
12631291
is useful for modifying the behavior on a per-run basis without overriding other
12641292
instructions.
12651293
1294+
additional_messages: Adds additional messages to the thread before creating the run.
1295+
12661296
instructions: Overrides the
12671297
[instructions](https://platform.openai.com/docs/api-reference/assistants/createAssistant)
12681298
of the assistant. This is useful for modifying the behavior on a per-run basis.
@@ -1301,6 +1331,7 @@ async def create(
13011331
*,
13021332
assistant_id: str,
13031333
additional_instructions: Optional[str] | NotGiven = NOT_GIVEN,
1334+
additional_messages: Optional[Iterable[run_create_params.AdditionalMessage]] | NotGiven = NOT_GIVEN,
13041335
instructions: Optional[str] | NotGiven = NOT_GIVEN,
13051336
metadata: Optional[object] | NotGiven = NOT_GIVEN,
13061337
model: Optional[str] | NotGiven = NOT_GIVEN,
@@ -1323,6 +1354,7 @@ async def create(
13231354
{
13241355
"assistant_id": assistant_id,
13251356
"additional_instructions": additional_instructions,
1357+
"additional_messages": additional_messages,
13261358
"instructions": instructions,
13271359
"metadata": metadata,
13281360
"model": model,
@@ -1530,6 +1562,7 @@ async def create_and_poll(
15301562
*,
15311563
assistant_id: str,
15321564
additional_instructions: Optional[str] | NotGiven = NOT_GIVEN,
1565+
additional_messages: Optional[Iterable[run_create_params.AdditionalMessage]] | NotGiven = NOT_GIVEN,
15331566
instructions: Optional[str] | NotGiven = NOT_GIVEN,
15341567
metadata: Optional[object] | NotGiven = NOT_GIVEN,
15351568
model: Optional[str] | NotGiven = NOT_GIVEN,
@@ -1553,6 +1586,7 @@ async def create_and_poll(
15531586
thread_id=thread_id,
15541587
assistant_id=assistant_id,
15551588
additional_instructions=additional_instructions,
1589+
additional_messages=additional_messages,
15561590
instructions=instructions,
15571591
metadata=metadata,
15581592
model=model,
@@ -1582,6 +1616,7 @@ def create_and_stream(
15821616
*,
15831617
assistant_id: str,
15841618
additional_instructions: Optional[str] | NotGiven = NOT_GIVEN,
1619+
additional_messages: Optional[Iterable[run_create_params.AdditionalMessage]] | NotGiven = NOT_GIVEN,
15851620
instructions: Optional[str] | NotGiven = NOT_GIVEN,
15861621
metadata: Optional[object] | NotGiven = NOT_GIVEN,
15871622
model: Optional[str] | NotGiven = NOT_GIVEN,
@@ -1605,6 +1640,7 @@ def create_and_stream(
16051640
*,
16061641
assistant_id: str,
16071642
additional_instructions: Optional[str] | NotGiven = NOT_GIVEN,
1643+
additional_messages: Optional[Iterable[run_create_params.AdditionalMessage]] | NotGiven = NOT_GIVEN,
16081644
instructions: Optional[str] | NotGiven = NOT_GIVEN,
16091645
metadata: Optional[object] | NotGiven = NOT_GIVEN,
16101646
model: Optional[str] | NotGiven = NOT_GIVEN,
@@ -1628,6 +1664,7 @@ def create_and_stream(
16281664
*,
16291665
assistant_id: str,
16301666
additional_instructions: Optional[str] | NotGiven = NOT_GIVEN,
1667+
additional_messages: Optional[Iterable[run_create_params.AdditionalMessage]] | NotGiven = NOT_GIVEN,
16311668
instructions: Optional[str] | NotGiven = NOT_GIVEN,
16321669
metadata: Optional[object] | NotGiven = NOT_GIVEN,
16331670
model: Optional[str] | NotGiven = NOT_GIVEN,
@@ -1661,6 +1698,7 @@ def create_and_stream(
16611698
{
16621699
"assistant_id": assistant_id,
16631700
"additional_instructions": additional_instructions,
1701+
"additional_messages": additional_messages,
16641702
"instructions": instructions,
16651703
"metadata": metadata,
16661704
"model": model,
@@ -1730,6 +1768,7 @@ def stream(
17301768
*,
17311769
assistant_id: str,
17321770
additional_instructions: Optional[str] | NotGiven = NOT_GIVEN,
1771+
additional_messages: Optional[Iterable[run_create_params.AdditionalMessage]] | NotGiven = NOT_GIVEN,
17331772
instructions: Optional[str] | NotGiven = NOT_GIVEN,
17341773
metadata: Optional[object] | NotGiven = NOT_GIVEN,
17351774
model: Optional[str] | NotGiven = NOT_GIVEN,
@@ -1752,6 +1791,7 @@ def stream(
17521791
*,
17531792
assistant_id: str,
17541793
additional_instructions: Optional[str] | NotGiven = NOT_GIVEN,
1794+
additional_messages: Optional[Iterable[run_create_params.AdditionalMessage]] | NotGiven = NOT_GIVEN,
17551795
instructions: Optional[str] | NotGiven = NOT_GIVEN,
17561796
metadata: Optional[object] | NotGiven = NOT_GIVEN,
17571797
model: Optional[str] | NotGiven = NOT_GIVEN,
@@ -1774,6 +1814,7 @@ def stream(
17741814
*,
17751815
assistant_id: str,
17761816
additional_instructions: Optional[str] | NotGiven = NOT_GIVEN,
1817+
additional_messages: Optional[Iterable[run_create_params.AdditionalMessage]] | NotGiven = NOT_GIVEN,
17771818
instructions: Optional[str] | NotGiven = NOT_GIVEN,
17781819
metadata: Optional[object] | NotGiven = NOT_GIVEN,
17791820
model: Optional[str] | NotGiven = NOT_GIVEN,
@@ -1807,6 +1848,7 @@ def stream(
18071848
{
18081849
"assistant_id": assistant_id,
18091850
"additional_instructions": additional_instructions,
1851+
"additional_messages": additional_messages,
18101852
"instructions": instructions,
18111853
"metadata": metadata,
18121854
"model": model,

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

+35-2
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,12 @@
22

33
from __future__ import annotations
44

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

88
from ..assistant_tool_param import AssistantToolParam
99

10-
__all__ = ["RunCreateParamsBase", "RunCreateParamsNonStreaming", "RunCreateParamsStreaming"]
10+
__all__ = ["RunCreateParamsBase", "AdditionalMessage", "RunCreateParamsNonStreaming", "RunCreateParamsStreaming"]
1111

1212

1313
class RunCreateParamsBase(TypedDict, total=False):
@@ -25,6 +25,9 @@ class RunCreateParamsBase(TypedDict, total=False):
2525
other instructions.
2626
"""
2727

28+
additional_messages: Optional[Iterable[AdditionalMessage]]
29+
"""Adds additional messages to the thread before creating the run."""
30+
2831
instructions: Optional[str]
2932
"""
3033
Overrides the
@@ -62,6 +65,36 @@ class RunCreateParamsBase(TypedDict, total=False):
6265
"""
6366

6467

68+
class AdditionalMessage(TypedDict, total=False):
69+
content: Required[str]
70+
"""The content of the message."""
71+
72+
role: Required[Literal["user", "assistant"]]
73+
"""The role of the entity that is creating the message. Allowed values include:
74+
75+
- `user`: Indicates the message is sent by an actual user and should be used in
76+
most cases to represent user-generated messages.
77+
- `assistant`: Indicates the message is generated by the assistant. Use this
78+
value to insert messages from the assistant into the conversation.
79+
"""
80+
81+
file_ids: List[str]
82+
"""
83+
A list of [File](https://platform.openai.com/docs/api-reference/files) IDs that
84+
the message should use. There can be a maximum of 10 files attached to a
85+
message. Useful for tools like `retrieval` and `code_interpreter` that can
86+
access and use files.
87+
"""
88+
89+
metadata: Optional[object]
90+
"""Set of 16 key-value pairs that can be attached to an object.
91+
92+
This can be useful for storing additional information about the object in a
93+
structured format. Keys can be a maximum of 64 characters long and values can be
94+
a maxium of 512 characters long.
95+
"""
96+
97+
6598
class RunCreateParamsNonStreaming(RunCreateParamsBase):
6699
stream: Optional[Literal[False]]
67100
"""

0 commit comments

Comments
 (0)