Commit e2d65bf7

Stainless Bot <107565488+stainless-bot@users.noreply.github.com>
2024-04-05 20:36:56
feat(api): add additional messages when creating thread run (#1298)
1 parent 0bdc377
Changed files (3)
src
openai
resources
beta
threads
runs
types
tests
api_resources
beta
threads
src/openai/resources/beta/threads/runs/runs.py
@@ -75,6 +75,7 @@ class Runs(SyncAPIResource):
         *,
         assistant_id: str,
         additional_instructions: Optional[str] | NotGiven = NOT_GIVEN,
+        additional_messages: Optional[Iterable[run_create_params.AdditionalMessage]] | NotGiven = NOT_GIVEN,
         instructions: Optional[str] | NotGiven = NOT_GIVEN,
         metadata: Optional[object] | NotGiven = NOT_GIVEN,
         model: Optional[str] | NotGiven = NOT_GIVEN,
@@ -100,6 +101,8 @@ class Runs(SyncAPIResource):
               is useful for modifying the behavior on a per-run basis without overriding other
               instructions.
 
+          additional_messages: Adds additional messages to the thread before creating the run.
+
           instructions: Overrides the
               [instructions](https://platform.openai.com/docs/api-reference/assistants/createAssistant)
               of the assistant. This is useful for modifying the behavior on a per-run basis.
@@ -143,6 +146,7 @@ class Runs(SyncAPIResource):
         assistant_id: str,
         stream: Literal[True],
         additional_instructions: Optional[str] | NotGiven = NOT_GIVEN,
+        additional_messages: Optional[Iterable[run_create_params.AdditionalMessage]] | NotGiven = NOT_GIVEN,
         instructions: Optional[str] | NotGiven = NOT_GIVEN,
         metadata: Optional[object] | NotGiven = NOT_GIVEN,
         model: Optional[str] | NotGiven = NOT_GIVEN,
@@ -171,6 +175,8 @@ class Runs(SyncAPIResource):
               is useful for modifying the behavior on a per-run basis without overriding other
               instructions.
 
+          additional_messages: Adds additional messages to the thread before creating the run.
+
           instructions: Overrides the
               [instructions](https://platform.openai.com/docs/api-reference/assistants/createAssistant)
               of the assistant. This is useful for modifying the behavior on a per-run basis.
@@ -210,6 +216,7 @@ class Runs(SyncAPIResource):
         assistant_id: str,
         stream: bool,
         additional_instructions: Optional[str] | NotGiven = NOT_GIVEN,
+        additional_messages: Optional[Iterable[run_create_params.AdditionalMessage]] | NotGiven = NOT_GIVEN,
         instructions: Optional[str] | NotGiven = NOT_GIVEN,
         metadata: Optional[object] | NotGiven = NOT_GIVEN,
         model: Optional[str] | NotGiven = NOT_GIVEN,
@@ -238,6 +245,8 @@ class Runs(SyncAPIResource):
               is useful for modifying the behavior on a per-run basis without overriding other
               instructions.
 
+          additional_messages: Adds additional messages to the thread before creating the run.
+
           instructions: Overrides the
               [instructions](https://platform.openai.com/docs/api-reference/assistants/createAssistant)
               of the assistant. This is useful for modifying the behavior on a per-run basis.
@@ -276,6 +285,7 @@ class Runs(SyncAPIResource):
         *,
         assistant_id: str,
         additional_instructions: Optional[str] | NotGiven = NOT_GIVEN,
+        additional_messages: Optional[Iterable[run_create_params.AdditionalMessage]] | NotGiven = NOT_GIVEN,
         instructions: Optional[str] | NotGiven = NOT_GIVEN,
         metadata: Optional[object] | NotGiven = NOT_GIVEN,
         model: Optional[str] | NotGiven = NOT_GIVEN,
@@ -298,6 +308,7 @@ class Runs(SyncAPIResource):
                 {
                     "assistant_id": assistant_id,
                     "additional_instructions": additional_instructions,
+                    "additional_messages": additional_messages,
                     "instructions": instructions,
                     "metadata": metadata,
                     "model": model,
@@ -505,6 +516,7 @@ class Runs(SyncAPIResource):
         *,
         assistant_id: str,
         additional_instructions: Optional[str] | NotGiven = NOT_GIVEN,
+        additional_messages: Optional[Iterable[run_create_params.AdditionalMessage]] | NotGiven = NOT_GIVEN,
         instructions: Optional[str] | NotGiven = NOT_GIVEN,
         metadata: Optional[object] | NotGiven = NOT_GIVEN,
         model: Optional[str] | NotGiven = NOT_GIVEN,
@@ -528,6 +540,7 @@ class Runs(SyncAPIResource):
             thread_id=thread_id,
             assistant_id=assistant_id,
             additional_instructions=additional_instructions,
+            additional_messages=additional_messages,
             instructions=instructions,
             metadata=metadata,
             model=model,
@@ -557,6 +570,7 @@ class Runs(SyncAPIResource):
         *,
         assistant_id: str,
         additional_instructions: Optional[str] | NotGiven = NOT_GIVEN,
+        additional_messages: Optional[Iterable[run_create_params.AdditionalMessage]] | NotGiven = NOT_GIVEN,
         instructions: Optional[str] | NotGiven = NOT_GIVEN,
         metadata: Optional[object] | NotGiven = NOT_GIVEN,
         model: Optional[str] | NotGiven = NOT_GIVEN,
@@ -580,6 +594,7 @@ class Runs(SyncAPIResource):
         *,
         assistant_id: str,
         additional_instructions: Optional[str] | NotGiven = NOT_GIVEN,
+        additional_messages: Optional[Iterable[run_create_params.AdditionalMessage]] | NotGiven = NOT_GIVEN,
         instructions: Optional[str] | NotGiven = NOT_GIVEN,
         metadata: Optional[object] | NotGiven = NOT_GIVEN,
         model: Optional[str] | NotGiven = NOT_GIVEN,
@@ -603,6 +618,7 @@ class Runs(SyncAPIResource):
         *,
         assistant_id: str,
         additional_instructions: Optional[str] | NotGiven = NOT_GIVEN,
+        additional_messages: Optional[Iterable[run_create_params.AdditionalMessage]] | NotGiven = NOT_GIVEN,
         instructions: Optional[str] | NotGiven = NOT_GIVEN,
         metadata: Optional[object] | NotGiven = NOT_GIVEN,
         model: Optional[str] | NotGiven = NOT_GIVEN,
@@ -634,6 +650,7 @@ class Runs(SyncAPIResource):
                 {
                     "assistant_id": assistant_id,
                     "additional_instructions": additional_instructions,
+                    "additional_messages": additional_messages,
                     "instructions": instructions,
                     "metadata": metadata,
                     "model": model,
@@ -703,6 +720,7 @@ class Runs(SyncAPIResource):
         *,
         assistant_id: str,
         additional_instructions: Optional[str] | NotGiven = NOT_GIVEN,
+        additional_messages: Optional[Iterable[run_create_params.AdditionalMessage]] | NotGiven = NOT_GIVEN,
         instructions: Optional[str] | NotGiven = NOT_GIVEN,
         metadata: Optional[object] | NotGiven = NOT_GIVEN,
         model: Optional[str] | NotGiven = NOT_GIVEN,
@@ -725,6 +743,7 @@ class Runs(SyncAPIResource):
         *,
         assistant_id: str,
         additional_instructions: Optional[str] | NotGiven = NOT_GIVEN,
+        additional_messages: Optional[Iterable[run_create_params.AdditionalMessage]] | NotGiven = NOT_GIVEN,
         instructions: Optional[str] | NotGiven = NOT_GIVEN,
         metadata: Optional[object] | NotGiven = NOT_GIVEN,
         model: Optional[str] | NotGiven = NOT_GIVEN,
@@ -747,6 +766,7 @@ class Runs(SyncAPIResource):
         *,
         assistant_id: str,
         additional_instructions: Optional[str] | NotGiven = NOT_GIVEN,
+        additional_messages: Optional[Iterable[run_create_params.AdditionalMessage]] | NotGiven = NOT_GIVEN,
         instructions: Optional[str] | NotGiven = NOT_GIVEN,
         metadata: Optional[object] | NotGiven = NOT_GIVEN,
         model: Optional[str] | NotGiven = NOT_GIVEN,
@@ -778,6 +798,7 @@ class Runs(SyncAPIResource):
                 {
                     "assistant_id": assistant_id,
                     "additional_instructions": additional_instructions,
+                    "additional_messages": additional_messages,
                     "instructions": instructions,
                     "metadata": metadata,
                     "model": model,
@@ -1100,6 +1121,7 @@ class AsyncRuns(AsyncAPIResource):
         *,
         assistant_id: str,
         additional_instructions: Optional[str] | NotGiven = NOT_GIVEN,
+        additional_messages: Optional[Iterable[run_create_params.AdditionalMessage]] | NotGiven = NOT_GIVEN,
         instructions: Optional[str] | NotGiven = NOT_GIVEN,
         metadata: Optional[object] | NotGiven = NOT_GIVEN,
         model: Optional[str] | NotGiven = NOT_GIVEN,
@@ -1125,6 +1147,8 @@ class AsyncRuns(AsyncAPIResource):
               is useful for modifying the behavior on a per-run basis without overriding other
               instructions.
 
+          additional_messages: Adds additional messages to the thread before creating the run.
+
           instructions: Overrides the
               [instructions](https://platform.openai.com/docs/api-reference/assistants/createAssistant)
               of the assistant. This is useful for modifying the behavior on a per-run basis.
@@ -1168,6 +1192,7 @@ class AsyncRuns(AsyncAPIResource):
         assistant_id: str,
         stream: Literal[True],
         additional_instructions: Optional[str] | NotGiven = NOT_GIVEN,
+        additional_messages: Optional[Iterable[run_create_params.AdditionalMessage]] | NotGiven = NOT_GIVEN,
         instructions: Optional[str] | NotGiven = NOT_GIVEN,
         metadata: Optional[object] | NotGiven = NOT_GIVEN,
         model: Optional[str] | NotGiven = NOT_GIVEN,
@@ -1196,6 +1221,8 @@ class AsyncRuns(AsyncAPIResource):
               is useful for modifying the behavior on a per-run basis without overriding other
               instructions.
 
+          additional_messages: Adds additional messages to the thread before creating the run.
+
           instructions: Overrides the
               [instructions](https://platform.openai.com/docs/api-reference/assistants/createAssistant)
               of the assistant. This is useful for modifying the behavior on a per-run basis.
@@ -1235,6 +1262,7 @@ class AsyncRuns(AsyncAPIResource):
         assistant_id: str,
         stream: bool,
         additional_instructions: Optional[str] | NotGiven = NOT_GIVEN,
+        additional_messages: Optional[Iterable[run_create_params.AdditionalMessage]] | NotGiven = NOT_GIVEN,
         instructions: Optional[str] | NotGiven = NOT_GIVEN,
         metadata: Optional[object] | NotGiven = NOT_GIVEN,
         model: Optional[str] | NotGiven = NOT_GIVEN,
@@ -1263,6 +1291,8 @@ class AsyncRuns(AsyncAPIResource):
               is useful for modifying the behavior on a per-run basis without overriding other
               instructions.
 
+          additional_messages: Adds additional messages to the thread before creating the run.
+
           instructions: Overrides the
               [instructions](https://platform.openai.com/docs/api-reference/assistants/createAssistant)
               of the assistant. This is useful for modifying the behavior on a per-run basis.
@@ -1301,6 +1331,7 @@ class AsyncRuns(AsyncAPIResource):
         *,
         assistant_id: str,
         additional_instructions: Optional[str] | NotGiven = NOT_GIVEN,
+        additional_messages: Optional[Iterable[run_create_params.AdditionalMessage]] | NotGiven = NOT_GIVEN,
         instructions: Optional[str] | NotGiven = NOT_GIVEN,
         metadata: Optional[object] | NotGiven = NOT_GIVEN,
         model: Optional[str] | NotGiven = NOT_GIVEN,
@@ -1323,6 +1354,7 @@ class AsyncRuns(AsyncAPIResource):
                 {
                     "assistant_id": assistant_id,
                     "additional_instructions": additional_instructions,
+                    "additional_messages": additional_messages,
                     "instructions": instructions,
                     "metadata": metadata,
                     "model": model,
@@ -1530,6 +1562,7 @@ class AsyncRuns(AsyncAPIResource):
         *,
         assistant_id: str,
         additional_instructions: Optional[str] | NotGiven = NOT_GIVEN,
+        additional_messages: Optional[Iterable[run_create_params.AdditionalMessage]] | NotGiven = NOT_GIVEN,
         instructions: Optional[str] | NotGiven = NOT_GIVEN,
         metadata: Optional[object] | NotGiven = NOT_GIVEN,
         model: Optional[str] | NotGiven = NOT_GIVEN,
@@ -1553,6 +1586,7 @@ class AsyncRuns(AsyncAPIResource):
             thread_id=thread_id,
             assistant_id=assistant_id,
             additional_instructions=additional_instructions,
+            additional_messages=additional_messages,
             instructions=instructions,
             metadata=metadata,
             model=model,
@@ -1582,6 +1616,7 @@ class AsyncRuns(AsyncAPIResource):
         *,
         assistant_id: str,
         additional_instructions: Optional[str] | NotGiven = NOT_GIVEN,
+        additional_messages: Optional[Iterable[run_create_params.AdditionalMessage]] | NotGiven = NOT_GIVEN,
         instructions: Optional[str] | NotGiven = NOT_GIVEN,
         metadata: Optional[object] | NotGiven = NOT_GIVEN,
         model: Optional[str] | NotGiven = NOT_GIVEN,
@@ -1605,6 +1640,7 @@ class AsyncRuns(AsyncAPIResource):
         *,
         assistant_id: str,
         additional_instructions: Optional[str] | NotGiven = NOT_GIVEN,
+        additional_messages: Optional[Iterable[run_create_params.AdditionalMessage]] | NotGiven = NOT_GIVEN,
         instructions: Optional[str] | NotGiven = NOT_GIVEN,
         metadata: Optional[object] | NotGiven = NOT_GIVEN,
         model: Optional[str] | NotGiven = NOT_GIVEN,
@@ -1628,6 +1664,7 @@ class AsyncRuns(AsyncAPIResource):
         *,
         assistant_id: str,
         additional_instructions: Optional[str] | NotGiven = NOT_GIVEN,
+        additional_messages: Optional[Iterable[run_create_params.AdditionalMessage]] | NotGiven = NOT_GIVEN,
         instructions: Optional[str] | NotGiven = NOT_GIVEN,
         metadata: Optional[object] | NotGiven = NOT_GIVEN,
         model: Optional[str] | NotGiven = NOT_GIVEN,
@@ -1661,6 +1698,7 @@ class AsyncRuns(AsyncAPIResource):
                 {
                     "assistant_id": assistant_id,
                     "additional_instructions": additional_instructions,
+                    "additional_messages": additional_messages,
                     "instructions": instructions,
                     "metadata": metadata,
                     "model": model,
@@ -1730,6 +1768,7 @@ class AsyncRuns(AsyncAPIResource):
         *,
         assistant_id: str,
         additional_instructions: Optional[str] | NotGiven = NOT_GIVEN,
+        additional_messages: Optional[Iterable[run_create_params.AdditionalMessage]] | NotGiven = NOT_GIVEN,
         instructions: Optional[str] | NotGiven = NOT_GIVEN,
         metadata: Optional[object] | NotGiven = NOT_GIVEN,
         model: Optional[str] | NotGiven = NOT_GIVEN,
@@ -1752,6 +1791,7 @@ class AsyncRuns(AsyncAPIResource):
         *,
         assistant_id: str,
         additional_instructions: Optional[str] | NotGiven = NOT_GIVEN,
+        additional_messages: Optional[Iterable[run_create_params.AdditionalMessage]] | NotGiven = NOT_GIVEN,
         instructions: Optional[str] | NotGiven = NOT_GIVEN,
         metadata: Optional[object] | NotGiven = NOT_GIVEN,
         model: Optional[str] | NotGiven = NOT_GIVEN,
@@ -1774,6 +1814,7 @@ class AsyncRuns(AsyncAPIResource):
         *,
         assistant_id: str,
         additional_instructions: Optional[str] | NotGiven = NOT_GIVEN,
+        additional_messages: Optional[Iterable[run_create_params.AdditionalMessage]] | NotGiven = NOT_GIVEN,
         instructions: Optional[str] | NotGiven = NOT_GIVEN,
         metadata: Optional[object] | NotGiven = NOT_GIVEN,
         model: Optional[str] | NotGiven = NOT_GIVEN,
@@ -1807,6 +1848,7 @@ class AsyncRuns(AsyncAPIResource):
                 {
                     "assistant_id": assistant_id,
                     "additional_instructions": additional_instructions,
+                    "additional_messages": additional_messages,
                     "instructions": instructions,
                     "metadata": metadata,
                     "model": model,
src/openai/types/beta/threads/run_create_params.py
@@ -2,12 +2,12 @@
 
 from __future__ import annotations
 
-from typing import Union, Iterable, Optional
+from typing import List, Union, Iterable, Optional
 from typing_extensions import Literal, Required, TypedDict
 
 from ..assistant_tool_param import AssistantToolParam
 
-__all__ = ["RunCreateParamsBase", "RunCreateParamsNonStreaming", "RunCreateParamsStreaming"]
+__all__ = ["RunCreateParamsBase", "AdditionalMessage", "RunCreateParamsNonStreaming", "RunCreateParamsStreaming"]
 
 
 class RunCreateParamsBase(TypedDict, total=False):
@@ -25,6 +25,9 @@ class RunCreateParamsBase(TypedDict, total=False):
     other instructions.
     """
 
+    additional_messages: Optional[Iterable[AdditionalMessage]]
+    """Adds additional messages to the thread before creating the run."""
+
     instructions: Optional[str]
     """
     Overrides the
@@ -62,6 +65,36 @@ class RunCreateParamsBase(TypedDict, total=False):
     """
 
 
+class AdditionalMessage(TypedDict, total=False):
+    content: Required[str]
+    """The content of the message."""
+
+    role: Required[Literal["user", "assistant"]]
+    """The role of the entity that is creating the message. Allowed values include:
+
+    - `user`: Indicates the message is sent by an actual user and should be used in
+      most cases to represent user-generated messages.
+    - `assistant`: Indicates the message is generated by the assistant. Use this
+      value to insert messages from the assistant into the conversation.
+    """
+
+    file_ids: List[str]
+    """
+    A list of [File](https://platform.openai.com/docs/api-reference/files) IDs that
+    the message should use. There can be a maximum of 10 files attached to a
+    message. Useful for tools like `retrieval` and `code_interpreter` that can
+    access and use files.
+    """
+
+    metadata: Optional[object]
+    """Set of 16 key-value pairs that can be attached to an object.
+
+    This can be useful for storing additional information about the object in a
+    structured format. Keys can be a maximum of 64 characters long and values can be
+    a maxium of 512 characters long.
+    """
+
+
 class RunCreateParamsNonStreaming(RunCreateParamsBase):
     stream: Optional[Literal[False]]
     """
tests/api_resources/beta/threads/test_runs.py
@@ -36,6 +36,26 @@ class TestRuns:
             "string",
             assistant_id="string",
             additional_instructions="string",
+            additional_messages=[
+                {
+                    "role": "user",
+                    "content": "x",
+                    "file_ids": ["string"],
+                    "metadata": {},
+                },
+                {
+                    "role": "user",
+                    "content": "x",
+                    "file_ids": ["string"],
+                    "metadata": {},
+                },
+                {
+                    "role": "user",
+                    "content": "x",
+                    "file_ids": ["string"],
+                    "metadata": {},
+                },
+            ],
             instructions="string",
             metadata={},
             model="string",
@@ -95,6 +115,26 @@ class TestRuns:
             assistant_id="string",
             stream=True,
             additional_instructions="string",
+            additional_messages=[
+                {
+                    "role": "user",
+                    "content": "x",
+                    "file_ids": ["string"],
+                    "metadata": {},
+                },
+                {
+                    "role": "user",
+                    "content": "x",
+                    "file_ids": ["string"],
+                    "metadata": {},
+                },
+                {
+                    "role": "user",
+                    "content": "x",
+                    "file_ids": ["string"],
+                    "metadata": {},
+                },
+            ],
             instructions="string",
             metadata={},
             model="string",
@@ -492,6 +532,26 @@ class TestAsyncRuns:
             "string",
             assistant_id="string",
             additional_instructions="string",
+            additional_messages=[
+                {
+                    "role": "user",
+                    "content": "x",
+                    "file_ids": ["string"],
+                    "metadata": {},
+                },
+                {
+                    "role": "user",
+                    "content": "x",
+                    "file_ids": ["string"],
+                    "metadata": {},
+                },
+                {
+                    "role": "user",
+                    "content": "x",
+                    "file_ids": ["string"],
+                    "metadata": {},
+                },
+            ],
             instructions="string",
             metadata={},
             model="string",
@@ -551,6 +611,26 @@ class TestAsyncRuns:
             assistant_id="string",
             stream=True,
             additional_instructions="string",
+            additional_messages=[
+                {
+                    "role": "user",
+                    "content": "x",
+                    "file_ids": ["string"],
+                    "metadata": {},
+                },
+                {
+                    "role": "user",
+                    "content": "x",
+                    "file_ids": ["string"],
+                    "metadata": {},
+                },
+                {
+                    "role": "user",
+                    "content": "x",
+                    "file_ids": ["string"],
+                    "metadata": {},
+                },
+            ],
             instructions="string",
             metadata={},
             model="string",