Current section
Files
Jump to
Current section
Files
src/gopenai@model.erl
-module(gopenai@model).
-compile([no_auto_import, nowarn_unused_vars, nowarn_unused_function, nowarn_nomatch]).
-export([model_to_json/1, model_from_json/1]).
-export_type([model/0]).
-type model() :: gpt3_dot5_turbo |
gpt4 |
gpt4o |
text_embedding_ada002 |
llama2 |
gemma |
qwen2_large |
qwen2 |
qwen2_small |
qwen2_tiny |
l_la_ma3_size8b |
l_la_ma3_size70b.
-spec model_to_json(model()) -> gleam@json:json().
model_to_json(M) ->
_pipe = case M of
gpt3_dot5_turbo ->
<<"gpt-3.5-turbo"/utf8>>;
gpt4 ->
<<"gpt-4"/utf8>>;
gpt4o ->
<<"gpt-4o"/utf8>>;
text_embedding_ada002 ->
<<"text-embedding-ada-002"/utf8>>;
llama2 ->
<<"llama2"/utf8>>;
gemma ->
<<"gemma"/utf8>>;
qwen2_large ->
<<"qwen2:72b"/utf8>>;
qwen2 ->
<<"qwen2"/utf8>>;
qwen2_small ->
<<"qwen2:1.5b"/utf8>>;
qwen2_tiny ->
<<"qwen2:0.5b"/utf8>>;
l_la_ma3_size8b ->
<<"llama3-8b-8192"/utf8>>;
l_la_ma3_size70b ->
<<"llama3-70b-8192"/utf8>>
end,
gleam@json:string(_pipe).
-spec model_from_json(gleam@dynamic:dynamic_()) -> {ok, model()} |
{error, list(gleam@dynamic:decode_error())}.
model_from_json(Data) ->
case gleam@dynamic:string(Data) of
{ok, Str} ->
case Str of
<<"gpt-3.5-turbo"/utf8>> ->
{ok, gpt3_dot5_turbo};
<<"gpt-4"/utf8>> ->
{ok, gpt4};
<<"text-embedding-ada-002"/utf8>> ->
{ok, text_embedding_ada002};
Default ->
{error,
[{decode_error, <<"valid model"/utf8>>, Default, []}]}
end;
{error, E} ->
{error, E}
end.