Skip to content

Commit

Permalink
Fix Claude no-arg tool calling in streaming mode (#229)
Browse files Browse the repository at this point in the history
* Don't error when Claude does a no-arg tool call in streaming mode
* Make tool calling unit test use streaming
  • Loading branch information
jcheng5 authored Dec 18, 2024
1 parent 8683a9a commit 678b9f8
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 2 deletions.
5 changes: 4 additions & 1 deletion R/provider-claude.R
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,10 @@ method(stream_merge_chunks, ProviderClaude) <- function(provider, result, chunk)
if (chunk$delta$type == "text_delta") {
paste(result$content[[chunk$index + 1L]]$text) <- chunk$delta$text
} else if (chunk$delta$type == "input_json_delta") {
paste(result$content[[chunk$index + 1L]]$input) <- chunk$delta$partial_json
if (chunk$delta$partial_json != "") {
# See issue #228 about partial_json sometimes being ""
paste(result$content[[chunk$index + 1L]]$input) <- chunk$delta$partial_json
}
} else {
cli::cli_inform(c("!" = "Unknown delta type {.str {chunk$delta$type}}."))
}
Expand Down
2 changes: 1 addition & 1 deletion tests/testthat/helper-provider.R
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ test_tools_simple <- function(chat_fun) {
chat <- chat_fun(system_prompt = "Be very terse, not even punctuation.")
chat$register_tool(tool(function() "2024-01-01", "Return the current date"))

result <- chat$chat("What's the current date in YMD format?")
result <- chat$chat("What's the current date in YMD format?", echo = TRUE)
expect_match(result, "2024-01-01")

result <- chat$chat("What month is it? Provide the full name")
Expand Down

0 comments on commit 678b9f8

Please sign in to comment.