Packages

Gleam SDK for Dagger — type-safe pipelines via GraphQL codegen

Current section

Files

Jump to
dagger_gleam src dagger@dsl@l_l_m.erl
Raw

src/dagger@dsl@l_l_m.erl

-module(dagger@dsl@l_l_m).
-compile([no_auto_import, nowarn_unused_vars, nowarn_unused_function, nowarn_nomatch, inline]).
-define(FILEPATH, "src/dagger/dsl/l_l_m.gleam").
-export([none/1, opt_model/2, max_a_p_i_calls/2, l_l_m/1, attempt/2, bind_result/2, env/1, has_prompt/3, history/3, history_j_s_o_n/3, id/1, last_reply/3, loop/1, model/3, provider/3, step/1, sync/1, token_usage/1, tools/3, with_blocked_function/3, with_env/2, with_m_c_p_server/3, with_model/2, with_prompt/2, with_prompt_file/2, with_static_tools/1, with_system_prompt/2, without_default_system_prompt/1, without_message_history/1, without_system_prompts/1]).
-export_type([opts/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 opts() :: {opts,
gleam@option:option(binary()),
gleam@option:option(integer())}.
-file("src/dagger/dsl/l_l_m.gleam", 17).
-spec defaults() -> opts().
defaults() ->
{opts, none, none}.
-file("src/dagger/dsl/l_l_m.gleam", 24).
-spec none(opts()) -> opts().
none(Opts) ->
Opts.
-file("src/dagger/dsl/l_l_m.gleam", 28).
-spec opt_model(opts(), binary()) -> opts().
opt_model(Opts, Val) ->
{opts, {some, Val}, erlang:element(3, Opts)}.
-file("src/dagger/dsl/l_l_m.gleam", 32).
-spec max_a_p_i_calls(opts(), integer()) -> opts().
max_a_p_i_calls(Opts, Val) ->
{opts, erlang:element(2, Opts), {some, Val}}.
-file("src/dagger/dsl/l_l_m.gleam", 36).
-spec encode_l_l_m(opts()) -> list({binary(), dagger@types:value()}).
encode_l_l_m(Opts) ->
gleam@list:filter_map([case erlang:element(2, Opts) of
{some, Val} ->
{ok, {<<"model"/utf8>>, {g_string, Val}}};
none ->
{error, nil}
end, case erlang:element(3, Opts) of
{some, Val@1} ->
{ok, {<<"maxAPICalls"/utf8>>, {g_int, Val@1}}};
none ->
{error, nil}
end], fun(X) -> X end).
-file("src/dagger/dsl/l_l_m.gleam", 49).
-spec l_l_m(fun((opts()) -> opts())) -> dagger@dsl@types:l_l_m().
l_l_m(With_fn) ->
Opts = With_fn(defaults()),
Field = {field, <<"llm"/utf8>>, encode_l_l_m(Opts), []},
{l_l_m, {pure, [Field]}}.
-file("src/dagger/dsl/l_l_m.gleam", 56).
?DOC(" create a branch in the LLM's history\n").
-spec attempt(dagger@dsl@types:l_l_m(), integer()) -> dagger@dsl@types:l_l_m().
attempt(Parent, Number) ->
Field = {field,
<<"attempt"/utf8>>,
[{<<"number"/utf8>>, {g_int, Number}}],
[]},
New_op = begin
dagger@types:bind(
erlang:element(2, Parent),
fun(Q) -> {pure, lists:append(Q, [Field])} end
)
end,
{l_l_m, New_op}.
-file("src/dagger/dsl/l_l_m.gleam", 66).
?DOC(" returns the type of the current state\n").
-spec bind_result(dagger@dsl@types:l_l_m(), binary()) -> dagger@dsl@types:binding().
bind_result(Parent, Name) ->
Field = {field,
<<"bindResult"/utf8>>,
[{<<"name"/utf8>>, {g_string, Name}}],
[]},
New_op = begin
dagger@types:bind(
erlang:element(2, Parent),
fun(Q) -> {pure, lists:append(Q, [Field])} end
)
end,
{binding, New_op}.
-file("src/dagger/dsl/l_l_m.gleam", 76).
?DOC(" return the LLM's current environment\n").
-spec env(dagger@dsl@types:l_l_m()) -> dagger@dsl@types:env().
env(Parent) ->
Field = {field, <<"env"/utf8>>, [], []},
New_op = begin
dagger@types:bind(
erlang:element(2, Parent),
fun(Q) -> {pure, lists:append(Q, [Field])} end
)
end,
{env, New_op}.
-file("src/dagger/dsl/l_l_m.gleam", 86).
?DOC(" Indicates whether there are any queued prompts or tool results to send to the model\n").
-spec has_prompt(
dagger@dsl@types:l_l_m(),
dagger@types:client(),
fun(({ok, boolean()} | {error, dagger@types:query_error()}) -> TYI)
) -> TYI.
has_prompt(Parent, Client, Handler) ->
Field = {field, <<"hasPrompt"/utf8>>, [], []},
Op = begin
dagger@types:bind(
erlang:element(2, Parent),
fun(Q) ->
Full_query = lists:append(Q, [Field]),
{fetch,
Full_query,
{decoder, fun gleam@dynamic@decode:decode_dynamic/1},
fun(Dyn) ->
Path = dagger@types:make_path(Full_query),
case gleam@dynamic@decode:run(
Dyn,
gleam@dynamic@decode:at(
Path,
{decoder,
fun gleam@dynamic@decode:decode_bool/1}
)
) of
{ok, Val} ->
{pure, {ok, Val}};
{error, _} ->
{pure,
{error,
{decoding_error, <<"hasPrompt"/utf8>>}}}
end
end}
end
)
end,
Handler(dagger@interpreter:run(Op, Client)).
-file("src/dagger/dsl/l_l_m.gleam", 107).
?DOC(" return the llm message history\n").
-spec history(
dagger@dsl@types:l_l_m(),
dagger@types:client(),
fun(({ok, list(binary())} | {error, dagger@types:query_error()}) -> TYL)
) -> TYL.
history(Parent, Client, Handler) ->
Field = {field, <<"history"/utf8>>, [], []},
Op = begin
dagger@types:bind(
erlang:element(2, Parent),
fun(Q) ->
Full_query = lists:append(Q, [Field]),
{fetch,
Full_query,
{decoder, fun gleam@dynamic@decode:decode_dynamic/1},
fun(Dyn) ->
Path = dagger@types:make_path(Full_query),
case gleam@dynamic@decode:run(
Dyn,
gleam@dynamic@decode:at(
Path,
gleam@dynamic@decode:list(
{decoder,
fun gleam@dynamic@decode:decode_string/1}
)
)
) of
{ok, Val} ->
{pure, {ok, Val}};
{error, _} ->
{pure,
{error,
{decoding_error, <<"history"/utf8>>}}}
end
end}
end
)
end,
Handler(dagger@interpreter:run(Op, Client)).
-file("src/dagger/dsl/l_l_m.gleam", 128).
?DOC(" return the raw llm message history as json\n").
-spec history_j_s_o_n(
dagger@dsl@types:l_l_m(),
dagger@types:client(),
fun(({ok, binary()} | {error, dagger@types:query_error()}) -> TYN)
) -> TYN.
history_j_s_o_n(Parent, Client, Handler) ->
Field = {field, <<"historyJSON"/utf8>>, [], []},
Op = begin
dagger@types:bind(
erlang:element(2, Parent),
fun(Q) ->
Full_query = lists:append(Q, [Field]),
{fetch,
Full_query,
{decoder, fun gleam@dynamic@decode:decode_dynamic/1},
fun(Dyn) ->
Path = dagger@types:make_path(Full_query),
case gleam@dynamic@decode:run(
Dyn,
gleam@dynamic@decode:at(
Path,
{decoder,
fun gleam@dynamic@decode:decode_string/1}
)
) of
{ok, Val} ->
{pure, {ok, Val}};
{error, _} ->
{pure,
{error,
{decoding_error, <<"historyJSON"/utf8>>}}}
end
end}
end
)
end,
Handler(dagger@interpreter:run(Op, Client)).
-file("src/dagger/dsl/l_l_m.gleam", 149).
?DOC(" A unique identifier for this LLM.\n").
-spec id(dagger@dsl@types:l_l_m()) -> dagger@dsl@types:l_l_m().
id(Parent) ->
Field = {field, <<"id"/utf8>>, [], []},
New_op = begin
dagger@types:bind(
erlang:element(2, Parent),
fun(Q) -> {pure, lists:append(Q, [Field])} end
)
end,
{l_l_m, New_op}.
-file("src/dagger/dsl/l_l_m.gleam", 159).
?DOC(" return the last llm reply from the history\n").
-spec last_reply(
dagger@dsl@types:l_l_m(),
dagger@types:client(),
fun(({ok, binary()} | {error, dagger@types:query_error()}) -> TYP)
) -> TYP.
last_reply(Parent, Client, Handler) ->
Field = {field, <<"lastReply"/utf8>>, [], []},
Op = begin
dagger@types:bind(
erlang:element(2, Parent),
fun(Q) ->
Full_query = lists:append(Q, [Field]),
{fetch,
Full_query,
{decoder, fun gleam@dynamic@decode:decode_dynamic/1},
fun(Dyn) ->
Path = dagger@types:make_path(Full_query),
case gleam@dynamic@decode:run(
Dyn,
gleam@dynamic@decode:at(
Path,
{decoder,
fun gleam@dynamic@decode:decode_string/1}
)
) of
{ok, Val} ->
{pure, {ok, Val}};
{error, _} ->
{pure,
{error,
{decoding_error, <<"lastReply"/utf8>>}}}
end
end}
end
)
end,
Handler(dagger@interpreter:run(Op, Client)).
-file("src/dagger/dsl/l_l_m.gleam", 180).
?DOC(" Submit the queued prompt, evaluate any tool calls, queue their results, and keep going until the model ends its turn\n").
-spec loop(dagger@dsl@types:l_l_m()) -> dagger@dsl@types:l_l_m().
loop(Parent) ->
Field = {field, <<"loop"/utf8>>, [], []},
New_op = begin
dagger@types:bind(
erlang:element(2, Parent),
fun(Q) -> {pure, lists:append(Q, [Field])} end
)
end,
{l_l_m, New_op}.
-file("src/dagger/dsl/l_l_m.gleam", 190).
?DOC(" return the model used by the llm\n").
-spec model(
dagger@dsl@types:l_l_m(),
dagger@types:client(),
fun(({ok, binary()} | {error, dagger@types:query_error()}) -> TYR)
) -> TYR.
model(Parent, Client, Handler) ->
Field = {field, <<"model"/utf8>>, [], []},
Op = begin
dagger@types:bind(
erlang:element(2, Parent),
fun(Q) ->
Full_query = lists:append(Q, [Field]),
{fetch,
Full_query,
{decoder, fun gleam@dynamic@decode:decode_dynamic/1},
fun(Dyn) ->
Path = dagger@types:make_path(Full_query),
case gleam@dynamic@decode:run(
Dyn,
gleam@dynamic@decode:at(
Path,
{decoder,
fun gleam@dynamic@decode:decode_string/1}
)
) of
{ok, Val} ->
{pure, {ok, Val}};
{error, _} ->
{pure,
{error, {decoding_error, <<"model"/utf8>>}}}
end
end}
end
)
end,
Handler(dagger@interpreter:run(Op, Client)).
-file("src/dagger/dsl/l_l_m.gleam", 211).
?DOC(" return the provider used by the llm\n").
-spec provider(
dagger@dsl@types:l_l_m(),
dagger@types:client(),
fun(({ok, binary()} | {error, dagger@types:query_error()}) -> TYT)
) -> TYT.
provider(Parent, Client, Handler) ->
Field = {field, <<"provider"/utf8>>, [], []},
Op = begin
dagger@types:bind(
erlang:element(2, Parent),
fun(Q) ->
Full_query = lists:append(Q, [Field]),
{fetch,
Full_query,
{decoder, fun gleam@dynamic@decode:decode_dynamic/1},
fun(Dyn) ->
Path = dagger@types:make_path(Full_query),
case gleam@dynamic@decode:run(
Dyn,
gleam@dynamic@decode:at(
Path,
{decoder,
fun gleam@dynamic@decode:decode_string/1}
)
) of
{ok, Val} ->
{pure, {ok, Val}};
{error, _} ->
{pure,
{error,
{decoding_error, <<"provider"/utf8>>}}}
end
end}
end
)
end,
Handler(dagger@interpreter:run(Op, Client)).
-file("src/dagger/dsl/l_l_m.gleam", 232).
?DOC(" Submit the queued prompt or tool call results, evaluate any tool calls, and queue their results\n").
-spec step(dagger@dsl@types:l_l_m()) -> dagger@dsl@types:l_l_m().
step(Parent) ->
Field = {field, <<"step"/utf8>>, [], []},
New_op = begin
dagger@types:bind(
erlang:element(2, Parent),
fun(Q) -> {pure, lists:append(Q, [Field])} end
)
end,
{l_l_m, New_op}.
-file("src/dagger/dsl/l_l_m.gleam", 242).
?DOC(" synchronize LLM state\n").
-spec sync(dagger@dsl@types:l_l_m()) -> dagger@dsl@types:l_l_m().
sync(Parent) ->
Field = {field, <<"sync"/utf8>>, [], []},
New_op = begin
dagger@types:bind(
erlang:element(2, Parent),
fun(Q) -> {pure, lists:append(Q, [Field])} end
)
end,
{l_l_m, New_op}.
-file("src/dagger/dsl/l_l_m.gleam", 252).
?DOC(" returns the token usage of the current state\n").
-spec token_usage(dagger@dsl@types:l_l_m()) -> dagger@dsl@types:l_l_m_token_usage().
token_usage(Parent) ->
Field = {field, <<"tokenUsage"/utf8>>, [], []},
New_op = begin
dagger@types:bind(
erlang:element(2, Parent),
fun(Q) -> {pure, lists:append(Q, [Field])} end
)
end,
{l_l_m_token_usage, New_op}.
-file("src/dagger/dsl/l_l_m.gleam", 262).
?DOC(" print documentation for available tools\n").
-spec tools(
dagger@dsl@types:l_l_m(),
dagger@types:client(),
fun(({ok, binary()} | {error, dagger@types:query_error()}) -> TYV)
) -> TYV.
tools(Parent, Client, Handler) ->
Field = {field, <<"tools"/utf8>>, [], []},
Op = begin
dagger@types:bind(
erlang:element(2, Parent),
fun(Q) ->
Full_query = lists:append(Q, [Field]),
{fetch,
Full_query,
{decoder, fun gleam@dynamic@decode:decode_dynamic/1},
fun(Dyn) ->
Path = dagger@types:make_path(Full_query),
case gleam@dynamic@decode:run(
Dyn,
gleam@dynamic@decode:at(
Path,
{decoder,
fun gleam@dynamic@decode:decode_string/1}
)
) of
{ok, Val} ->
{pure, {ok, Val}};
{error, _} ->
{pure,
{error, {decoding_error, <<"tools"/utf8>>}}}
end
end}
end
)
end,
Handler(dagger@interpreter:run(Op, Client)).
-file("src/dagger/dsl/l_l_m.gleam", 283).
?DOC(" Return a new LLM with the specified function no longer exposed as a tool\n").
-spec with_blocked_function(dagger@dsl@types:l_l_m(), binary(), binary()) -> dagger@dsl@types:l_l_m().
with_blocked_function(Parent, Type_name, Function) ->
Field = {field,
<<"withBlockedFunction"/utf8>>,
[{<<"typeName"/utf8>>, {g_string, Type_name}},
{<<"function"/utf8>>, {g_string, Function}}],
[]},
New_op = begin
dagger@types:bind(
erlang:element(2, Parent),
fun(Q) -> {pure, lists:append(Q, [Field])} end
)
end,
{l_l_m, New_op}.
-file("src/dagger/dsl/l_l_m.gleam", 293).
?DOC(" allow the LLM to interact with an environment via MCP\n").
-spec with_env(dagger@dsl@types:l_l_m(), dagger@dsl@types:env()) -> dagger@dsl@types:l_l_m().
with_env(Parent, Env) ->
Field = {field,
<<"withEnv"/utf8>>,
[{<<"env"/utf8>>, {g_deferred, erlang:element(2, Env)}}],
[]},
New_op = begin
dagger@types:bind(
erlang:element(2, Parent),
fun(Q) -> {pure, lists:append(Q, [Field])} end
)
end,
{l_l_m, New_op}.
-file("src/dagger/dsl/l_l_m.gleam", 303).
?DOC(" Add an external MCP server to the LLM\n").
-spec with_m_c_p_server(
dagger@dsl@types:l_l_m(),
binary(),
dagger@dsl@types:service()
) -> dagger@dsl@types:l_l_m().
with_m_c_p_server(Parent, Name, Service) ->
Field = {field,
<<"withMCPServer"/utf8>>,
[{<<"name"/utf8>>, {g_string, Name}},
{<<"service"/utf8>>, {g_deferred, erlang:element(2, Service)}}],
[]},
New_op = begin
dagger@types:bind(
erlang:element(2, Parent),
fun(Q) -> {pure, lists:append(Q, [Field])} end
)
end,
{l_l_m, New_op}.
-file("src/dagger/dsl/l_l_m.gleam", 313).
?DOC(" swap out the llm model\n").
-spec with_model(dagger@dsl@types:l_l_m(), binary()) -> dagger@dsl@types:l_l_m().
with_model(Parent, Model) ->
Field = {field,
<<"withModel"/utf8>>,
[{<<"model"/utf8>>, {g_string, Model}}],
[]},
New_op = begin
dagger@types:bind(
erlang:element(2, Parent),
fun(Q) -> {pure, lists:append(Q, [Field])} end
)
end,
{l_l_m, New_op}.
-file("src/dagger/dsl/l_l_m.gleam", 323).
?DOC(" append a prompt to the llm context\n").
-spec with_prompt(dagger@dsl@types:l_l_m(), binary()) -> dagger@dsl@types:l_l_m().
with_prompt(Parent, Prompt) ->
Field = {field,
<<"withPrompt"/utf8>>,
[{<<"prompt"/utf8>>, {g_string, Prompt}}],
[]},
New_op = begin
dagger@types:bind(
erlang:element(2, Parent),
fun(Q) -> {pure, lists:append(Q, [Field])} end
)
end,
{l_l_m, New_op}.
-file("src/dagger/dsl/l_l_m.gleam", 333).
?DOC(" append the contents of a file to the llm context\n").
-spec with_prompt_file(dagger@dsl@types:l_l_m(), dagger@dsl@types:file()) -> dagger@dsl@types:l_l_m().
with_prompt_file(Parent, File) ->
Field = {field,
<<"withPromptFile"/utf8>>,
[{<<"file"/utf8>>, {g_deferred, erlang:element(2, File)}}],
[]},
New_op = begin
dagger@types:bind(
erlang:element(2, Parent),
fun(Q) -> {pure, lists:append(Q, [Field])} end
)
end,
{l_l_m, New_op}.
-file("src/dagger/dsl/l_l_m.gleam", 343).
?DOC(" Use a static set of tools for method calls, e.g. for MCP clients that do not support dynamic tool registration\n").
-spec with_static_tools(dagger@dsl@types:l_l_m()) -> dagger@dsl@types:l_l_m().
with_static_tools(Parent) ->
Field = {field, <<"withStaticTools"/utf8>>, [], []},
New_op = begin
dagger@types:bind(
erlang:element(2, Parent),
fun(Q) -> {pure, lists:append(Q, [Field])} end
)
end,
{l_l_m, New_op}.
-file("src/dagger/dsl/l_l_m.gleam", 353).
?DOC(" Add a system prompt to the LLM's environment\n").
-spec with_system_prompt(dagger@dsl@types:l_l_m(), binary()) -> dagger@dsl@types:l_l_m().
with_system_prompt(Parent, Prompt) ->
Field = {field,
<<"withSystemPrompt"/utf8>>,
[{<<"prompt"/utf8>>, {g_string, Prompt}}],
[]},
New_op = begin
dagger@types:bind(
erlang:element(2, Parent),
fun(Q) -> {pure, lists:append(Q, [Field])} end
)
end,
{l_l_m, New_op}.
-file("src/dagger/dsl/l_l_m.gleam", 363).
?DOC(" Disable the default system prompt\n").
-spec without_default_system_prompt(dagger@dsl@types:l_l_m()) -> dagger@dsl@types:l_l_m().
without_default_system_prompt(Parent) ->
Field = {field, <<"withoutDefaultSystemPrompt"/utf8>>, [], []},
New_op = begin
dagger@types:bind(
erlang:element(2, Parent),
fun(Q) -> {pure, lists:append(Q, [Field])} end
)
end,
{l_l_m, New_op}.
-file("src/dagger/dsl/l_l_m.gleam", 373).
?DOC(" Clear the message history, leaving only the system prompts\n").
-spec without_message_history(dagger@dsl@types:l_l_m()) -> dagger@dsl@types:l_l_m().
without_message_history(Parent) ->
Field = {field, <<"withoutMessageHistory"/utf8>>, [], []},
New_op = begin
dagger@types:bind(
erlang:element(2, Parent),
fun(Q) -> {pure, lists:append(Q, [Field])} end
)
end,
{l_l_m, New_op}.
-file("src/dagger/dsl/l_l_m.gleam", 383).
?DOC(" Clear the system prompts, leaving only the default system prompt\n").
-spec without_system_prompts(dagger@dsl@types:l_l_m()) -> dagger@dsl@types:l_l_m().
without_system_prompts(Parent) ->
Field = {field, <<"withoutSystemPrompts"/utf8>>, [], []},
New_op = begin
dagger@types:bind(
erlang:element(2, Parent),
fun(Q) -> {pure, lists:append(Q, [Field])} end
)
end,
{l_l_m, New_op}.