Packages

An LLM interaction library that makes you feel like a star

Current section

Files

Jump to
starlet src examples@ollama_chat.erl
Raw

src/examples@ollama_chat.erl

-module(examples@ollama_chat).
-compile([no_auto_import, nowarn_unused_vars, nowarn_unused_function, nowarn_nomatch, inline]).
-define(FILEPATH, "src/examples/ollama_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/ollama_chat.gleam", 7).
?DOC(false).
-spec main() -> nil.
main() ->
Client = starlet@ollama:new(<<"http://localhost:11434"/utf8>>),
Result = begin
Msg1 = <<"What is the capital of France?"/utf8>>,
Msg2 = <<"What is its population?"/utf8>>,
Chat = begin
_pipe = starlet:chat(Client, <<"qwen3:0.6b"/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(
<<"Ollama: "/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(
<<"Ollama: "/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.