Current section
Files
Jump to
Current section
Files
src/gllm@types@chat_completion.erl
-module(gllm@types@chat_completion).
-compile([no_auto_import, nowarn_unused_vars, nowarn_unused_function, nowarn_nomatch, inline]).
-define(FILEPATH, "src/gllm/types/chat_completion.gleam").
-export([chat_completion_decoder/0, parse_chat_completion/1]).
-export_type([chat_completion/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.
?MODULEDOC(" This module defines the ChatCompletion type and parsing functionality for API responses.\n").
-type chat_completion() :: {chat_completion,
binary(),
binary(),
binary(),
binary(),
integer(),
list(gllm@types@choice:choice()),
gllm@types@usage:usage()}.
-file("src/gllm/types/chat_completion.gleam", 20).
-spec chat_completion_decoder() -> gleam@dynamic@decode:decoder(chat_completion()).
chat_completion_decoder() ->
gleam@dynamic@decode:field(
<<"id"/utf8>>,
{decoder, fun gleam@dynamic@decode:decode_string/1},
fun(Id) ->
gleam@dynamic@decode:field(
<<"provider"/utf8>>,
{decoder, fun gleam@dynamic@decode:decode_string/1},
fun(Provider) ->
gleam@dynamic@decode:field(
<<"model"/utf8>>,
{decoder, fun gleam@dynamic@decode:decode_string/1},
fun(Model) ->
gleam@dynamic@decode:field(
<<"object"/utf8>>,
{decoder,
fun gleam@dynamic@decode:decode_string/1},
fun(Object) ->
gleam@dynamic@decode:field(
<<"created"/utf8>>,
{decoder,
fun gleam@dynamic@decode:decode_int/1},
fun(Created) ->
gleam@dynamic@decode:field(
<<"choices"/utf8>>,
gleam@dynamic@decode:list(
gllm@types@choice:choice_decoder(
)
),
fun(Choices) ->
gleam@dynamic@decode:field(
<<"usage"/utf8>>,
gllm@types@usage:usage_decoder(
),
fun(Usage) ->
gleam@dynamic@decode:success(
{chat_completion,
Id,
Provider,
Model,
Object,
Created,
Choices,
Usage}
)
end
)
end
)
end
)
end
)
end
)
end
)
end
).
-file("src/gllm/types/chat_completion.gleam", 40).
?DOC(" Parses a JSON string into a ChatCompletion object.\n").
-spec parse_chat_completion(binary()) -> {ok, chat_completion()} |
{error, gleam@json:decode_error()}.
parse_chat_completion(Json_string) ->
gleam@json:parse(Json_string, chat_completion_decoder()).