View Source ExOpenAI.Threads (ex_openai.ex v1.5.1)
Modules for interacting with the threads
group of OpenAI APIs
API Reference: https://platform.openai.com/docs/api-reference/threads
Summary
Functions
Cancels a run that is in_progress
.
Create a message.
Create a run.
Create a thread.
Create a thread and run it in one request.
Delete a thread.
Retrieve a message.
Retrieves a message file.
Retrieves a run.
Retrieves a run step.
Retrieves a thread.
Returns a list of message files.
Returns a list of messages for a given thread.
Returns a list of run steps belonging to a run.
Returns a list of runs belonging to a thread.
Modifies a message.
Modifies a run.
Modifies a thread.
When a run has the status: "requires_action"
and required_action.type
is submit_tool_outputs
, this endpoint can be used to submit the outputs from the tool calls once they're all completed. All outputs must be submitted in a single request.
Functions
@spec cancel_run(String.t(), String.t(), openai_organization_key: String.t(), openai_api_key: String.t() ) :: {:ok, ExOpenAI.Components.RunObject.t()} | {:error, any()}
Cancels a run that is in_progress
.
Endpoint: https://api.openai.com/v1/threads/{thread_id}/runs/{run_id}/cancel
Method: POST
Docs: https://platform.openai.com/docs/api-reference/threads
Required Arguments:
thread_id
run_id
Optional Arguments:
openai_api_key
: OpenAI API key to pass directly. If this is specified, it will override theapi_key
config value.openai_organization_key
: OpenAI API key to pass directly. If this is specified, it will override theorganization_key
config value.
@spec create_message(String.t(), String.t(), :user, openai_organization_key: String.t(), openai_api_key: String.t(), metadata: map(), file_ids: [String.t()], stream_to: (... -> any()) | pid() ) :: {:ok, ExOpenAI.Components.MessageObject.t()} | {:error, any()}
Create a message.
Endpoint: https://api.openai.com/v1/threads/{thread_id}/messages
Method: POST
Docs: https://platform.openai.com/docs/api-reference/threads
Required Arguments:
thread_id
content
: The content of the message.role
: The role of the entity that is creating the message. Currently onlyuser
is supported.
Optional Arguments:
stream_to
: PID or function of where to stream content tofile_ids
: A list of File IDs that the message should use. There can be a maximum of 10 files attached to a message. Useful for tools likeretrieval
andcode_interpreter
that can access and use files.metadata
: 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.openai_api_key
: OpenAI API key to pass directly. If this is specified, it will override theapi_key
config value.openai_organization_key
: OpenAI API key to pass directly. If this is specified, it will override theorganization_key
config value.
@spec create_run(String.t(), String.t(), openai_organization_key: String.t(), openai_api_key: String.t(), tools: [map()], model: String.t(), metadata: map(), instructions: String.t(), stream_to: (... -> any()) | pid() ) :: {:ok, ExOpenAI.Components.RunObject.t()} | {:error, any()}
Create a run.
Endpoint: https://api.openai.com/v1/threads/{thread_id}/runs
Method: POST
Docs: https://platform.openai.com/docs/api-reference/threads
Required Arguments:
thread_id
assistant_id
: The ID of the assistant to use to execute this run.
Optional Arguments:
stream_to
: PID or function of where to stream content toinstructions
: Override the default system message of the assistant. This is useful for modifying the behavior on a per-run basis.metadata
: 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.model
: The ID of the Model to be used to execute this run. If a value is provided here, it will override the model associated with the assistant. If not, the model associated with the assistant will be used.tools
: Override the tools the assistant can use for this run. This is useful for modifying the behavior on a per-run basis.openai_api_key
: OpenAI API key to pass directly. If this is specified, it will override theapi_key
config value.openai_organization_key
: OpenAI API key to pass directly. If this is specified, it will override theorganization_key
config value.
@spec create_thread( openai_organization_key: String.t(), openai_api_key: String.t(), metadata: map(), messages: [ExOpenAI.Components.CreateMessageRequest.t()], stream_to: (... -> any()) | pid() ) :: {:ok, ExOpenAI.Components.ThreadObject.t()} | {:error, any()}
Create a thread.
Endpoint: https://api.openai.com/v1/threads
Method: POST
Docs: https://platform.openai.com/docs/api-reference/threads
Required Arguments:
Optional Arguments:
stream_to
: PID or function of where to stream content tomessages
: A list of messages to start the thread with.metadata
: 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.openai_api_key
: OpenAI API key to pass directly. If this is specified, it will override theapi_key
config value.openai_organization_key
: OpenAI API key to pass directly. If this is specified, it will override theorganization_key
config value.
@spec create_thread_and_run(String.t(), openai_organization_key: String.t(), openai_api_key: String.t(), tools: [map()], thread: ExOpenAI.Components.CreateThreadRequest.t(), model: String.t(), metadata: map(), instructions: String.t(), stream_to: (... -> any()) | pid() ) :: {:ok, ExOpenAI.Components.RunObject.t()} | {:error, any()}
Create a thread and run it in one request.
Endpoint: https://api.openai.com/v1/threads/runs
Method: POST
Docs: https://platform.openai.com/docs/api-reference/threads
Required Arguments:
assistant_id
: The ID of the assistant to use to execute this run.
Optional Arguments:
stream_to
: PID or function of where to stream content toinstructions
: Override the default system message of the assistant. This is useful for modifying the behavior on a per-run basis.metadata
: 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.model
: The ID of the Model to be used to execute this run. If a value is provided here, it will override the model associated with the assistant. If not, the model associated with the assistant will be used.thread
: If no thread is provided, an empty thread will be created.tools
: Override the tools the assistant can use for this run. This is useful for modifying the behavior on a per-run basis.openai_api_key
: OpenAI API key to pass directly. If this is specified, it will override theapi_key
config value.openai_organization_key
: OpenAI API key to pass directly. If this is specified, it will override theorganization_key
config value.
@spec delete_thread(String.t(), openai_organization_key: String.t(), openai_api_key: String.t() ) :: {:ok, ExOpenAI.Components.DeleteThreadResponse.t()} | {:error, any()}
Delete a thread.
Endpoint: https://api.openai.com/v1/threads/{thread_id}
Method: DELETE
Docs: https://platform.openai.com/docs/api-reference/threads
Required Arguments:
thread_id
Optional Arguments:
openai_api_key
: OpenAI API key to pass directly. If this is specified, it will override theapi_key
config value.openai_organization_key
: OpenAI API key to pass directly. If this is specified, it will override theorganization_key
config value.
@spec get_message(String.t(), String.t(), openai_organization_key: String.t(), openai_api_key: String.t() ) :: {:ok, ExOpenAI.Components.MessageObject.t()} | {:error, any()}
Retrieve a message.
Endpoint: https://api.openai.com/v1/threads/{thread_id}/messages/{message_id}
Method: GET
Docs: https://platform.openai.com/docs/api-reference/threads
Required Arguments:
thread_id
message_id
Optional Arguments:
openai_api_key
: OpenAI API key to pass directly. If this is specified, it will override theapi_key
config value.openai_organization_key
: OpenAI API key to pass directly. If this is specified, it will override theorganization_key
config value.
@spec get_message_file(String.t(), String.t(), String.t(), openai_organization_key: String.t(), openai_api_key: String.t() ) :: {:ok, ExOpenAI.Components.MessageFileObject.t()} | {:error, any()}
Retrieves a message file.
Endpoint: https://api.openai.com/v1/threads/{thread_id}/messages/{message_id}/files/{file_id}
Method: GET
Docs: https://platform.openai.com/docs/api-reference/threads
Required Arguments:
thread_id
Example: thread_AF1WoRqd3aJAHsqc9NY7iL8F
message_id
Example: msg_AF1WoRqd3aJAHsqc9NY7iL8F
file_id
Example: file-AF1WoRqd3aJAHsqc9NY7iL8F
Optional Arguments:
openai_api_key
: OpenAI API key to pass directly. If this is specified, it will override theapi_key
config value.openai_organization_key
: OpenAI API key to pass directly. If this is specified, it will override theorganization_key
config value.
@spec get_run(String.t(), String.t(), openai_organization_key: String.t(), openai_api_key: String.t() ) :: {:ok, ExOpenAI.Components.RunObject.t()} | {:error, any()}
Retrieves a run.
Endpoint: https://api.openai.com/v1/threads/{thread_id}/runs/{run_id}
Method: GET
Docs: https://platform.openai.com/docs/api-reference/threads
Required Arguments:
thread_id
run_id
Optional Arguments:
openai_api_key
: OpenAI API key to pass directly. If this is specified, it will override theapi_key
config value.openai_organization_key
: OpenAI API key to pass directly. If this is specified, it will override theorganization_key
config value.
@spec get_run_step(String.t(), String.t(), String.t(), openai_organization_key: String.t(), openai_api_key: String.t() ) :: {:ok, ExOpenAI.Components.RunStepObject.t()} | {:error, any()}
Retrieves a run step.
Endpoint: https://api.openai.com/v1/threads/{thread_id}/runs/{run_id}/steps/{step_id}
Method: GET
Docs: https://platform.openai.com/docs/api-reference/threads
Required Arguments:
thread_id
run_id
step_id
Optional Arguments:
openai_api_key
: OpenAI API key to pass directly. If this is specified, it will override theapi_key
config value.openai_organization_key
: OpenAI API key to pass directly. If this is specified, it will override theorganization_key
config value.
@spec get_thread(String.t(), openai_organization_key: String.t(), openai_api_key: String.t() ) :: {:ok, ExOpenAI.Components.ThreadObject.t()} | {:error, any()}
Retrieves a thread.
Endpoint: https://api.openai.com/v1/threads/{thread_id}
Method: GET
Docs: https://platform.openai.com/docs/api-reference/threads
Required Arguments:
thread_id
Optional Arguments:
openai_api_key
: OpenAI API key to pass directly. If this is specified, it will override theapi_key
config value.openai_organization_key
: OpenAI API key to pass directly. If this is specified, it will override theorganization_key
config value.
@spec list_message_files(String.t(), String.t(), openai_organization_key: String.t(), openai_api_key: String.t(), before: String.t(), after: String.t(), order: String.t(), limit: integer(), stream_to: (... -> any()) | pid() ) :: {:ok, ExOpenAI.Components.ListMessageFilesResponse.t()} | {:error, any()}
Returns a list of message files.
Endpoint: https://api.openai.com/v1/threads/{thread_id}/messages/{message_id}/files
Method: GET
Docs: https://platform.openai.com/docs/api-reference/threads
Required Arguments:
thread_id
message_id
Optional Arguments:
stream_to
: PID or function of where to stream content tolimit
order
after
before
openai_api_key
: OpenAI API key to pass directly. If this is specified, it will override theapi_key
config value.openai_organization_key
: OpenAI API key to pass directly. If this is specified, it will override theorganization_key
config value.
@spec list_messages(String.t(), openai_organization_key: String.t(), openai_api_key: String.t(), before: String.t(), after: String.t(), order: String.t(), limit: integer(), stream_to: (... -> any()) | pid() ) :: {:ok, ExOpenAI.Components.ListMessagesResponse.t()} | {:error, any()}
Returns a list of messages for a given thread.
Endpoint: https://api.openai.com/v1/threads/{thread_id}/messages
Method: GET
Docs: https://platform.openai.com/docs/api-reference/threads
Required Arguments:
thread_id
Optional Arguments:
stream_to
: PID or function of where to stream content tolimit
order
after
before
openai_api_key
: OpenAI API key to pass directly. If this is specified, it will override theapi_key
config value.openai_organization_key
: OpenAI API key to pass directly. If this is specified, it will override theorganization_key
config value.
@spec list_run_steps(String.t(), String.t(), openai_organization_key: String.t(), openai_api_key: String.t(), before: String.t(), after: String.t(), order: String.t(), limit: integer(), stream_to: (... -> any()) | pid() ) :: {:ok, ExOpenAI.Components.ListRunStepsResponse.t()} | {:error, any()}
Returns a list of run steps belonging to a run.
Endpoint: https://api.openai.com/v1/threads/{thread_id}/runs/{run_id}/steps
Method: GET
Docs: https://platform.openai.com/docs/api-reference/threads
Required Arguments:
thread_id
run_id
Optional Arguments:
stream_to
: PID or function of where to stream content tolimit
order
after
before
openai_api_key
: OpenAI API key to pass directly. If this is specified, it will override theapi_key
config value.openai_organization_key
: OpenAI API key to pass directly. If this is specified, it will override theorganization_key
config value.
@spec list_runs(String.t(), openai_organization_key: String.t(), openai_api_key: String.t(), before: String.t(), after: String.t(), order: String.t(), limit: integer(), stream_to: (... -> any()) | pid() ) :: {:ok, ExOpenAI.Components.ListRunsResponse.t()} | {:error, any()}
Returns a list of runs belonging to a thread.
Endpoint: https://api.openai.com/v1/threads/{thread_id}/runs
Method: GET
Docs: https://platform.openai.com/docs/api-reference/threads
Required Arguments:
thread_id
Optional Arguments:
stream_to
: PID or function of where to stream content tolimit
order
after
before
openai_api_key
: OpenAI API key to pass directly. If this is specified, it will override theapi_key
config value.openai_organization_key
: OpenAI API key to pass directly. If this is specified, it will override theorganization_key
config value.
@spec modify_message(String.t(), String.t(), openai_organization_key: String.t(), openai_api_key: String.t(), metadata: map(), stream_to: (... -> any()) | pid() ) :: {:ok, ExOpenAI.Components.MessageObject.t()} | {:error, any()}
Modifies a message.
Endpoint: https://api.openai.com/v1/threads/{thread_id}/messages/{message_id}
Method: POST
Docs: https://platform.openai.com/docs/api-reference/threads
Required Arguments:
thread_id
message_id
Optional Arguments:
stream_to
: PID or function of where to stream content tometadata
: 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.openai_api_key
: OpenAI API key to pass directly. If this is specified, it will override theapi_key
config value.openai_organization_key
: OpenAI API key to pass directly. If this is specified, it will override theorganization_key
config value.
@spec modify_run(String.t(), String.t(), openai_organization_key: String.t(), openai_api_key: String.t(), metadata: map(), stream_to: (... -> any()) | pid() ) :: {:ok, ExOpenAI.Components.RunObject.t()} | {:error, any()}
Modifies a run.
Endpoint: https://api.openai.com/v1/threads/{thread_id}/runs/{run_id}
Method: POST
Docs: https://platform.openai.com/docs/api-reference/threads
Required Arguments:
thread_id
run_id
Optional Arguments:
stream_to
: PID or function of where to stream content tometadata
: 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.openai_api_key
: OpenAI API key to pass directly. If this is specified, it will override theapi_key
config value.openai_organization_key
: OpenAI API key to pass directly. If this is specified, it will override theorganization_key
config value.
@spec modify_thread(String.t(), openai_organization_key: String.t(), openai_api_key: String.t(), metadata: map(), stream_to: (... -> any()) | pid() ) :: {:ok, ExOpenAI.Components.ThreadObject.t()} | {:error, any()}
Modifies a thread.
Endpoint: https://api.openai.com/v1/threads/{thread_id}
Method: POST
Docs: https://platform.openai.com/docs/api-reference/threads
Required Arguments:
thread_id
Optional Arguments:
stream_to
: PID or function of where to stream content tometadata
: 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.openai_api_key
: OpenAI API key to pass directly. If this is specified, it will override theapi_key
config value.openai_organization_key
: OpenAI API key to pass directly. If this is specified, it will override theorganization_key
config value.
submit_tool_ouputs_to_run(thread_id, run_id, tool_outputs, opts \\ [])
View Source@spec submit_tool_ouputs_to_run( String.t(), String.t(), [%{output: String.t(), tool_call_id: String.t()}], openai_organization_key: String.t(), openai_api_key: String.t() ) :: {:ok, ExOpenAI.Components.RunObject.t()} | {:error, any()}
When a run has the status: "requires_action"
and required_action.type
is submit_tool_outputs
, this endpoint can be used to submit the outputs from the tool calls once they're all completed. All outputs must be submitted in a single request.
Endpoint: https://api.openai.com/v1/threads/{thread_id}/runs/{run_id}/submit_tool_outputs
Method: POST
Docs: https://platform.openai.com/docs/api-reference/threads
Required Arguments:
thread_id
run_id
tool_outputs
: A list of tools for which the outputs are being submitted.
Optional Arguments:
openai_api_key
: OpenAI API key to pass directly. If this is specified, it will override theapi_key
config value.openai_organization_key
: OpenAI API key to pass directly. If this is specified, it will override theorganization_key
config value.