Skip to content

Commit 22c93f2

Browse files
authored
✨ forward 'thoughtSignature' with Google Gemini (#870)
1 parent 846e57e commit 22c93f2

File tree

3 files changed

+17
-8
lines changed

3 files changed

+17
-8
lines changed

R/content.R

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -202,14 +202,17 @@ show_image <- function(x) {
202202
#' @param arguments Named list of arguments to call the function with.
203203
#' @param tool ellmer automatically matches a tool request to the tools defined
204204
#' for the chatbot. If `NULL`, the request did not match a defined tool.
205+
#' @param extra Provider-specific metadata associated with the tool request.
206+
#' Automatically managed by \pkg{ellmer}.
205207
ContentToolRequest <- new_class(
206208
"ContentToolRequest",
207209
parent = Content,
208210
properties = list(
209211
id = prop_string(),
210212
name = prop_string(),
211213
arguments = class_list,
212-
tool = NULL | ToolDef
214+
tool = NULL | ToolDef,
215+
extra = class_list
213216
)
214217
)
215218
method(format, ContentToolRequest) <- function(

R/provider-google.R

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -327,10 +327,14 @@ method(value_turn, ProviderGoogleGemini) <- function(
327327
ContentText(content$text)
328328
}
329329
} else if (has_name(content, "functionCall")) {
330+
extra <- compact(list(
331+
thoughtSignature = content$thoughtSignature
332+
))
330333
ContentToolRequest(
331334
content$functionCall$name,
332335
content$functionCall$name,
333-
content$functionCall$args
336+
content$functionCall$args,
337+
extra = extra
334338
)
335339
} else if (has_name(content, "inlineData")) {
336340
ContentImageInline(
@@ -456,12 +460,13 @@ method(as_json, list(ProviderGoogleGemini, ContentToolRequest)) <- function(
456460
x,
457461
...
458462
) {
459-
list(
463+
compact(list(
460464
functionCall = list(
461465
name = x@id,
462466
args = x@arguments
463-
)
464-
)
467+
),
468+
thoughtSignature = x@extra$thoughtSignature
469+
))
465470
}
466471

467472
# https://ai.google.dev/api/caching#FunctionResponse

man/Content.Rd

Lines changed: 4 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)