@@ -2226,6 +2226,56 @@ def test_message_to_generate_content_response_tool_call():
22262226 assert response .content .parts [0 ].function_call .id == "test_tool_call_id"
22272227
22282228
2229+ def test_message_to_generate_content_response_tool_call_with_thought_signature ():
2230+ signature = b"gemini_signature"
2231+ encoded_signature = base64 .b64encode (signature ).decode ("utf-8" )
2232+ message = ChatCompletionAssistantMessage (
2233+ role = "assistant" ,
2234+ content = None ,
2235+ tool_calls = [
2236+ ChatCompletionMessageToolCall (
2237+ type = "function" ,
2238+ id = f"test_tool_call_id__thought__{ encoded_signature } " ,
2239+ function = Function (
2240+ name = "test_function" ,
2241+ arguments = '{"test_arg": "test_value"}' ,
2242+ ),
2243+ )
2244+ ],
2245+ )
2246+
2247+ response = _message_to_generate_content_response (message )
2248+ assert response .content .role == "model"
2249+ assert response .content .parts [0 ].function_call .name == "test_function"
2250+ assert response .content .parts [0 ].function_call .args == {
2251+ "test_arg" : "test_value"
2252+ }
2253+ assert response .content .parts [0 ].function_call .id == "test_tool_call_id"
2254+ assert response .content .parts [0 ].thought_signature == signature
2255+
2256+
2257+ @pytest .mark .asyncio
2258+ async def test_content_to_message_param_embeds_thought_signature_in_tool_call ():
2259+ part = types .Part .from_function_call (
2260+ name = "test_function" ,
2261+ args = {"test_arg" : "test_value" },
2262+ )
2263+ part .function_call .id = "test_tool_call_id"
2264+ part .thought_signature = b"gemini_signature"
2265+ content = types .Content (role = "model" , parts = [part ])
2266+
2267+ message = await _content_to_message_param (content )
2268+
2269+ tool_calls = message ["tool_calls" ]
2270+ assert tool_calls is not None
2271+ assert len (tool_calls ) == 1
2272+ assert (
2273+ tool_calls [0 ]["id" ]
2274+ == "test_tool_call_id__thought__"
2275+ + base64 .b64encode (b"gemini_signature" ).decode ("utf-8" )
2276+ )
2277+
2278+
22292279def test_message_to_generate_content_response_inline_tool_call_text ():
22302280 message = ChatCompletionAssistantMessage (
22312281 role = "assistant" ,
0 commit comments