Packages

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

Current section

Files

Jump to
dagger_gleam src dagger dsl l_l_m.gleam
Raw

src/dagger/dsl/l_l_m.gleam

// AUTO-GENERATED BY DAGGER_GLEAM - DO NOT EDIT
import dagger/types.{type Client, type Try} as types
import dagger/interpreter
import dagger/dsl/types as t
import gleam/dynamic/decode
import gleam/list
import gleam/option.{type Option, None, Some}
pub type Opts {
Opts(
model: Option(String),
max_a_p_i_calls: Option(Int),
)
}
fn defaults() -> Opts {
Opts(
model: None,
max_a_p_i_calls: None,
)
}
pub fn none(opts: Opts) -> Opts {
opts
}
pub fn opt_model(opts: Opts, val: String) -> Opts {
Opts(..opts, model: Some(val))
}
pub fn max_a_p_i_calls(opts: Opts, val: Int) -> Opts {
Opts(..opts, max_a_p_i_calls: Some(val))
}
fn encode_l_l_m(opts: Opts) -> List(#(String, types.Value)) {
list.filter_map([
case opts.model {
Some(val) -> Ok(#("model", types.GString(val)))
None -> Error(Nil)
},
case opts.max_a_p_i_calls {
Some(val) -> Ok(#("maxAPICalls", types.GInt(val)))
None -> Error(Nil)
}
], fn(x) { x })
}
pub fn l_l_m(with with_fn: fn(Opts) -> Opts) -> t.LLM {
let opts = with_fn(defaults())
let field = types.Field(name: "llm", args: encode_l_l_m(opts), subfields: [])
t.LLM(op: types.Pure([field]))
}
/// create a branch in the LLM's history
pub fn attempt(parent: t.LLM, number number: Int) -> t.LLM {
let field = types.Field(name: "attempt", args: [#("number", types.GInt(number))], subfields: [])
let new_op = {
use q <- types.bind(parent.op)
types.Pure(list.append(q, [field]))
}
t.LLM(op: new_op)
}
/// returns the type of the current state
pub fn bind_result(parent: t.LLM, name name: String) -> t.Binding {
let field = types.Field(name: "bindResult", args: [#("name", types.GString(name))], subfields: [])
let new_op = {
use q <- types.bind(parent.op)
types.Pure(list.append(q, [field]))
}
t.Binding(op: new_op)
}
/// return the LLM's current environment
pub fn env(parent: t.LLM) -> t.Env {
let field = types.Field(name: "env", args: [], subfields: [])
let new_op = {
use q <- types.bind(parent.op)
types.Pure(list.append(q, [field]))
}
t.Env(op: new_op)
}
/// Indicates whether there are any queued prompts or tool results to send to the model
pub fn has_prompt(parent: t.LLM, client client: Client, then handler: fn(Try(Bool)) -> a) -> a {
let field = types.Field(name: "hasPrompt", args: [], subfields: [])
let op = {
use q <- types.bind(parent.op)
let full_query = list.append(q, [field])
types.Fetch(
fields: full_query,
decoder: decode.dynamic,
next: fn(dyn) {
let path = types.make_path(full_query)
case decode.run(dyn, decode.at(path, decode.bool)) {
Ok(val) -> types.Pure(Ok(val))
Error(_) -> types.Pure(Error(types.DecodingError("hasPrompt")))
}
}
)
}
handler(interpreter.run(op, client))
}
/// return the llm message history
pub fn history(parent: t.LLM, client client: Client, then handler: fn(Try(List(String))) -> a) -> a {
let field = types.Field(name: "history", args: [], subfields: [])
let op = {
use q <- types.bind(parent.op)
let full_query = list.append(q, [field])
types.Fetch(
fields: full_query,
decoder: decode.dynamic,
next: fn(dyn) {
let path = types.make_path(full_query)
case decode.run(dyn, decode.at(path, decode.list(decode.string))) {
Ok(val) -> types.Pure(Ok(val))
Error(_) -> types.Pure(Error(types.DecodingError("history")))
}
}
)
}
handler(interpreter.run(op, client))
}
/// return the raw llm message history as json
pub fn history_j_s_o_n(parent: t.LLM, client client: Client, then handler: fn(Try(String)) -> a) -> a {
let field = types.Field(name: "historyJSON", args: [], subfields: [])
let op = {
use q <- types.bind(parent.op)
let full_query = list.append(q, [field])
types.Fetch(
fields: full_query,
decoder: decode.dynamic,
next: fn(dyn) {
let path = types.make_path(full_query)
case decode.run(dyn, decode.at(path, decode.string)) {
Ok(val) -> types.Pure(Ok(val))
Error(_) -> types.Pure(Error(types.DecodingError("historyJSON")))
}
}
)
}
handler(interpreter.run(op, client))
}
/// A unique identifier for this LLM.
pub fn id(parent: t.LLM) -> t.LLM {
let field = types.Field(name: "id", args: [], subfields: [])
let new_op = {
use q <- types.bind(parent.op)
types.Pure(list.append(q, [field]))
}
t.LLM(op: new_op)
}
/// return the last llm reply from the history
pub fn last_reply(parent: t.LLM, client client: Client, then handler: fn(Try(String)) -> a) -> a {
let field = types.Field(name: "lastReply", args: [], subfields: [])
let op = {
use q <- types.bind(parent.op)
let full_query = list.append(q, [field])
types.Fetch(
fields: full_query,
decoder: decode.dynamic,
next: fn(dyn) {
let path = types.make_path(full_query)
case decode.run(dyn, decode.at(path, decode.string)) {
Ok(val) -> types.Pure(Ok(val))
Error(_) -> types.Pure(Error(types.DecodingError("lastReply")))
}
}
)
}
handler(interpreter.run(op, client))
}
/// Submit the queued prompt, evaluate any tool calls, queue their results, and keep going until the model ends its turn
pub fn loop(parent: t.LLM) -> t.LLM {
let field = types.Field(name: "loop", args: [], subfields: [])
let new_op = {
use q <- types.bind(parent.op)
types.Pure(list.append(q, [field]))
}
t.LLM(op: new_op)
}
/// return the model used by the llm
pub fn model(parent: t.LLM, client client: Client, then handler: fn(Try(String)) -> a) -> a {
let field = types.Field(name: "model", args: [], subfields: [])
let op = {
use q <- types.bind(parent.op)
let full_query = list.append(q, [field])
types.Fetch(
fields: full_query,
decoder: decode.dynamic,
next: fn(dyn) {
let path = types.make_path(full_query)
case decode.run(dyn, decode.at(path, decode.string)) {
Ok(val) -> types.Pure(Ok(val))
Error(_) -> types.Pure(Error(types.DecodingError("model")))
}
}
)
}
handler(interpreter.run(op, client))
}
/// return the provider used by the llm
pub fn provider(parent: t.LLM, client client: Client, then handler: fn(Try(String)) -> a) -> a {
let field = types.Field(name: "provider", args: [], subfields: [])
let op = {
use q <- types.bind(parent.op)
let full_query = list.append(q, [field])
types.Fetch(
fields: full_query,
decoder: decode.dynamic,
next: fn(dyn) {
let path = types.make_path(full_query)
case decode.run(dyn, decode.at(path, decode.string)) {
Ok(val) -> types.Pure(Ok(val))
Error(_) -> types.Pure(Error(types.DecodingError("provider")))
}
}
)
}
handler(interpreter.run(op, client))
}
/// Submit the queued prompt or tool call results, evaluate any tool calls, and queue their results
pub fn step(parent: t.LLM) -> t.LLM {
let field = types.Field(name: "step", args: [], subfields: [])
let new_op = {
use q <- types.bind(parent.op)
types.Pure(list.append(q, [field]))
}
t.LLM(op: new_op)
}
/// synchronize LLM state
pub fn sync(parent: t.LLM) -> t.LLM {
let field = types.Field(name: "sync", args: [], subfields: [])
let new_op = {
use q <- types.bind(parent.op)
types.Pure(list.append(q, [field]))
}
t.LLM(op: new_op)
}
/// returns the token usage of the current state
pub fn token_usage(parent: t.LLM) -> t.LLMTokenUsage {
let field = types.Field(name: "tokenUsage", args: [], subfields: [])
let new_op = {
use q <- types.bind(parent.op)
types.Pure(list.append(q, [field]))
}
t.LLMTokenUsage(op: new_op)
}
/// print documentation for available tools
pub fn tools(parent: t.LLM, client client: Client, then handler: fn(Try(String)) -> a) -> a {
let field = types.Field(name: "tools", args: [], subfields: [])
let op = {
use q <- types.bind(parent.op)
let full_query = list.append(q, [field])
types.Fetch(
fields: full_query,
decoder: decode.dynamic,
next: fn(dyn) {
let path = types.make_path(full_query)
case decode.run(dyn, decode.at(path, decode.string)) {
Ok(val) -> types.Pure(Ok(val))
Error(_) -> types.Pure(Error(types.DecodingError("tools")))
}
}
)
}
handler(interpreter.run(op, client))
}
/// Return a new LLM with the specified function no longer exposed as a tool
pub fn with_blocked_function(parent: t.LLM, type_name type_name: String, function function: String) -> t.LLM {
let field = types.Field(name: "withBlockedFunction", args: [#("typeName", types.GString(type_name)), #("function", types.GString(function))], subfields: [])
let new_op = {
use q <- types.bind(parent.op)
types.Pure(list.append(q, [field]))
}
t.LLM(op: new_op)
}
/// allow the LLM to interact with an environment via MCP
pub fn with_env(parent: t.LLM, env env: t.Env) -> t.LLM {
let field = types.Field(name: "withEnv", args: [#("env", types.GDeferred(env.op))], subfields: [])
let new_op = {
use q <- types.bind(parent.op)
types.Pure(list.append(q, [field]))
}
t.LLM(op: new_op)
}
/// Add an external MCP server to the LLM
pub fn with_m_c_p_server(parent: t.LLM, name name: String, service service: t.Service) -> t.LLM {
let field = types.Field(name: "withMCPServer", args: [#("name", types.GString(name)), #("service", types.GDeferred(service.op))], subfields: [])
let new_op = {
use q <- types.bind(parent.op)
types.Pure(list.append(q, [field]))
}
t.LLM(op: new_op)
}
/// swap out the llm model
pub fn with_model(parent: t.LLM, model model: String) -> t.LLM {
let field = types.Field(name: "withModel", args: [#("model", types.GString(model))], subfields: [])
let new_op = {
use q <- types.bind(parent.op)
types.Pure(list.append(q, [field]))
}
t.LLM(op: new_op)
}
/// append a prompt to the llm context
pub fn with_prompt(parent: t.LLM, prompt prompt: String) -> t.LLM {
let field = types.Field(name: "withPrompt", args: [#("prompt", types.GString(prompt))], subfields: [])
let new_op = {
use q <- types.bind(parent.op)
types.Pure(list.append(q, [field]))
}
t.LLM(op: new_op)
}
/// append the contents of a file to the llm context
pub fn with_prompt_file(parent: t.LLM, file file: t.File) -> t.LLM {
let field = types.Field(name: "withPromptFile", args: [#("file", types.GDeferred(file.op))], subfields: [])
let new_op = {
use q <- types.bind(parent.op)
types.Pure(list.append(q, [field]))
}
t.LLM(op: new_op)
}
/// Use a static set of tools for method calls, e.g. for MCP clients that do not support dynamic tool registration
pub fn with_static_tools(parent: t.LLM) -> t.LLM {
let field = types.Field(name: "withStaticTools", args: [], subfields: [])
let new_op = {
use q <- types.bind(parent.op)
types.Pure(list.append(q, [field]))
}
t.LLM(op: new_op)
}
/// Add a system prompt to the LLM's environment
pub fn with_system_prompt(parent: t.LLM, prompt prompt: String) -> t.LLM {
let field = types.Field(name: "withSystemPrompt", args: [#("prompt", types.GString(prompt))], subfields: [])
let new_op = {
use q <- types.bind(parent.op)
types.Pure(list.append(q, [field]))
}
t.LLM(op: new_op)
}
/// Disable the default system prompt
pub fn without_default_system_prompt(parent: t.LLM) -> t.LLM {
let field = types.Field(name: "withoutDefaultSystemPrompt", args: [], subfields: [])
let new_op = {
use q <- types.bind(parent.op)
types.Pure(list.append(q, [field]))
}
t.LLM(op: new_op)
}
/// Clear the message history, leaving only the system prompts
pub fn without_message_history(parent: t.LLM) -> t.LLM {
let field = types.Field(name: "withoutMessageHistory", args: [], subfields: [])
let new_op = {
use q <- types.bind(parent.op)
types.Pure(list.append(q, [field]))
}
t.LLM(op: new_op)
}
/// Clear the system prompts, leaving only the default system prompt
pub fn without_system_prompts(parent: t.LLM) -> t.LLM {
let field = types.Field(name: "withoutSystemPrompts", args: [], subfields: [])
let new_op = {
use q <- types.bind(parent.op)
types.Pure(list.append(q, [field]))
}
t.LLM(op: new_op)
}