-module(starflow@encoder). -compile([no_auto_import, nowarn_unused_vars, nowarn_unused_function, nowarn_nomatch]). -export([encode/3]). -file("/home/ethanthoma/projects/flow/src/starflow/encoder.gleam", 50). -spec image_source(starflow@state:image_source()) -> gleam@json:json(). image_source(Source) -> case Source of {base64_image, Data, Media_type} -> gleam@json:object( [{<<"type"/utf8>>, gleam@json:string(<<"base64"/utf8>>)}, {<<"data"/utf8>>, gleam@json:string(Data)}, {<<"media_type"/utf8>>, gleam@json:string(Media_type)}] ) end. -file("/home/ethanthoma/projects/flow/src/starflow/encoder.gleam", 28). -spec content(starflow@state:content()) -> gleam@json:json(). content(Content) -> case Content of {text_content, Text} -> gleam@json:object( [{<<"type"/utf8>>, gleam@json:string(<<"text"/utf8>>)}, {<<"text"/utf8>>, gleam@json:string(Text)}] ); {image_content, Source} -> gleam@json:object( [{<<"type"/utf8>>, gleam@json:string(<<"image"/utf8>>)}, {<<"source"/utf8>>, image_source(Source)}] ); {tool_content, Id, Name, Input} -> _assert_subject = gleam@dynamic:string(Input), {ok, Input@1} = case _assert_subject of {ok, _} -> _assert_subject; _assert_fail -> erlang:error(#{gleam_error => let_assert, message => <<"Pattern match failed, no pattern matched the value."/utf8>>, value => _assert_fail, module => <<"starflow/encoder"/utf8>>, function => <<"content"/utf8>>, line => 38}) end, gleam@json:object( [{<<"type"/utf8>>, gleam@json:string(<<"tool_use"/utf8>>)}, {<<"id"/utf8>>, gleam@json:string(Id)}, {<<"name"/utf8>>, gleam@json:string(Name)}, {<<"input"/utf8>>, gleam@json:string(Input@1)}] ) end. -file("/home/ethanthoma/projects/flow/src/starflow/encoder.gleam", 21). -spec message(starflow@state:message()) -> gleam@json:json(). message(Message) -> gleam@json:object( [{<<"role"/utf8>>, gleam@json:string(erlang:element(2, Message))}, {<<"content"/utf8>>, gleam@json:array(erlang:element(3, Message), fun content/1)}] ). -file("/home/ethanthoma/projects/flow/src/starflow/encoder.gleam", 8). -spec encode( starflow@model:model(), list(starflow@state:message()), list(starflow@tool:tool()) ) -> gleam@json:json(). encode(Model, Messages, Tools) -> gleam@json:object( [{<<"model"/utf8>>, gleam@json:string(erlang:element(4, Model))}, {<<"max_tokens"/utf8>>, gleam@json:int(erlang:element(6, Model))}, {<<"messages"/utf8>>, gleam@json:array(Messages, fun message/1)}, {<<"tools"/utf8>>, gleam@json:array(Tools, fun starflow@tool:to_json/1)}] ).