Skip to content

Commit 272c430

Browse files
stephentoubamanda-tarafa
authored andcommitted
fix: Handling of tool calls without thought signatures
Copy/paste mistake. It was intending to be a null check on thoughtSignature (`thoughtSignature ?? defaultValue), but then thoughtSignature got wrapped in a ByteString.CopyFrom, changing the meaning of the line.
1 parent baf1e9e commit 272c430

File tree

2 files changed

+42
-1
lines changed

2 files changed

+42
-1
lines changed

apis/Google.Cloud.VertexAI.Extensions/Google.Cloud.VertexAI.Extensions.Tests/BuildIChatClientTest.cs

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1011,6 +1011,47 @@ public async Task IChatClient_GetResponseAsync_SendsTextReasoningContent()
10111011
Assert.NotNull(result);
10121012
}
10131013

1014+
[Fact]
1015+
public async Task IChatClient_GetResponseAsync_SendsFunctionCallContent_WithoutThoughtSignature()
1016+
{
1017+
DelegateCallInvoker invoker = new()
1018+
{
1019+
OnGenerateContentRequest = request =>
1020+
{
1021+
Assert.Equal(3, request.Contents.Count);
1022+
1023+
Assert.Equal("user", request.Contents[0].Role);
1024+
Assert.Single(request.Contents[0].Parts);
1025+
Assert.Equal("What's the weather?", request.Contents[0].Parts[0].Text);
1026+
1027+
Assert.Equal("model", request.Contents[1].Role);
1028+
Assert.Single(request.Contents[1].Parts);
1029+
Part functionCallPart = request.Contents[1].Parts[0];
1030+
Assert.NotNull(functionCallPart.FunctionCall);
1031+
Assert.Equal("get_weather", functionCallPart.FunctionCall.Name);
1032+
Assert.False(functionCallPart.ThoughtSignature.IsEmpty);
1033+
Assert.Equal("skip_thought_signature_validator", functionCallPart.ThoughtSignature.ToStringUtf8());
1034+
1035+
Assert.Equal("user", request.Contents[2].Role);
1036+
1037+
return CreateResponse(new() { Role = "model", Parts = { new Part() { Text = "It's sunny." } } });
1038+
}
1039+
};
1040+
1041+
IChatClient chatClient = CreateClientBuilder(invoker).BuildIChatClient("projects/test-project/locations/us-central1/publishers/google/models/mymodel");
1042+
1043+
ChatMessage[] messages =
1044+
[
1045+
new(ChatRole.User, "What's the weather?"),
1046+
new(ChatRole.Assistant, [new FunctionCallContent("fc_1", "get_weather", new Dictionary<string, object?> { ["location"] = "Seattle" })]),
1047+
new(ChatRole.User, [new FunctionResultContent("fc_1", "Sunny, 72°F")])
1048+
];
1049+
1050+
ChatResponse result = await chatClient.GetResponseAsync(messages);
1051+
Assert.NotNull(result);
1052+
Assert.Equal("It's sunny.", ((TextContent)result.Messages[0].Contents[0]).Text);
1053+
}
1054+
10141055
[Fact]
10151056
public async Task IChatClient_GetResponseAsync_CodeInterpreterToolCallContent()
10161057
{

apis/Google.Cloud.VertexAI.Extensions/Google.Cloud.VertexAI.Extensions/PredictionServiceChatClient.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -417,7 +417,7 @@ private static void AddPartsForAIContents(IList<AIContent> contents, RepeatedFie
417417
Struct.Parser.ParseJson(JsonSerializer.Serialize(functionCallContent.Arguments, AIJsonUtilities.DefaultOptions)) :
418418
new(),
419419
},
420-
ThoughtSignature = ByteString.CopyFrom(thoughtSignature) ?? s_skipThoughtValidation,
420+
ThoughtSignature = thoughtSignature is not null ? ByteString.CopyFrom(thoughtSignature) : s_skipThoughtValidation,
421421
};
422422
break;
423423

0 commit comments

Comments
 (0)