-module(glopenai@shared). -compile([no_auto_import, nowarn_unused_vars, nowarn_unused_function, nowarn_nomatch, inline]). -define(FILEPATH, "src/glopenai/shared.gleam"). -export([image_detail_to_json/1, image_detail_decoder/0, image_url_to_json/1, image_url_decoder/0, function_object_to_json/1, function_object_decoder/0, function_call_to_json/1, function_call_decoder/0, function_name_to_json/1, function_name_decoder/0, reasoning_effort_to_json/1, reasoning_effort_decoder/0, response_format_json_schema_to_json/1, response_format_to_json/1, response_format_json_schema_decoder/0, response_format_decoder/0, prompt_tokens_details_to_json/1, completion_tokens_details_to_json/1, completion_usage_to_json/1, prompt_tokens_details_decoder/0, completion_tokens_details_decoder/0, completion_usage_decoder/0, response_usage_to_json/1, response_usage_decoder/0]). -export_type([image_detail/0, image_url/0, function_object/0, function_call/0, function_name/0, reasoning_effort/0, response_format_json_schema/0, response_format/0, prompt_tokens_details/0, completion_tokens_details/0, completion_usage/0, input_token_details/0, output_token_details/0, response_usage/0]). -type image_detail() :: auto | low | high | original. -type image_url() :: {image_url, binary(), gleam@option:option(image_detail())}. -type function_object() :: {function_object, binary(), gleam@option:option(binary()), gleam@option:option(gleam@dynamic:dynamic_()), gleam@option:option(boolean())}. -type function_call() :: {function_call, binary(), binary()}. -type function_name() :: {function_name, binary()}. -type reasoning_effort() :: reasoning_none | reasoning_minimal | reasoning_low | reasoning_medium | reasoning_high | reasoning_xhigh. -type response_format_json_schema() :: {response_format_json_schema, binary(), gleam@option:option(binary()), gleam@option:option(gleam@dynamic:dynamic_()), gleam@option:option(boolean())}. -type response_format() :: response_format_text | response_format_json_object | {response_format_json_schema_variant, response_format_json_schema()}. -type prompt_tokens_details() :: {prompt_tokens_details, gleam@option:option(integer()), gleam@option:option(integer())}. -type completion_tokens_details() :: {completion_tokens_details, gleam@option:option(integer()), gleam@option:option(integer()), gleam@option:option(integer()), gleam@option:option(integer())}. -type completion_usage() :: {completion_usage, integer(), integer(), integer(), gleam@option:option(prompt_tokens_details()), gleam@option:option(completion_tokens_details())}. -type input_token_details() :: {input_token_details, integer()}. -type output_token_details() :: {output_token_details, integer()}. -type response_usage() :: {response_usage, integer(), input_token_details(), integer(), output_token_details(), integer()}. -file("src/glopenai/shared.gleam", 17). -spec image_detail_to_json(image_detail()) -> gleam@json:json(). image_detail_to_json(Detail) -> gleam@json:string(case Detail of auto -> <<"auto"/utf8>>; low -> <<"low"/utf8>>; high -> <<"high"/utf8>>; original -> <<"original"/utf8>> end). -file("src/glopenai/shared.gleam", 26). -spec image_detail_decoder() -> gleam@dynamic@decode:decoder(image_detail()). image_detail_decoder() -> gleam@dynamic@decode:then( {decoder, fun gleam@dynamic@decode:decode_string/1}, fun(Value) -> case Value of <<"auto"/utf8>> -> gleam@dynamic@decode:success(auto); <<"low"/utf8>> -> gleam@dynamic@decode:success(low); <<"high"/utf8>> -> gleam@dynamic@decode:success(high); <<"original"/utf8>> -> gleam@dynamic@decode:success(original); _ -> gleam@dynamic@decode:failure(auto, <<"ImageDetail"/utf8>>) end end ). -file("src/glopenai/shared.gleam", 43). -spec image_url_to_json(image_url()) -> gleam@json:json(). image_url_to_json(Image_url) -> glopenai@internal@codec:object_with_optional( [{<<"url"/utf8>>, gleam@json:string(erlang:element(2, Image_url))}], [glopenai@internal@codec:optional_field( <<"detail"/utf8>>, erlang:element(3, Image_url), fun image_detail_to_json/1 )] ). -file("src/glopenai/shared.gleam", 49). -spec image_url_decoder() -> gleam@dynamic@decode:decoder(image_url()). image_url_decoder() -> gleam@dynamic@decode:field( <<"url"/utf8>>, {decoder, fun gleam@dynamic@decode:decode_string/1}, fun(Url) -> gleam@dynamic@decode:optional_field( <<"detail"/utf8>>, none, gleam@dynamic@decode:optional(image_detail_decoder()), fun(Detail) -> gleam@dynamic@decode:success({image_url, Url, Detail}) end ) end ). -file("src/glopenai/shared.gleam", 70). -spec function_object_to_json(function_object()) -> gleam@json:json(). function_object_to_json(Function) -> glopenai@internal@codec:object_with_optional( [{<<"name"/utf8>>, gleam@json:string(erlang:element(2, Function))}], [glopenai@internal@codec:optional_field( <<"description"/utf8>>, erlang:element(3, Function), fun gleam@json:string/1 ), glopenai@internal@codec:optional_field( <<"parameters"/utf8>>, erlang:element(4, Function), fun glopenai_codec_ffi:dynamic_to_json/1 ), glopenai@internal@codec:optional_field( <<"strict"/utf8>>, erlang:element(5, Function), fun gleam@json:bool/1 )] ). -file("src/glopenai/shared.gleam", 82). -spec function_object_decoder() -> gleam@dynamic@decode:decoder(function_object()). function_object_decoder() -> gleam@dynamic@decode:field( <<"name"/utf8>>, {decoder, fun gleam@dynamic@decode:decode_string/1}, fun(Name) -> gleam@dynamic@decode:optional_field( <<"description"/utf8>>, none, gleam@dynamic@decode:optional( {decoder, fun gleam@dynamic@decode:decode_string/1} ), fun(Description) -> gleam@dynamic@decode:optional_field( <<"parameters"/utf8>>, none, gleam@dynamic@decode:optional( {decoder, fun gleam@dynamic@decode:decode_dynamic/1} ), fun(Parameters) -> gleam@dynamic@decode:optional_field( <<"strict"/utf8>>, none, gleam@dynamic@decode:optional( {decoder, fun gleam@dynamic@decode:decode_bool/1} ), fun(Strict) -> gleam@dynamic@decode:success( {function_object, Name, Description, Parameters, Strict} ) end ) end ) end ) end ). -file("src/glopenai/shared.gleam", 113). -spec function_call_to_json(function_call()) -> gleam@json:json(). function_call_to_json(Call) -> gleam@json:object( [{<<"name"/utf8>>, gleam@json:string(erlang:element(2, Call))}, {<<"arguments"/utf8>>, gleam@json:string(erlang:element(3, Call))}] ). -file("src/glopenai/shared.gleam", 120). -spec function_call_decoder() -> gleam@dynamic@decode:decoder(function_call()). function_call_decoder() -> gleam@dynamic@decode:field( <<"name"/utf8>>, {decoder, fun gleam@dynamic@decode:decode_string/1}, fun(Name) -> gleam@dynamic@decode:field( <<"arguments"/utf8>>, {decoder, fun gleam@dynamic@decode:decode_string/1}, fun(Arguments) -> gleam@dynamic@decode:success( {function_call, Name, Arguments} ) end ) end ). -file("src/glopenai/shared.gleam", 132). -spec function_name_to_json(function_name()) -> gleam@json:json(). function_name_to_json(Function_name) -> gleam@json:object( [{<<"name"/utf8>>, gleam@json:string(erlang:element(2, Function_name))}] ). -file("src/glopenai/shared.gleam", 136). -spec function_name_decoder() -> gleam@dynamic@decode:decoder(function_name()). function_name_decoder() -> gleam@dynamic@decode:field( <<"name"/utf8>>, {decoder, fun gleam@dynamic@decode:decode_string/1}, fun(Name) -> gleam@dynamic@decode:success({function_name, Name}) end ). -file("src/glopenai/shared.gleam", 152). -spec reasoning_effort_to_json(reasoning_effort()) -> gleam@json:json(). reasoning_effort_to_json(Effort) -> gleam@json:string(case Effort of reasoning_none -> <<"none"/utf8>>; reasoning_minimal -> <<"minimal"/utf8>>; reasoning_low -> <<"low"/utf8>>; reasoning_medium -> <<"medium"/utf8>>; reasoning_high -> <<"high"/utf8>>; reasoning_xhigh -> <<"xhigh"/utf8>> end). -file("src/glopenai/shared.gleam", 163). -spec reasoning_effort_decoder() -> gleam@dynamic@decode:decoder(reasoning_effort()). reasoning_effort_decoder() -> gleam@dynamic@decode:then( {decoder, fun gleam@dynamic@decode:decode_string/1}, fun(Value) -> case Value of <<"none"/utf8>> -> gleam@dynamic@decode:success(reasoning_none); <<"minimal"/utf8>> -> gleam@dynamic@decode:success(reasoning_minimal); <<"low"/utf8>> -> gleam@dynamic@decode:success(reasoning_low); <<"medium"/utf8>> -> gleam@dynamic@decode:success(reasoning_medium); <<"high"/utf8>> -> gleam@dynamic@decode:success(reasoning_high); <<"xhigh"/utf8>> -> gleam@dynamic@decode:success(reasoning_xhigh); _ -> gleam@dynamic@decode:failure( reasoning_medium, <<"ReasoningEffort"/utf8>> ) end end ). -file("src/glopenai/shared.gleam", 206). -spec response_format_json_schema_to_json(response_format_json_schema()) -> gleam@json:json(). response_format_json_schema_to_json(Schema) -> glopenai@internal@codec:object_with_optional( [{<<"name"/utf8>>, gleam@json:string(erlang:element(2, Schema))}], [glopenai@internal@codec:optional_field( <<"description"/utf8>>, erlang:element(3, Schema), fun gleam@json:string/1 ), glopenai@internal@codec:optional_field( <<"schema"/utf8>>, erlang:element(4, Schema), fun glopenai_codec_ffi:dynamic_to_json/1 ), glopenai@internal@codec:optional_field( <<"strict"/utf8>>, erlang:element(5, Schema), fun gleam@json:bool/1 )] ). -file("src/glopenai/shared.gleam", 193). -spec response_format_to_json(response_format()) -> gleam@json:json(). response_format_to_json(Format) -> case Format of response_format_text -> gleam@json:object( [{<<"type"/utf8>>, gleam@json:string(<<"text"/utf8>>)}] ); response_format_json_object -> gleam@json:object( [{<<"type"/utf8>>, gleam@json:string(<<"json_object"/utf8>>)}] ); {response_format_json_schema_variant, Schema} -> gleam@json:object( [{<<"type"/utf8>>, gleam@json:string(<<"json_schema"/utf8>>)}, {<<"json_schema"/utf8>>, response_format_json_schema_to_json(Schema)}] ) end. -file("src/glopenai/shared.gleam", 232). -spec response_format_json_schema_decoder() -> gleam@dynamic@decode:decoder(response_format_json_schema()). response_format_json_schema_decoder() -> gleam@dynamic@decode:field( <<"name"/utf8>>, {decoder, fun gleam@dynamic@decode:decode_string/1}, fun(Name) -> gleam@dynamic@decode:optional_field( <<"description"/utf8>>, none, gleam@dynamic@decode:optional( {decoder, fun gleam@dynamic@decode:decode_string/1} ), fun(Description) -> gleam@dynamic@decode:optional_field( <<"schema"/utf8>>, none, gleam@dynamic@decode:optional( {decoder, fun gleam@dynamic@decode:decode_dynamic/1} ), fun(Schema) -> gleam@dynamic@decode:optional_field( <<"strict"/utf8>>, none, gleam@dynamic@decode:optional( {decoder, fun gleam@dynamic@decode:decode_bool/1} ), fun(Strict) -> gleam@dynamic@decode:success( {response_format_json_schema, Name, Description, Schema, Strict} ) end ) end ) end ) end ). -file("src/glopenai/shared.gleam", 216). -spec response_format_decoder() -> gleam@dynamic@decode:decoder(response_format()). response_format_decoder() -> gleam@dynamic@decode:field( <<"type"/utf8>>, {decoder, fun gleam@dynamic@decode:decode_string/1}, fun(Tag) -> case Tag of <<"text"/utf8>> -> gleam@dynamic@decode:success(response_format_text); <<"json_object"/utf8>> -> gleam@dynamic@decode:success(response_format_json_object); <<"json_schema"/utf8>> -> gleam@dynamic@decode:field( <<"json_schema"/utf8>>, response_format_json_schema_decoder(), fun(Schema) -> gleam@dynamic@decode:success( {response_format_json_schema_variant, Schema} ) end ); _ -> gleam@dynamic@decode:failure( response_format_text, <<"ResponseFormat"/utf8>> ) end end ). -file("src/glopenai/shared.gleam", 306). -spec prompt_tokens_details_to_json(prompt_tokens_details()) -> gleam@json:json(). prompt_tokens_details_to_json(Details) -> gleam@json:object( [{<<"audio_tokens"/utf8>>, gleam@json:nullable( erlang:element(2, Details), fun gleam@json:int/1 )}, {<<"cached_tokens"/utf8>>, gleam@json:nullable( erlang:element(3, Details), fun gleam@json:int/1 )}] ). -file("src/glopenai/shared.gleam", 313). -spec completion_tokens_details_to_json(completion_tokens_details()) -> gleam@json:json(). completion_tokens_details_to_json(Details) -> gleam@json:object( [{<<"accepted_prediction_tokens"/utf8>>, gleam@json:nullable( erlang:element(2, Details), fun gleam@json:int/1 )}, {<<"audio_tokens"/utf8>>, gleam@json:nullable( erlang:element(3, Details), fun gleam@json:int/1 )}, {<<"reasoning_tokens"/utf8>>, gleam@json:nullable( erlang:element(4, Details), fun gleam@json:int/1 )}, {<<"rejected_prediction_tokens"/utf8>>, gleam@json:nullable( erlang:element(5, Details), fun gleam@json:int/1 )}] ). -file("src/glopenai/shared.gleam", 284). -spec completion_usage_to_json(completion_usage()) -> gleam@json:json(). completion_usage_to_json(Usage) -> glopenai@internal@codec:object_with_optional( [{<<"prompt_tokens"/utf8>>, gleam@json:int(erlang:element(2, Usage))}, {<<"completion_tokens"/utf8>>, gleam@json:int(erlang:element(3, Usage))}, {<<"total_tokens"/utf8>>, gleam@json:int(erlang:element(4, Usage))}], [glopenai@internal@codec:optional_field( <<"prompt_tokens_details"/utf8>>, erlang:element(5, Usage), fun prompt_tokens_details_to_json/1 ), glopenai@internal@codec:optional_field( <<"completion_tokens_details"/utf8>>, erlang:element(6, Usage), fun completion_tokens_details_to_json/1 )] ). -file("src/glopenai/shared.gleam", 353). -spec prompt_tokens_details_decoder() -> gleam@dynamic@decode:decoder(prompt_tokens_details()). prompt_tokens_details_decoder() -> gleam@dynamic@decode:optional_field( <<"audio_tokens"/utf8>>, none, gleam@dynamic@decode:optional( {decoder, fun gleam@dynamic@decode:decode_int/1} ), fun(Audio_tokens) -> gleam@dynamic@decode:optional_field( <<"cached_tokens"/utf8>>, none, gleam@dynamic@decode:optional( {decoder, fun gleam@dynamic@decode:decode_int/1} ), fun(Cached_tokens) -> gleam@dynamic@decode:success( {prompt_tokens_details, Audio_tokens, Cached_tokens} ) end ) end ). -file("src/glopenai/shared.gleam", 370). -spec completion_tokens_details_decoder() -> gleam@dynamic@decode:decoder(completion_tokens_details()). completion_tokens_details_decoder() -> gleam@dynamic@decode:optional_field( <<"accepted_prediction_tokens"/utf8>>, none, gleam@dynamic@decode:optional( {decoder, fun gleam@dynamic@decode:decode_int/1} ), fun(Accepted_prediction_tokens) -> gleam@dynamic@decode:optional_field( <<"audio_tokens"/utf8>>, none, gleam@dynamic@decode:optional( {decoder, fun gleam@dynamic@decode:decode_int/1} ), fun(Audio_tokens) -> gleam@dynamic@decode:optional_field( <<"reasoning_tokens"/utf8>>, none, gleam@dynamic@decode:optional( {decoder, fun gleam@dynamic@decode:decode_int/1} ), fun(Reasoning_tokens) -> gleam@dynamic@decode:optional_field( <<"rejected_prediction_tokens"/utf8>>, none, gleam@dynamic@decode:optional( {decoder, fun gleam@dynamic@decode:decode_int/1} ), fun(Rejected_prediction_tokens) -> gleam@dynamic@decode:success( {completion_tokens_details, Accepted_prediction_tokens, Audio_tokens, Reasoning_tokens, Rejected_prediction_tokens} ) end ) end ) end ) end ). -file("src/glopenai/shared.gleam", 330). -spec completion_usage_decoder() -> gleam@dynamic@decode:decoder(completion_usage()). completion_usage_decoder() -> gleam@dynamic@decode:field( <<"prompt_tokens"/utf8>>, {decoder, fun gleam@dynamic@decode:decode_int/1}, fun(Prompt_tokens) -> gleam@dynamic@decode:field( <<"completion_tokens"/utf8>>, {decoder, fun gleam@dynamic@decode:decode_int/1}, fun(Completion_tokens) -> gleam@dynamic@decode:field( <<"total_tokens"/utf8>>, {decoder, fun gleam@dynamic@decode:decode_int/1}, fun(Total_tokens) -> gleam@dynamic@decode:optional_field( <<"prompt_tokens_details"/utf8>>, none, gleam@dynamic@decode:optional( prompt_tokens_details_decoder() ), fun(Prompt_tokens_details) -> gleam@dynamic@decode:optional_field( <<"completion_tokens_details"/utf8>>, none, gleam@dynamic@decode:optional( completion_tokens_details_decoder() ), fun(Completion_tokens_details) -> gleam@dynamic@decode:success( {completion_usage, Prompt_tokens, Completion_tokens, Total_tokens, Prompt_tokens_details, Completion_tokens_details} ) end ) end ) end ) end ) end ). -file("src/glopenai/shared.gleam", 421). -spec response_usage_to_json(response_usage()) -> gleam@json:json(). response_usage_to_json(Usage) -> gleam@json:object( [{<<"input_tokens"/utf8>>, gleam@json:int(erlang:element(2, Usage))}, {<<"input_tokens_details"/utf8>>, gleam@json:object( [{<<"cached_tokens"/utf8>>, gleam@json:int( erlang:element(2, erlang:element(3, Usage)) )}] )}, {<<"output_tokens"/utf8>>, gleam@json:int(erlang:element(4, Usage))}, {<<"output_tokens_details"/utf8>>, gleam@json:object( [{<<"reasoning_tokens"/utf8>>, gleam@json:int( erlang:element(2, erlang:element(5, Usage)) )}] )}, {<<"total_tokens"/utf8>>, gleam@json:int(erlang:element(6, Usage))}] ). -file("src/glopenai/shared.gleam", 465). -spec input_token_details_decoder() -> gleam@dynamic@decode:decoder(input_token_details()). input_token_details_decoder() -> gleam@dynamic@decode:field( <<"cached_tokens"/utf8>>, {decoder, fun gleam@dynamic@decode:decode_int/1}, fun(Cached_tokens) -> gleam@dynamic@decode:success({input_token_details, Cached_tokens}) end ). -file("src/glopenai/shared.gleam", 470). -spec output_token_details_decoder() -> gleam@dynamic@decode:decoder(output_token_details()). output_token_details_decoder() -> gleam@dynamic@decode:field( <<"reasoning_tokens"/utf8>>, {decoder, fun gleam@dynamic@decode:decode_int/1}, fun(Reasoning_tokens) -> gleam@dynamic@decode:success( {output_token_details, Reasoning_tokens} ) end ). -file("src/glopenai/shared.gleam", 444). -spec response_usage_decoder() -> gleam@dynamic@decode:decoder(response_usage()). response_usage_decoder() -> gleam@dynamic@decode:field( <<"input_tokens"/utf8>>, {decoder, fun gleam@dynamic@decode:decode_int/1}, fun(Input_tokens) -> gleam@dynamic@decode:field( <<"input_tokens_details"/utf8>>, input_token_details_decoder(), fun(Input_tokens_details) -> gleam@dynamic@decode:field( <<"output_tokens"/utf8>>, {decoder, fun gleam@dynamic@decode:decode_int/1}, fun(Output_tokens) -> gleam@dynamic@decode:field( <<"output_tokens_details"/utf8>>, output_token_details_decoder(), fun(Output_tokens_details) -> gleam@dynamic@decode:field( <<"total_tokens"/utf8>>, {decoder, fun gleam@dynamic@decode:decode_int/1}, fun(Total_tokens) -> gleam@dynamic@decode:success( {response_usage, Input_tokens, Input_tokens_details, Output_tokens, Output_tokens_details, Total_tokens} ) end ) end ) end ) end ) end ).