Skip to content

feat(api): add additional messages when creating thread run #1298

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 42 additions & 0 deletions src/openai/resources/beta/threads/runs/runs.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ def create(
*,
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,
Expand All @@ -100,6 +101,8 @@ def create(
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.
Expand Down Expand Up @@ -143,6 +146,7 @@ def create(
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,
Expand Down Expand Up @@ -171,6 +175,8 @@ def create(
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.
Expand Down Expand Up @@ -210,6 +216,7 @@ def create(
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,
Expand Down Expand Up @@ -238,6 +245,8 @@ def create(
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.
Expand Down Expand Up @@ -276,6 +285,7 @@ def create(
*,
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,
Expand All @@ -298,6 +308,7 @@ def create(
{
"assistant_id": assistant_id,
"additional_instructions": additional_instructions,
"additional_messages": additional_messages,
"instructions": instructions,
"metadata": metadata,
"model": model,
Expand Down Expand Up @@ -505,6 +516,7 @@ def create_and_poll(
*,
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,
Expand All @@ -528,6 +540,7 @@ def create_and_poll(
thread_id=thread_id,
assistant_id=assistant_id,
additional_instructions=additional_instructions,
additional_messages=additional_messages,
instructions=instructions,
metadata=metadata,
model=model,
Expand Down Expand Up @@ -557,6 +570,7 @@ def create_and_stream(
*,
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,
Expand All @@ -580,6 +594,7 @@ def create_and_stream(
*,
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,
Expand All @@ -603,6 +618,7 @@ def create_and_stream(
*,
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,
Expand Down Expand Up @@ -634,6 +650,7 @@ def create_and_stream(
{
"assistant_id": assistant_id,
"additional_instructions": additional_instructions,
"additional_messages": additional_messages,
"instructions": instructions,
"metadata": metadata,
"model": model,
Expand Down Expand Up @@ -703,6 +720,7 @@ def stream(
*,
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,
Expand All @@ -725,6 +743,7 @@ def stream(
*,
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,
Expand All @@ -747,6 +766,7 @@ def stream(
*,
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,
Expand Down Expand Up @@ -778,6 +798,7 @@ def stream(
{
"assistant_id": assistant_id,
"additional_instructions": additional_instructions,
"additional_messages": additional_messages,
"instructions": instructions,
"metadata": metadata,
"model": model,
Expand Down Expand Up @@ -1100,6 +1121,7 @@ async def create(
*,
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,
Expand All @@ -1125,6 +1147,8 @@ async def create(
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.
Expand Down Expand Up @@ -1168,6 +1192,7 @@ async def create(
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,
Expand Down Expand Up @@ -1196,6 +1221,8 @@ async def create(
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.
Expand Down Expand Up @@ -1235,6 +1262,7 @@ async def create(
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,
Expand Down Expand Up @@ -1263,6 +1291,8 @@ async def create(
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.
Expand Down Expand Up @@ -1301,6 +1331,7 @@ async def create(
*,
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,
Expand All @@ -1323,6 +1354,7 @@ async def create(
{
"assistant_id": assistant_id,
"additional_instructions": additional_instructions,
"additional_messages": additional_messages,
"instructions": instructions,
"metadata": metadata,
"model": model,
Expand Down Expand Up @@ -1530,6 +1562,7 @@ async def create_and_poll(
*,
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,
Expand All @@ -1553,6 +1586,7 @@ async def create_and_poll(
thread_id=thread_id,
assistant_id=assistant_id,
additional_instructions=additional_instructions,
additional_messages=additional_messages,
instructions=instructions,
metadata=metadata,
model=model,
Expand Down Expand Up @@ -1582,6 +1616,7 @@ def create_and_stream(
*,
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,
Expand All @@ -1605,6 +1640,7 @@ def create_and_stream(
*,
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,
Expand All @@ -1628,6 +1664,7 @@ def create_and_stream(
*,
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,
Expand Down Expand Up @@ -1661,6 +1698,7 @@ def create_and_stream(
{
"assistant_id": assistant_id,
"additional_instructions": additional_instructions,
"additional_messages": additional_messages,
"instructions": instructions,
"metadata": metadata,
"model": model,
Expand Down Expand Up @@ -1730,6 +1768,7 @@ def stream(
*,
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,
Expand All @@ -1752,6 +1791,7 @@ def stream(
*,
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,
Expand All @@ -1774,6 +1814,7 @@ def stream(
*,
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,
Expand Down Expand Up @@ -1807,6 +1848,7 @@ def stream(
{
"assistant_id": assistant_id,
"additional_instructions": additional_instructions,
"additional_messages": additional_messages,
"instructions": instructions,
"metadata": metadata,
"model": model,
Expand Down
37 changes: 35 additions & 2 deletions src/openai/types/beta/threads/run_create_params.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand All @@ -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
Expand Down Expand Up @@ -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]]
"""
Expand Down
Loading