Current section
Files
Jump to
Current section
Files
src/starflow.erl
-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, with_tool/2, invoke/2]).
-export_type([flow/1]).
-type flow(JED) :: {flow,
starflow@model:model(),
fun((starflow@state:state(JED)) -> list(starflow@state:content())),
fun((starflow@state:state(JED), starflow@state:response(), list({binary(),
starflow@tool:tool_result()})) -> starflow@state:state(JED)),
list(starflow@tool:tool())}.
-file("/home/ethanthoma/projects/flow/src/starflow.gleam", 59).
-spec new(starflow@model:model()) -> flow(any()).
new(Model) ->
{flow,
Model,
fun starflow@transform:prompt_default/1,
fun starflow@transform:parser_default/3,
[]}.
-file("/home/ethanthoma/projects/flow/src/starflow.gleam", 78).
-spec with_model(flow(JEG), starflow@model:model()) -> flow(JEG).
with_model(Flow, Model) ->
erlang:setelement(2, Flow, Model).
-file("/home/ethanthoma/projects/flow/src/starflow.gleam", 94).
-spec with_prompt(
flow(JEJ),
fun((starflow@state:state(JEJ)) -> list(starflow@state:content()))
) -> flow(JEJ).
with_prompt(Flow, Prompt) ->
erlang:setelement(3, Flow, Prompt).
-file("/home/ethanthoma/projects/flow/src/starflow.gleam", 117).
-spec with_parser(
flow(JEN),
fun((starflow@state:state(JEN), starflow@state:response(), list({binary(),
starflow@tool:tool_result()})) -> starflow@state:state(JEN))
) -> flow(JEN).
with_parser(Flow, Parser) ->
erlang:setelement(4, Flow, Parser).
-file("/home/ethanthoma/projects/flow/src/starflow.gleam", 121).
-spec with_tool(flow(JER), starflow@tool:tool()) -> flow(JER).
with_tool(Flow, Tool) ->
erlang:setelement(
5,
Flow,
gleam@list:prepend(erlang:element(5, Flow), Tool)
).
-file("/home/ethanthoma/projects/flow/src/starflow.gleam", 169).
-spec use_tools(flow(any()), starflow@state:response()) -> list({binary(),
starflow@tool:tool_result()}).
use_tools(Flow, Resp) ->
_pipe@2 = (gleam@list:map(
erlang:element(3, Resp),
fun(Content) -> case Content of
{tool_content, _, Name, Input} ->
gleam@result:'try'(
gleam@list:find(
erlang:element(5, Flow),
fun(Tool) -> erlang:element(2, Tool) =:= Name end
),
fun(Tool@1) ->
_pipe = (erlang:element(6, Tool@1))(Input),
_pipe@1 = gleam@result:map(
_pipe,
fun(A) -> {erlang:element(2, Tool@1), A} end
),
gleam@result:replace_error(_pipe@1, nil)
end
);
_ ->
{error, nil}
end end
)),
gleam@result:values(_pipe@2).
-file("/home/ethanthoma/projects/flow/src/starflow.gleam", 152).
-spec invoke(starflow@state:state(JEU), flow(JEU)) -> {ok,
starflow@state:state(JEU)} |
{error, starflow@api_request:api_error()}.
invoke(State, Flow) ->
Model = erlang:element(2, Flow),
Prompt = erlang:element(3, Flow),
Message = {message, <<"user"/utf8>>, Prompt(State)},
Messages = lists:append(erlang:element(2, State), [Message]),
gleam@result:'try'(
starflow@api_request:create_message(
Model,
Messages,
erlang:element(5, Flow)
),
fun(Resp) -> _pipe = Flow,
_pipe@1 = use_tools(_pipe, Resp),
_pipe@2 = (erlang:element(4, Flow))(State, Resp, _pipe@1),
{ok, _pipe@2} end
).