Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix Claude no-arg tool calling in streaming mode #229

Merged
merged 2 commits into from
Dec 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Did you mean to change this?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes--this turns on streaming, which makes the test fail without this fix and pass with this fix.

I know this also makes Gemini fail, until we merge the other PR.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, gotcha. Let's merge and then fix gemini ASAP.

expect_match(result, "2024-01-01")

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