Packages

Sans-IO OpenAI API client for Gleam, ported from async-openai

Current section

Files

Jump to
glopenai src glopenai@batch.erl
Raw

src/glopenai@batch.erl

-module(glopenai@batch).
-compile([no_auto_import, nowarn_unused_vars, nowarn_unused_function, nowarn_nomatch, inline]).
-define(FILEPATH, "src/glopenai/batch.gleam").
-export([new_batch_request/3, with_metadata/2, with_output_expires_after/2, batch_endpoint_to_json/1, batch_completion_window_to_json/1, batch_status_to_json/1, batch_file_expiration_anchor_to_json/1, batch_file_expiration_after_to_json/1, batch_request_input_method_to_json/1, batch_request_to_json/1, batch_request_input_to_json/1, batch_endpoint_decoder/0, batch_completion_window_decoder/0, batch_status_decoder/0, batch_file_expiration_anchor_decoder/0, batch_error_decoder/0, batch_errors_decoder/0, batch_request_counts_decoder/0, batch_decoder/0, batch_request_input_method_decoder/0, batch_request_input_decoder/0, batch_request_output_response_decoder/0, batch_request_output_error_decoder/0, batch_request_output_decoder/0, create_request/2, create_response/1, list_request/1, list_response/1, retrieve_request/2, retrieve_response/1, cancel_request/2, cancel_response/1]).
-export_type([batch_endpoint/0, batch_completion_window/0, batch_file_expiration_anchor/0, batch_status/0, batch_request_input_method/0, batch_file_expiration_after/0, batch_request/0, batch_error/0, batch_errors/0, batch_request_counts/0, batch/0, list_batches_response/0, batch_request_input/0, batch_request_output_response/0, batch_request_output_error/0, batch_request_output/0]).
-if(?OTP_RELEASE >= 27).
-define(MODULEDOC(Str), -moduledoc(Str)).
-define(DOC(Str), -doc(Str)).
-else.
-define(MODULEDOC(Str), -compile([])).
-define(DOC(Str), -compile([])).
-endif.
-type batch_endpoint() :: v1_responses |
v1_chat_completions |
v1_embeddings |
v1_completions |
v1_moderations.
-type batch_completion_window() :: w24_h.
-type batch_file_expiration_anchor() :: created_at.
-type batch_status() :: validating |
failed |
in_progress |
finalizing |
completed |
expired |
cancelling |
cancelled.
-type batch_request_input_method() :: post.
-type batch_file_expiration_after() :: {batch_file_expiration_after,
batch_file_expiration_anchor(),
integer()}.
-type batch_request() :: {batch_request,
binary(),
batch_endpoint(),
batch_completion_window(),
gleam@option:option(gleam@dynamic:dynamic_()),
gleam@option:option(batch_file_expiration_after())}.
-type batch_error() :: {batch_error,
binary(),
binary(),
gleam@option:option(binary()),
gleam@option:option(integer())}.
-type batch_errors() :: {batch_errors, binary(), list(batch_error())}.
-type batch_request_counts() :: {batch_request_counts,
integer(),
integer(),
integer()}.
-type batch() :: {batch,
binary(),
binary(),
binary(),
gleam@option:option(binary()),
gleam@option:option(batch_errors()),
binary(),
binary(),
batch_status(),
gleam@option:option(binary()),
gleam@option:option(binary()),
integer(),
gleam@option:option(integer()),
gleam@option:option(integer()),
gleam@option:option(integer()),
gleam@option:option(integer()),
gleam@option:option(integer()),
gleam@option:option(integer()),
gleam@option:option(integer()),
gleam@option:option(integer()),
gleam@option:option(batch_request_counts()),
gleam@option:option(glopenai@shared:response_usage()),
gleam@option:option(gleam@dynamic:dynamic_())}.
-type list_batches_response() :: {list_batches_response,
list(batch()),
gleam@option:option(binary()),
gleam@option:option(binary()),
boolean(),
binary()}.
-type batch_request_input() :: {batch_request_input,
binary(),
batch_request_input_method(),
batch_endpoint(),
gleam@option:option(gleam@dynamic:dynamic_())}.
-type batch_request_output_response() :: {batch_request_output_response,
integer(),
binary(),
gleam@dynamic:dynamic_()}.
-type batch_request_output_error() :: {batch_request_output_error,
binary(),
binary()}.
-type batch_request_output() :: {batch_request_output,
binary(),
binary(),
gleam@option:option(batch_request_output_response()),
gleam@option:option(batch_request_output_error())}.
-file("src/glopenai/batch.gleam", 172).
?DOC(" Create a new batch request with required fields.\n").
-spec new_batch_request(binary(), batch_endpoint(), batch_completion_window()) -> batch_request().
new_batch_request(Input_file_id, Endpoint, Completion_window) ->
{batch_request, Input_file_id, Endpoint, Completion_window, none, none}.
-file("src/glopenai/batch.gleam", 186).
-spec with_metadata(batch_request(), gleam@dynamic:dynamic_()) -> batch_request().
with_metadata(Request, Metadata) ->
{batch_request,
erlang:element(2, Request),
erlang:element(3, Request),
erlang:element(4, Request),
{some, Metadata},
erlang:element(6, Request)}.
-file("src/glopenai/batch.gleam", 193).
-spec with_output_expires_after(batch_request(), batch_file_expiration_after()) -> batch_request().
with_output_expires_after(Request, Expiration) ->
{batch_request,
erlang:element(2, Request),
erlang:element(3, Request),
erlang:element(4, Request),
erlang:element(5, Request),
{some, Expiration}}.
-file("src/glopenai/batch.gleam", 204).
-spec batch_endpoint_to_json(batch_endpoint()) -> gleam@json:json().
batch_endpoint_to_json(Endpoint) ->
gleam@json:string(case Endpoint of
v1_responses ->
<<"/v1/responses"/utf8>>;
v1_chat_completions ->
<<"/v1/chat/completions"/utf8>>;
v1_embeddings ->
<<"/v1/embeddings"/utf8>>;
v1_completions ->
<<"/v1/completions"/utf8>>;
v1_moderations ->
<<"/v1/moderations"/utf8>>
end).
-file("src/glopenai/batch.gleam", 214).
-spec batch_completion_window_to_json(batch_completion_window()) -> gleam@json:json().
batch_completion_window_to_json(Window) ->
gleam@json:string(case Window of
w24_h ->
<<"24h"/utf8>>
end).
-file("src/glopenai/batch.gleam", 222).
-spec batch_status_to_json(batch_status()) -> gleam@json:json().
batch_status_to_json(Status) ->
gleam@json:string(case Status of
validating ->
<<"validating"/utf8>>;
failed ->
<<"failed"/utf8>>;
in_progress ->
<<"in_progress"/utf8>>;
finalizing ->
<<"finalizing"/utf8>>;
completed ->
<<"completed"/utf8>>;
expired ->
<<"expired"/utf8>>;
cancelling ->
<<"cancelling"/utf8>>;
cancelled ->
<<"cancelled"/utf8>>
end).
-file("src/glopenai/batch.gleam", 235).
-spec batch_file_expiration_anchor_to_json(batch_file_expiration_anchor()) -> gleam@json:json().
batch_file_expiration_anchor_to_json(Anchor) ->
gleam@json:string(case Anchor of
created_at ->
<<"created_at"/utf8>>
end).
-file("src/glopenai/batch.gleam", 243).
-spec batch_file_expiration_after_to_json(batch_file_expiration_after()) -> gleam@json:json().
batch_file_expiration_after_to_json(Expiration) ->
gleam@json:object(
[{<<"anchor"/utf8>>,
batch_file_expiration_anchor_to_json(
erlang:element(2, Expiration)
)},
{<<"seconds"/utf8>>, gleam@json:int(erlang:element(3, Expiration))}]
).
-file("src/glopenai/batch.gleam", 252).
-spec batch_request_input_method_to_json(batch_request_input_method()) -> gleam@json:json().
batch_request_input_method_to_json(Method) ->
gleam@json:string(case Method of
post ->
<<"POST"/utf8>>
end).
-file("src/glopenai/batch.gleam", 260).
-spec batch_request_to_json(batch_request()) -> gleam@json:json().
batch_request_to_json(Request) ->
glopenai@internal@codec:object_with_optional(
[{<<"input_file_id"/utf8>>,
gleam@json:string(erlang:element(2, Request))},
{<<"endpoint"/utf8>>,
batch_endpoint_to_json(erlang:element(3, Request))},
{<<"completion_window"/utf8>>,
batch_completion_window_to_json(erlang:element(4, Request))}],
[glopenai@internal@codec:optional_field(
<<"metadata"/utf8>>,
erlang:element(5, Request),
fun glopenai_codec_ffi:dynamic_to_json/1
),
glopenai@internal@codec:optional_field(
<<"output_expires_after"/utf8>>,
erlang:element(6, Request),
fun batch_file_expiration_after_to_json/1
)]
).
-file("src/glopenai/batch.gleam", 281).
-spec batch_request_input_to_json(batch_request_input()) -> gleam@json:json().
batch_request_input_to_json(Input) ->
glopenai@internal@codec:object_with_optional(
[{<<"custom_id"/utf8>>, gleam@json:string(erlang:element(2, Input))},
{<<"method"/utf8>>,
batch_request_input_method_to_json(erlang:element(3, Input))},
{<<"url"/utf8>>, batch_endpoint_to_json(erlang:element(4, Input))}],
[glopenai@internal@codec:optional_field(
<<"body"/utf8>>,
erlang:element(5, Input),
fun glopenai_codec_ffi:dynamic_to_json/1
)]
).
-file("src/glopenai/batch.gleam", 296).
-spec batch_endpoint_decoder() -> gleam@dynamic@decode:decoder(batch_endpoint()).
batch_endpoint_decoder() ->
gleam@dynamic@decode:then(
{decoder, fun gleam@dynamic@decode:decode_string/1},
fun(Value) -> case Value of
<<"/v1/responses"/utf8>> ->
gleam@dynamic@decode:success(v1_responses);
<<"/v1/chat/completions"/utf8>> ->
gleam@dynamic@decode:success(v1_chat_completions);
<<"/v1/embeddings"/utf8>> ->
gleam@dynamic@decode:success(v1_embeddings);
<<"/v1/completions"/utf8>> ->
gleam@dynamic@decode:success(v1_completions);
<<"/v1/moderations"/utf8>> ->
gleam@dynamic@decode:success(v1_moderations);
_ ->
gleam@dynamic@decode:failure(
v1_responses,
<<"BatchEndpoint"/utf8>>
)
end end
).
-file("src/glopenai/batch.gleam", 308).
-spec batch_completion_window_decoder() -> gleam@dynamic@decode:decoder(batch_completion_window()).
batch_completion_window_decoder() ->
gleam@dynamic@decode:then(
{decoder, fun gleam@dynamic@decode:decode_string/1},
fun(Value) -> case Value of
<<"24h"/utf8>> ->
gleam@dynamic@decode:success(w24_h);
_ ->
gleam@dynamic@decode:failure(
w24_h,
<<"BatchCompletionWindow"/utf8>>
)
end end
).
-file("src/glopenai/batch.gleam", 318).
-spec batch_status_decoder() -> gleam@dynamic@decode:decoder(batch_status()).
batch_status_decoder() ->
gleam@dynamic@decode:then(
{decoder, fun gleam@dynamic@decode:decode_string/1},
fun(Value) -> case Value of
<<"validating"/utf8>> ->
gleam@dynamic@decode:success(validating);
<<"failed"/utf8>> ->
gleam@dynamic@decode:success(failed);
<<"in_progress"/utf8>> ->
gleam@dynamic@decode:success(in_progress);
<<"finalizing"/utf8>> ->
gleam@dynamic@decode:success(finalizing);
<<"completed"/utf8>> ->
gleam@dynamic@decode:success(completed);
<<"expired"/utf8>> ->
gleam@dynamic@decode:success(expired);
<<"cancelling"/utf8>> ->
gleam@dynamic@decode:success(cancelling);
<<"cancelled"/utf8>> ->
gleam@dynamic@decode:success(cancelled);
_ ->
gleam@dynamic@decode:failure(
validating,
<<"BatchStatus"/utf8>>
)
end end
).
-file("src/glopenai/batch.gleam", 333).
-spec batch_file_expiration_anchor_decoder() -> gleam@dynamic@decode:decoder(batch_file_expiration_anchor()).
batch_file_expiration_anchor_decoder() ->
gleam@dynamic@decode:then(
{decoder, fun gleam@dynamic@decode:decode_string/1},
fun(Value) -> case Value of
<<"created_at"/utf8>> ->
gleam@dynamic@decode:success(created_at);
_ ->
gleam@dynamic@decode:failure(
created_at,
<<"BatchFileExpirationAnchor"/utf8>>
)
end end
).
-file("src/glopenai/batch.gleam", 343).
-spec batch_error_decoder() -> gleam@dynamic@decode:decoder(batch_error()).
batch_error_decoder() ->
gleam@dynamic@decode:field(
<<"code"/utf8>>,
{decoder, fun gleam@dynamic@decode:decode_string/1},
fun(Code) ->
gleam@dynamic@decode:field(
<<"message"/utf8>>,
{decoder, fun gleam@dynamic@decode:decode_string/1},
fun(Message) ->
gleam@dynamic@decode:optional_field(
<<"param"/utf8>>,
none,
gleam@dynamic@decode:optional(
{decoder, fun gleam@dynamic@decode:decode_string/1}
),
fun(Param) ->
gleam@dynamic@decode:optional_field(
<<"line"/utf8>>,
none,
gleam@dynamic@decode:optional(
{decoder,
fun gleam@dynamic@decode:decode_int/1}
),
fun(Line) ->
gleam@dynamic@decode:success(
{batch_error,
Code,
Message,
Param,
Line}
)
end
)
end
)
end
)
end
).
-file("src/glopenai/batch.gleam", 360).
-spec batch_errors_decoder() -> gleam@dynamic@decode:decoder(batch_errors()).
batch_errors_decoder() ->
gleam@dynamic@decode:field(
<<"object"/utf8>>,
{decoder, fun gleam@dynamic@decode:decode_string/1},
fun(Object) ->
gleam@dynamic@decode:field(
<<"data"/utf8>>,
gleam@dynamic@decode:list(batch_error_decoder()),
fun(Data) ->
gleam@dynamic@decode:success({batch_errors, Object, Data})
end
)
end
).
-file("src/glopenai/batch.gleam", 366).
-spec batch_request_counts_decoder() -> gleam@dynamic@decode:decoder(batch_request_counts()).
batch_request_counts_decoder() ->
gleam@dynamic@decode:field(
<<"total"/utf8>>,
{decoder, fun gleam@dynamic@decode:decode_int/1},
fun(Total) ->
gleam@dynamic@decode:field(
<<"completed"/utf8>>,
{decoder, fun gleam@dynamic@decode:decode_int/1},
fun(Completed) ->
gleam@dynamic@decode:field(
<<"failed"/utf8>>,
{decoder, fun gleam@dynamic@decode:decode_int/1},
fun(Failed) ->
gleam@dynamic@decode:success(
{batch_request_counts, Total, Completed, Failed}
)
end
)
end
)
end
).
-file("src/glopenai/batch.gleam", 377).
-spec batch_decoder() -> gleam@dynamic@decode:decoder(batch()).
batch_decoder() ->
gleam@dynamic@decode:field(
<<"id"/utf8>>,
{decoder, fun gleam@dynamic@decode:decode_string/1},
fun(Id) ->
gleam@dynamic@decode:field(
<<"object"/utf8>>,
{decoder, fun gleam@dynamic@decode:decode_string/1},
fun(Object) ->
gleam@dynamic@decode:field(
<<"endpoint"/utf8>>,
{decoder, fun gleam@dynamic@decode:decode_string/1},
fun(Endpoint) ->
gleam@dynamic@decode:optional_field(
<<"model"/utf8>>,
none,
gleam@dynamic@decode:optional(
{decoder,
fun gleam@dynamic@decode:decode_string/1}
),
fun(Model) ->
gleam@dynamic@decode:optional_field(
<<"errors"/utf8>>,
none,
gleam@dynamic@decode:optional(
batch_errors_decoder()
),
fun(Errors) ->
gleam@dynamic@decode:field(
<<"input_file_id"/utf8>>,
{decoder,
fun gleam@dynamic@decode:decode_string/1},
fun(Input_file_id) ->
gleam@dynamic@decode:field(
<<"completion_window"/utf8>>,
{decoder,
fun gleam@dynamic@decode:decode_string/1},
fun(Completion_window) ->
gleam@dynamic@decode:field(
<<"status"/utf8>>,
batch_status_decoder(
),
fun(Status) ->
gleam@dynamic@decode:optional_field(
<<"output_file_id"/utf8>>,
none,
gleam@dynamic@decode:optional(
{decoder,
fun gleam@dynamic@decode:decode_string/1}
),
fun(
Output_file_id
) ->
gleam@dynamic@decode:optional_field(
<<"error_file_id"/utf8>>,
none,
gleam@dynamic@decode:optional(
{decoder,
fun gleam@dynamic@decode:decode_string/1}
),
fun(
Error_file_id
) ->
gleam@dynamic@decode:field(
<<"created_at"/utf8>>,
{decoder,
fun gleam@dynamic@decode:decode_int/1},
fun(
Created_at
) ->
gleam@dynamic@decode:optional_field(
<<"in_progress_at"/utf8>>,
none,
gleam@dynamic@decode:optional(
{decoder,
fun gleam@dynamic@decode:decode_int/1}
),
fun(
In_progress_at
) ->
gleam@dynamic@decode:optional_field(
<<"expires_at"/utf8>>,
none,
gleam@dynamic@decode:optional(
{decoder,
fun gleam@dynamic@decode:decode_int/1}
),
fun(
Expires_at
) ->
gleam@dynamic@decode:optional_field(
<<"finalizing_at"/utf8>>,
none,
gleam@dynamic@decode:optional(
{decoder,
fun gleam@dynamic@decode:decode_int/1}
),
fun(
Finalizing_at
) ->
gleam@dynamic@decode:optional_field(
<<"completed_at"/utf8>>,
none,
gleam@dynamic@decode:optional(
{decoder,
fun gleam@dynamic@decode:decode_int/1}
),
fun(
Completed_at
) ->
gleam@dynamic@decode:optional_field(
<<"failed_at"/utf8>>,
none,
gleam@dynamic@decode:optional(
{decoder,
fun gleam@dynamic@decode:decode_int/1}
),
fun(
Failed_at
) ->
gleam@dynamic@decode:optional_field(
<<"expired_at"/utf8>>,
none,
gleam@dynamic@decode:optional(
{decoder,
fun gleam@dynamic@decode:decode_int/1}
),
fun(
Expired_at
) ->
gleam@dynamic@decode:optional_field(
<<"cancelling_at"/utf8>>,
none,
gleam@dynamic@decode:optional(
{decoder,
fun gleam@dynamic@decode:decode_int/1}
),
fun(
Cancelling_at
) ->
gleam@dynamic@decode:optional_field(
<<"cancelled_at"/utf8>>,
none,
gleam@dynamic@decode:optional(
{decoder,
fun gleam@dynamic@decode:decode_int/1}
),
fun(
Cancelled_at
) ->
gleam@dynamic@decode:optional_field(
<<"request_counts"/utf8>>,
none,
gleam@dynamic@decode:optional(
batch_request_counts_decoder(
)
),
fun(
Request_counts
) ->
gleam@dynamic@decode:optional_field(
<<"usage"/utf8>>,
none,
gleam@dynamic@decode:optional(
glopenai@shared:response_usage_decoder(
)
),
fun(
Usage
) ->
gleam@dynamic@decode:optional_field(
<<"metadata"/utf8>>,
none,
gleam@dynamic@decode:optional(
{decoder,
fun gleam@dynamic@decode:decode_dynamic/1}
),
fun(
Metadata
) ->
gleam@dynamic@decode:success(
{batch,
Id,
Object,
Endpoint,
Model,
Errors,
Input_file_id,
Completion_window,
Status,
Output_file_id,
Error_file_id,
Created_at,
In_progress_at,
Expires_at,
Finalizing_at,
Completed_at,
Failed_at,
Expired_at,
Cancelling_at,
Cancelled_at,
Request_counts,
Usage,
Metadata}
)
end
)
end
)
end
)
end
)
end
)
end
)
end
)
end
)
end
)
end
)
end
)
end
)
end
)
end
)
end
)
end
)
end
)
end
)
end
)
end
)
end
)
end
).
-file("src/glopenai/batch.gleam", 486).
-spec list_batches_response_decoder() -> gleam@dynamic@decode:decoder(list_batches_response()).
list_batches_response_decoder() ->
gleam@dynamic@decode:field(
<<"data"/utf8>>,
gleam@dynamic@decode:list(batch_decoder()),
fun(Data) ->
gleam@dynamic@decode:optional_field(
<<"first_id"/utf8>>,
none,
gleam@dynamic@decode:optional(
{decoder, fun gleam@dynamic@decode:decode_string/1}
),
fun(First_id) ->
gleam@dynamic@decode:optional_field(
<<"last_id"/utf8>>,
none,
gleam@dynamic@decode:optional(
{decoder, fun gleam@dynamic@decode:decode_string/1}
),
fun(Last_id) ->
gleam@dynamic@decode:field(
<<"has_more"/utf8>>,
{decoder,
fun gleam@dynamic@decode:decode_bool/1},
fun(Has_more) ->
gleam@dynamic@decode:field(
<<"object"/utf8>>,
{decoder,
fun gleam@dynamic@decode:decode_string/1},
fun(Object) ->
gleam@dynamic@decode:success(
{list_batches_response,
Data,
First_id,
Last_id,
Has_more,
Object}
)
end
)
end
)
end
)
end
)
end
).
-file("src/glopenai/batch.gleam", 509).
-spec batch_request_input_method_decoder() -> gleam@dynamic@decode:decoder(batch_request_input_method()).
batch_request_input_method_decoder() ->
gleam@dynamic@decode:then(
{decoder, fun gleam@dynamic@decode:decode_string/1},
fun(Value) -> case Value of
<<"POST"/utf8>> ->
gleam@dynamic@decode:success(post);
_ ->
gleam@dynamic@decode:failure(
post,
<<"BatchRequestInputMethod"/utf8>>
)
end end
).
-file("src/glopenai/batch.gleam", 519).
-spec batch_request_input_decoder() -> gleam@dynamic@decode:decoder(batch_request_input()).
batch_request_input_decoder() ->
gleam@dynamic@decode:field(
<<"custom_id"/utf8>>,
{decoder, fun gleam@dynamic@decode:decode_string/1},
fun(Custom_id) ->
gleam@dynamic@decode:field(
<<"method"/utf8>>,
batch_request_input_method_decoder(),
fun(Method) ->
gleam@dynamic@decode:field(
<<"url"/utf8>>,
batch_endpoint_decoder(),
fun(Url) ->
gleam@dynamic@decode:optional_field(
<<"body"/utf8>>,
none,
gleam@dynamic@decode:optional(
{decoder,
fun gleam@dynamic@decode:decode_dynamic/1}
),
fun(Body) ->
gleam@dynamic@decode:success(
{batch_request_input,
Custom_id,
Method,
Url,
Body}
)
end
)
end
)
end
)
end
).
-file("src/glopenai/batch.gleam", 536).
-spec batch_request_output_response_decoder() -> gleam@dynamic@decode:decoder(batch_request_output_response()).
batch_request_output_response_decoder() ->
gleam@dynamic@decode:field(
<<"status_code"/utf8>>,
{decoder, fun gleam@dynamic@decode:decode_int/1},
fun(Status_code) ->
gleam@dynamic@decode:field(
<<"request_id"/utf8>>,
{decoder, fun gleam@dynamic@decode:decode_string/1},
fun(Request_id) ->
gleam@dynamic@decode:field(
<<"body"/utf8>>,
{decoder, fun gleam@dynamic@decode:decode_dynamic/1},
fun(Body) ->
gleam@dynamic@decode:success(
{batch_request_output_response,
Status_code,
Request_id,
Body}
)
end
)
end
)
end
).
-file("src/glopenai/batch.gleam", 549).
-spec batch_request_output_error_decoder() -> gleam@dynamic@decode:decoder(batch_request_output_error()).
batch_request_output_error_decoder() ->
gleam@dynamic@decode:field(
<<"code"/utf8>>,
{decoder, fun gleam@dynamic@decode:decode_string/1},
fun(Code) ->
gleam@dynamic@decode:field(
<<"message"/utf8>>,
{decoder, fun gleam@dynamic@decode:decode_string/1},
fun(Message) ->
gleam@dynamic@decode:success(
{batch_request_output_error, Code, Message}
)
end
)
end
).
-file("src/glopenai/batch.gleam", 557).
-spec batch_request_output_decoder() -> gleam@dynamic@decode:decoder(batch_request_output()).
batch_request_output_decoder() ->
gleam@dynamic@decode:field(
<<"id"/utf8>>,
{decoder, fun gleam@dynamic@decode:decode_string/1},
fun(Id) ->
gleam@dynamic@decode:field(
<<"custom_id"/utf8>>,
{decoder, fun gleam@dynamic@decode:decode_string/1},
fun(Custom_id) ->
gleam@dynamic@decode:optional_field(
<<"response"/utf8>>,
none,
gleam@dynamic@decode:optional(
batch_request_output_response_decoder()
),
fun(Response) ->
gleam@dynamic@decode:optional_field(
<<"error"/utf8>>,
none,
gleam@dynamic@decode:optional(
batch_request_output_error_decoder()
),
fun(Error) ->
gleam@dynamic@decode:success(
{batch_request_output,
Id,
Custom_id,
Response,
Error}
)
end
)
end
)
end
)
end
).
-file("src/glopenai/batch.gleam", 583).
?DOC(" Build a request to create a new batch.\n").
-spec create_request(glopenai@config:config(), batch_request()) -> gleam@http@request:request(binary()).
create_request(Config, Params) ->
glopenai@internal:post_request(
Config,
<<"/batches"/utf8>>,
batch_request_to_json(Params)
).
-file("src/glopenai/batch.gleam", 588).
?DOC(" Parse the response from creating a batch.\n").
-spec create_response(gleam@http@response:response(binary())) -> {ok, batch()} |
{error, glopenai@error:glopenai_error()}.
create_response(Response) ->
glopenai@internal:parse_response(Response, batch_decoder()).
-file("src/glopenai/batch.gleam", 595).
?DOC(" Build a request to list batches.\n").
-spec list_request(glopenai@config:config()) -> gleam@http@request:request(binary()).
list_request(Config) ->
glopenai@internal:get_request(Config, <<"/batches"/utf8>>).
-file("src/glopenai/batch.gleam", 600).
?DOC(" Parse the response from listing batches.\n").
-spec list_response(gleam@http@response:response(binary())) -> {ok,
list_batches_response()} |
{error, glopenai@error:glopenai_error()}.
list_response(Response) ->
glopenai@internal:parse_response(Response, list_batches_response_decoder()).
-file("src/glopenai/batch.gleam", 607).
?DOC(" Build a request to retrieve a specific batch.\n").
-spec retrieve_request(glopenai@config:config(), binary()) -> gleam@http@request:request(binary()).
retrieve_request(Config, Batch_id) ->
glopenai@internal:get_request(Config, <<"/batches/"/utf8, Batch_id/binary>>).
-file("src/glopenai/batch.gleam", 612).
?DOC(" Parse the response from retrieving a batch.\n").
-spec retrieve_response(gleam@http@response:response(binary())) -> {ok, batch()} |
{error, glopenai@error:glopenai_error()}.
retrieve_response(Response) ->
glopenai@internal:parse_response(Response, batch_decoder()).
-file("src/glopenai/batch.gleam", 619).
?DOC(" Build a request to cancel a batch.\n").
-spec cancel_request(glopenai@config:config(), binary()) -> gleam@http@request:request(binary()).
cancel_request(Config, Batch_id) ->
glopenai@internal:post_request(
Config,
<<<<"/batches/"/utf8, Batch_id/binary>>/binary, "/cancel"/utf8>>,
gleam@json:object([])
).
-file("src/glopenai/batch.gleam", 629).
?DOC(" Parse the response from cancelling a batch.\n").
-spec cancel_response(gleam@http@response:response(binary())) -> {ok, batch()} |
{error, glopenai@error:glopenai_error()}.
cancel_response(Response) ->
glopenai@internal:parse_response(Response, batch_decoder()).