-module(starflow). -compile([no_auto_import, nowarn_unused_vars, nowarn_unused_function, nowarn_nomatch]). -export([new/1, with_model/2, with_prompt/2, with_parser/2, invoke/2]). -export_type([no_model/0, has_model/0, flow/1]). -type no_model() :: any(). -type has_model() :: any(). -type flow(ISF) :: {flow, starflow@model:model(), fun((ISF) -> list(starflow@state:content())), fun((starflow@state:state(ISF), starflow@state:response()) -> starflow@state:state(ISF))}. -file("/home/ethanthoma/projects/flow/src/starflow.gleam", 61). -spec new(starflow@model:model()) -> flow(any()). new(Model) -> {flow, Model, fun starflow@transform:prompt_default/1, fun starflow@transform:parser_default/2}. -file("/home/ethanthoma/projects/flow/src/starflow.gleam", 79). -spec with_model(flow(ISI), starflow@model:model()) -> flow(ISI). with_model(Flow, Model) -> {flow, Model, erlang:element(3, Flow), erlang:element(4, Flow)}. -file("/home/ethanthoma/projects/flow/src/starflow.gleam", 95). -spec with_prompt(flow(ISL), fun((ISL) -> list(starflow@state:content()))) -> flow(ISL). with_prompt(Flow, Prompt) -> {flow, erlang:element(2, Flow), Prompt, erlang:element(4, Flow)}. -file("/home/ethanthoma/projects/flow/src/starflow.gleam", 118). -spec with_parser( flow(ISP), fun((starflow@state:state(ISP), starflow@state:response()) -> starflow@state:state(ISP)) ) -> flow(ISP). with_parser(Flow, Parser) -> {flow, erlang:element(2, Flow), erlang:element(3, Flow), Parser}. -file("/home/ethanthoma/projects/flow/src/starflow.gleam", 149). -spec invoke(starflow@state:state(IST), flow(IST)) -> {ok, starflow@state:state(IST)} | {error, starflow@api_request:api_error()}. invoke(State, Flow) -> Model = erlang:element(2, Flow), Prompt = erlang:element(3, Flow), Message = {message, <<"user"/utf8>>, Prompt(erlang:element(4, State))}, Messages = lists:append(erlang:element(2, State), [Message]), gleam@result:'try'( starflow@api_request:create_message(Model, Messages), fun(Resp) -> State@1 = (erlang:element(4, Flow))(State, Resp), {ok, State@1} end ).