Skip to content

Commit

Permalink
Merge pull request #9 from imclerran/streamline-tools-ex
Browse files Browse the repository at this point in the history
Streamlined the tools example
  • Loading branch information
imclerran authored Sep 19, 2024
2 parents e7a615b + dd2a1dc commit 4f305ca
Showing 1 changed file with 4 additions and 13 deletions.
17 changes: 4 additions & 13 deletions examples/tools.roc
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,8 @@ loop = \{ client, previousMessages } ->
Stdout.write! "You: "
query = Stdin.line!
messages = Chat.appendUserMessage previousMessages query
when query |> strToLower is
when query is
"goodbye" -> Task.ok (Done {})
"goodbye." -> Task.ok (Done {})
"goodbye!" -> Task.ok (Done {})
_ -> handlePrompt client messages

## Handle the prompt and send the request to the OpenRouter API
Expand All @@ -51,6 +49,9 @@ printLastMessage = \messages ->
when List.last messages is
Ok { role, content } if role == "assistant" ->
Stdout.line! ("\nAssistant: $(content)\n" |> Ansi.color { fg: Standard Magenta })

Ok { role, content } if role == "system" ->
Stdout.line! ("\nAssistant: $(content)\n" |> Ansi.color { fg: Standard Cyan })

_ -> Task.ok {}

Expand All @@ -69,16 +70,6 @@ getMessagesFromResponse = \messages, responseRes ->
Err (HttpErr err) ->
Chat.appendSystemMessage messages (Http.errorToString err)

## Convert a string to lowercase
strToLower : Str -> Str
strToLower = \str ->
str
|> Str.toUtf8
|> List.walk [] \acc, elem ->
acc |> List.append (if elem >= 65 && elem <= 90 then elem + 32 else elem)
|> Str.fromUtf8
|> Result.withDefault str

## Get the API key from the environmental variable
getApiKey : Task Str _
getApiKey =
Expand Down

0 comments on commit 4f305ca

Please sign in to comment.