Skip to content
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
2 changes: 1 addition & 1 deletion R/content.R
Original file line number Diff line number Diff line change
Expand Up @@ -322,7 +322,7 @@ tool_string <- function(x) {
paste(x@value, collapse = "\n")
} else {
withCallingHandlers(
jsonlite::toJSON(x@value, auto_unbox = TRUE),
to_json(x@value),
error = function(err) {
cli::cli_abort(
c(
Expand Down
2 changes: 1 addition & 1 deletion R/provider-databricks.R
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ method(as_json, list(ProviderDatabricks, ContentToolRequest)) <- function(
) {
# Databricks seems to require encoding empty arguments as an empty
# dictionary, rather than an empty array.
json_args <- jsonlite::toJSON(set_names(x@arguments))
json_args <- to_json(set_names(x@arguments))
list(
id = x@id,
`function` = list(name = x@name, arguments = json_args),
Expand Down
2 changes: 1 addition & 1 deletion R/provider-openai-compatible.R
Original file line number Diff line number Diff line change
Expand Up @@ -405,7 +405,7 @@ method(as_json, list(ProviderOpenAICompatible, ContentToolRequest)) <- function(
x,
...
) {
json_args <- jsonlite::toJSON(x@arguments)
json_args <- to_json(x@arguments)
list(
id = x@id,
`function` = list(name = x@name, arguments = json_args),
Expand Down
4 changes: 2 additions & 2 deletions R/provider-openai.R
Original file line number Diff line number Diff line change
Expand Up @@ -421,7 +421,7 @@ method(as_json, list(ProviderOpenAI, ContentToolRequest)) <- function(
type = "function_call",
call_id = x@id,
name = x@name,
arguments = jsonlite::toJSON(x@arguments)
arguments = to_json(x@arguments)
)
}

Expand Down Expand Up @@ -482,7 +482,7 @@ method(batch_submit, ProviderOpenAI) <- function(
body = body
)
})
json <- map_chr(requests, jsonlite::toJSON, auto_unbox = TRUE)
json <- map_chr(requests, to_json)
writeLines(json, path)
# Then upload it
uploaded <- openai_upload(provider, path)
Expand Down
4 changes: 4 additions & 0 deletions R/utils.R
Original file line number Diff line number Diff line change
Expand Up @@ -328,3 +328,7 @@ extract_custom_id <- function(json_string) {

result[2] # Second element is the captured group
}

to_json <- function(x) {
jsonlite::toJSON(x, auto_unbox = TRUE)
}
62 changes: 31 additions & 31 deletions inst/_vcr/tool.yml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions tests/testthat/_snaps/provider-openrouter.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@
Condition
Error in `req_perform()`:
! HTTP 400 Bad Request.
* Expected temperature to be a number, received "hot"
i Invalid input: expected number, received string
Code
chat$chat("What is 1 + 1?", echo = TRUE)
Condition
Error in `req_perform_connection()`:
! HTTP 400 Bad Request.
* Expected temperature to be a number, received "hot"
i Invalid input: expected number, received string

Loading