Current section
Files
Jump to
Current section
Files
lib/letta_api/api/messages.ex
# NOTE: This file is auto generated by OpenAPI Generator 7.13.0 (https://openapi-generator.tech).
# Do not edit this file manually.
defmodule LettaAPI.Api.Messages do
@moduledoc """
API calls for all endpoints tagged `Messages`.
"""
alias LettaAPI.Connection
import LettaAPI.RequestBuilder
@doc """
Cancel Batch Run
Cancel a batch run.
### Parameters
- `connection` (LettaAPI.Connection): Connection to server
- `batch_id` (String.t):
- `opts` (keyword): Optional parameters
- `:user_id` (String.t):
### Returns
- `{:ok, any()}` on success
- `{:error, Tesla.Env.t}` on failure
"""
@spec cancel_batch_run(Tesla.Env.client, String.t, keyword()) :: {:ok, any()} | {:ok, LettaAPI.Model.HttpValidationError.t} | {:error, Tesla.Env.t}
def cancel_batch_run(connection, batch_id, opts \\ []) do
optional_params = %{
:user_id => :headers
}
request =
%{}
|> method(:patch)
|> url("/v1/messages/batches/#{batch_id}/cancel")
|> add_optional_params(optional_params, opts)
|> ensure_body()
|> Enum.into([])
connection
|> Connection.request(request)
|> evaluate_response([
{200, LettaAPI.Model.AnyType},
{422, LettaAPI.Model.HttpValidationError}
])
end
@doc """
Create Messages Batch
Submit a batch of agent messages for asynchronous processing. Creates a job that will fan out messages to all listed agents and process them in parallel.
### Parameters
- `connection` (LettaAPI.Connection): Connection to server
- `create_batch` (CreateBatch):
- `opts` (keyword): Optional parameters
- `:user_id` (String.t):
### Returns
- `{:ok, LettaAPI.Model.BatchJob.t}` on success
- `{:error, Tesla.Env.t}` on failure
"""
@spec create_messages_batch(Tesla.Env.client, LettaAPI.Model.CreateBatch.t, keyword()) :: {:ok, LettaAPI.Model.BatchJob.t} | {:ok, LettaAPI.Model.HttpValidationError.t} | {:error, Tesla.Env.t}
def create_messages_batch(connection, create_batch, opts \\ []) do
optional_params = %{
:user_id => :headers
}
request =
%{}
|> method(:post)
|> url("/v1/messages/batches")
|> add_param(:body, :body, create_batch)
|> add_optional_params(optional_params, opts)
|> Enum.into([])
connection
|> Connection.request(request)
|> evaluate_response([
{200, LettaAPI.Model.BatchJob},
{422, LettaAPI.Model.HttpValidationError}
])
end
@doc """
List Batch Messages
Get messages for a specific batch job. Returns messages associated with the batch in chronological order. Pagination: - For the first page, omit the cursor parameter - For subsequent pages, use the ID of the last message from the previous response as the cursor - Results will include messages before/after the cursor based on sort_descending
### Parameters
- `connection` (LettaAPI.Connection): Connection to server
- `batch_id` (String.t):
- `opts` (keyword): Optional parameters
- `:limit` (integer()): Maximum number of messages to return
- `:cursor` (String.t): Message ID to use as pagination cursor (get messages before/after this ID) depending on sort_descending.
- `:agent_id` (String.t): Filter messages by agent ID
- `:sort_descending` (boolean()): Sort messages by creation time (true=newest first)
- `:user_id` (String.t):
### Returns
- `{:ok, LettaAPI.Model.LettaBatchMessages.t}` on success
- `{:error, Tesla.Env.t}` on failure
"""
@spec list_batch_messages(Tesla.Env.client, String.t, keyword()) :: {:ok, LettaAPI.Model.LettaBatchMessages.t} | {:ok, LettaAPI.Model.HttpValidationError.t} | {:error, Tesla.Env.t}
def list_batch_messages(connection, batch_id, opts \\ []) do
optional_params = %{
:limit => :query,
:cursor => :query,
:agent_id => :query,
:sort_descending => :query,
:user_id => :headers
}
request =
%{}
|> method(:get)
|> url("/v1/messages/batches/#{batch_id}/messages")
|> add_optional_params(optional_params, opts)
|> Enum.into([])
connection
|> Connection.request(request)
|> evaluate_response([
{200, LettaAPI.Model.LettaBatchMessages},
{422, LettaAPI.Model.HttpValidationError}
])
end
@doc """
List Batch Runs
List all batch runs.
### Parameters
- `connection` (LettaAPI.Connection): Connection to server
- `opts` (keyword): Optional parameters
- `:user_id` (String.t):
### Returns
- `{:ok, [%BatchJob{}, ...]}` on success
- `{:error, Tesla.Env.t}` on failure
"""
@spec list_batch_runs(Tesla.Env.client, keyword()) :: {:ok, [LettaAPI.Model.BatchJob.t]} | {:ok, LettaAPI.Model.HttpValidationError.t} | {:error, Tesla.Env.t}
def list_batch_runs(connection, opts \\ []) do
optional_params = %{
:user_id => :headers
}
request =
%{}
|> method(:get)
|> url("/v1/messages/batches")
|> add_optional_params(optional_params, opts)
|> Enum.into([])
connection
|> Connection.request(request)
|> evaluate_response([
{200, LettaAPI.Model.BatchJob},
{422, LettaAPI.Model.HttpValidationError}
])
end
@doc """
Retrieve Batch Run
Get the status of a batch run.
### Parameters
- `connection` (LettaAPI.Connection): Connection to server
- `batch_id` (String.t):
- `opts` (keyword): Optional parameters
- `:user_id` (String.t):
### Returns
- `{:ok, LettaAPI.Model.BatchJob.t}` on success
- `{:error, Tesla.Env.t}` on failure
"""
@spec retrieve_batch_run(Tesla.Env.client, String.t, keyword()) :: {:ok, LettaAPI.Model.BatchJob.t} | {:ok, LettaAPI.Model.HttpValidationError.t} | {:error, Tesla.Env.t}
def retrieve_batch_run(connection, batch_id, opts \\ []) do
optional_params = %{
:user_id => :headers
}
request =
%{}
|> method(:get)
|> url("/v1/messages/batches/#{batch_id}")
|> add_optional_params(optional_params, opts)
|> Enum.into([])
connection
|> Connection.request(request)
|> evaluate_response([
{200, LettaAPI.Model.BatchJob},
{422, LettaAPI.Model.HttpValidationError}
])
end
end