Skip to content

Commit

Permalink
update tools.roc example
Browse files Browse the repository at this point in the history
  • Loading branch information
imclerran committed Jan 3, 2025
1 parent e44bdf3 commit 15ac5ba
Showing 1 changed file with 1 addition and 16 deletions.
17 changes: 1 addition & 16 deletions examples/tools.roc
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ main =
Stdout.write! "You: "
messages = Chat.appendUserMessage previousMessages Stdin.line! {}
response = Http.send (Chat.buildHttpRequest client messages {}) |> Task.result!
updatedMessages = updateMessagesFromResponse response messages |> Tools.handleToolCalls! client toolHandlerMap
updatedMessages = Chat.updateMessageList response messages |> Tools.handleToolCalls! client toolHandlerMap
printLastMessage! updatedMessages
Task.ok (Step { previousMessages: updatedMessages })

Expand All @@ -48,21 +48,6 @@ printLastMessage = \messages ->

_ -> Task.ok {}

## decode the response from the OpenRouter API and append the first message to the list of messages
updateMessagesFromResponse : Result Http.Response _, List Message -> List Message
updateMessagesFromResponse = \responseRes, messages ->
when responseRes is
Ok response ->
when Chat.decodeTopMessageChoice response.body is
Ok message -> List.append messages message
Err (ApiError err) -> Chat.appendSystemMessage messages "API error: $(err.message)" {}
Err NoChoices -> Chat.appendSystemMessage messages "No choices in API response" {}
Err (BadJson str) -> Chat.appendSystemMessage messages "Could not decode JSON response:\n$(str)" {}
Err DecodingError -> Chat.appendSystemMessage messages "Error decoding API response" {}

Err (HttpErr err) ->
Chat.appendSystemMessage messages (Http.errorToString err) {}

## Map of tool names to tool handlers
toolHandlerMap : Dict Str (Str -> Task Str _)
toolHandlerMap =
Expand Down

0 comments on commit 15ac5ba

Please sign in to comment.