-module(examples@gemini_chat). -compile([no_auto_import, nowarn_unused_vars, nowarn_unused_function, nowarn_nomatch, inline]). -define(FILEPATH, "src/examples/gemini_chat.gleam"). -export([main/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. ?MODULEDOC(false). -file("src/examples/gemini_chat.gleam", 17). ?DOC(false). -spec run_example(binary()) -> nil. run_example(Api_key) -> Client = starlet@gemini:new(Api_key), Result = begin Msg1 = <<"What is the capital of France?"/utf8>>, Msg2 = <<"What is its population?"/utf8>>, Chat = begin _pipe = starlet:chat(Client, <<"gemini-2.5-flash"/utf8>>), _pipe@1 = starlet:system( _pipe, <<"You are a helpful assistant. Be concise."/utf8>> ), starlet:user(_pipe@1, Msg1) end, gleam@result:'try'( starlet:send(Chat), fun(_use0) -> {Chat@1, Turn} = _use0, gleam_stdlib:println(<<"User: "/utf8, Msg1/binary>>), gleam_stdlib:println( <<"Gemini: "/utf8, (starlet:text(Turn))/binary>> ), gleam_stdlib:println(<<""/utf8>>), Chat@2 = starlet:user(Chat@1, Msg2), gleam@result:'try'( starlet:send(Chat@2), fun(_use0@1) -> {_, Turn@1} = _use0@1, gleam_stdlib:println(<<"User: "/utf8, Msg2/binary>>), gleam_stdlib:println( <<"Gemini: "/utf8, (starlet:text(Turn@1))/binary>> ), {ok, nil} end ) end ) end, case Result of {ok, _} -> nil; {error, Err} -> gleam_stdlib:println( <<"Error: "/utf8, (examples@utils:error_to_string(Err))/binary>> ) end. -file("src/examples/gemini_chat.gleam", 8). ?DOC(false). -spec main() -> nil. main() -> Api_key = begin _pipe = envoy_ffi:get(<<"GEMINI_API_KEY"/utf8>>), gleam@result:unwrap(_pipe, <<""/utf8>>) end, case Api_key of <<""/utf8>> -> gleam_stdlib:println( <<"Error: GEMINI_API_KEY environment variable not set"/utf8>> ); _ -> run_example(Api_key) end.