22
33Request shape mirrors :meth:`giskard.llm.translators.google_response.GoogleResponseTranslator.to_google`.
44Each :class:`~giskard.llm.types.ResponseEasyInputMessage` and message item serializes to one
5- ``TurnParam `` (``content`` + ``role ``); :class:`~giskard.llm.types.ResponseFunctionToolCall`
6- matches assistant replay as a model turn whose ``content`` contains `` function_call`` (``id``, not top-level ``call_id``);
7- :class:`~giskard.llm.types.ResponseFunctionCallOutput` becomes a **user** turn whose ``content`` contains `` function_result``.
5+ ``StepParam `` (``content`` + ``type ``); :class:`~giskard.llm.types.ResponseFunctionToolCall`
6+ matches assistant replay as a `` function_call`` step (``id``, not ``call_id``);
7+ :class:`~giskard.llm.types.ResponseFunctionCallOutput` becomes a `` function_result`` step .
88``None`` from system/developer turns is dropped.
99
10- **Role mapping** (Gemini Interactions ``TurnParam.role``): ``user`` stays ``user``;
11- ``assistant`` becomes ``model`` (same for :class:`~giskard.llm.types.ResponseOutputMessage`).
12- :class:`~giskard.llm.types.ResponseOutputFunctionCall` is always ``model``.
10+ **Step mapping** (Gemini Interactions ``StepParam.type``): ``user`` becomes
11+ ``user_input``; ``assistant`` becomes ``model_output`` (same for
12+ :class:`~giskard.llm.types.ResponseOutputMessage`).
13+ :class:`~giskard.llm.types.ResponseOutputFunctionCall` is ``function_call``.
1314System and developer text is not emitted as turns: it is merged into ``system_instruction``.
1415
1516For **return** mapping -> :class:`~giskard.llm.types.ResponseResult`, see ``test_google_response_return.py``.
@@ -93,42 +94,34 @@ def _text_part(text: str) -> dict[str, str]:
9394 return {** _TEXT , "text" : text }
9495
9596
96- def _msg_turn (role : Literal ["user" , "model" ], text : str ) -> dict [str , object ]:
97- """One ``ResponseEasyInputMessage`` serializes to a single Interactions turn dict."""
98- return {"content" : [_text_part (text )], "role" : role }
97+ def _msg_step (
98+ step_type : Literal ["user_input" , "model_output" ], text : str
99+ ) -> dict [str , object ]:
100+ """One ``ResponseEasyInputMessage`` serializes to a single Interactions step dict."""
101+ return {"content" : [_text_part (text )], "type" : step_type }
99102
100103
101104def _model_function_call_turn (
102105 call_id : str , name : str , arguments : dict [str , object ]
103106) -> dict [str , object ]:
104107 """Input ``ResponseFunctionToolCall`` matches assistant replay shape (Interactions API)."""
105108 return {
106- "content" : [
107- {
108- "type" : "function_call" ,
109- "id" : call_id ,
110- "name" : name ,
111- "arguments" : arguments ,
112- }
113- ],
114- "role" : "model" ,
109+ "type" : "function_call" ,
110+ "id" : call_id ,
111+ "name" : name ,
112+ "arguments" : arguments ,
115113 }
116114
117115
118116def _user_function_result_turn (
119117 call_id : str , name : str , result : str
120118) -> dict [str , object ]:
121- """``ResponseFunctionCallOutput`` → user turn with ``function_result`` content (Gemini API)."""
119+ """``ResponseFunctionCallOutput`` -> ``function_result`` step (Gemini API)."""
122120 return {
123- "content" : [
124- {
125- "type" : "function_result" ,
126- "call_id" : call_id ,
127- "name" : name ,
128- "result" : result ,
129- }
130- ],
131- "role" : "user" ,
121+ "type" : "function_result" ,
122+ "call_id" : call_id ,
123+ "name" : name ,
124+ "result" : result ,
132125 }
133126
134127
@@ -146,7 +139,7 @@ def test_message_instruction_then_user(
146139 ]
147140 payload = GoogleResponseTranslator .to_google (_MODEL , items )
148141
149- assert payload ["input" ] == [_msg_turn ( "user " , "Hello." )]
142+ assert payload ["input" ] == [_msg_step ( "user_input " , "Hello." )]
150143 assert payload .get ("system_instruction" ) == "You are helpful."
151144 validate_google_interaction_params (payload )
152145
@@ -160,7 +153,7 @@ def test_message_system_then_developer_then_user():
160153 ]
161154 payload = GoogleResponseTranslator .to_google (_MODEL , items )
162155
163- assert payload ["input" ] == [_msg_turn ( "user " , "Hello." )]
156+ assert payload ["input" ] == [_msg_step ( "user_input " , "Hello." )]
164157 assert payload .get ("system_instruction" ) == "You are helpful.\n App version 2.0"
165158 validate_google_interaction_params (payload )
166159
@@ -188,7 +181,7 @@ def test_message_two_instructions_then_user(
188181 ]
189182 payload = GoogleResponseTranslator .to_google (_MODEL , items )
190183
191- assert payload ["input" ] == [_msg_turn ( "user " , "Hello." )]
184+ assert payload ["input" ] == [_msg_step ( "user_input " , "Hello." )]
192185 assert (
193186 payload .get ("system_instruction" )
194187 == "First system instruction.\n Second system instruction."
@@ -206,9 +199,9 @@ def test_message_user_assistant_user():
206199 payload = GoogleResponseTranslator .to_google (_MODEL , items )
207200
208201 assert payload ["input" ] == [
209- _msg_turn ( "user " , "First user." ),
210- _msg_turn ( "model " , "Assistant reply." ),
211- _msg_turn ( "user " , "Second user." ),
202+ _msg_step ( "user_input " , "First user." ),
203+ _msg_step ( "model_output " , "Assistant reply." ),
204+ _msg_step ( "user_input " , "Second user." ),
212205 ]
213206 assert "system_instruction" not in payload
214207 validate_google_interaction_params (payload )
@@ -223,7 +216,7 @@ def test_user_tool_call_and_result_with_tools():
223216 {"type" : "function" , ** WEATHER_TOOL .function .model_dump ()},
224217 ]
225218 assert payload .get ("input" ) == [
226- _msg_turn ( "user " , "What's the weather in Paris?" ),
219+ _msg_step ( "user_input " , "What's the weather in Paris?" ),
227220 _model_function_call_turn (TOOL_CALL_ID , "get_weather" , {"city" : "Paris" }),
228221 _user_function_result_turn (TOOL_CALL_ID , "get_weather" , TOOL_RESULT_CONTENT ),
229222 ]
@@ -240,7 +233,7 @@ def test_user_two_parallel_tool_calls_and_results_with_tools():
240233 {"type" : "function" , ** GET_TIME_TOOL .function .model_dump ()},
241234 ]
242235 assert payload .get ("input" ) == [
243- _msg_turn ( "user " , PARALLEL_USER_PROMPT ),
236+ _msg_step ( "user_input " , PARALLEL_USER_PROMPT ),
244237 _model_function_call_turn (
245238 TOOL_CALL_ID_WEATHER_PARALLEL ,
246239 "get_weather" ,
@@ -275,8 +268,8 @@ def test_user_assistant_text_two_parallel_tool_calls_and_results_with_tools():
275268 {"type" : "function" , ** GET_TIME_TOOL .function .model_dump ()},
276269 ]
277270 assert payload .get ("input" ) == [
278- _msg_turn ( "user " , PARALLEL_USER_PROMPT ),
279- _msg_turn ( "model " , ASSISTANT_TEXT_WITH_PARALLEL_TOOLS ),
271+ _msg_step ( "user_input " , PARALLEL_USER_PROMPT ),
272+ _msg_step ( "model_output " , ASSISTANT_TEXT_WITH_PARALLEL_TOOLS ),
280273 _model_function_call_turn (
281274 TOOL_CALL_ID_WEATHER_PARALLEL ,
282275 "get_weather" ,
@@ -319,7 +312,7 @@ def test_assistant_message_mixed_output_text_and_refusal_maps_to_text_parts():
319312 {"type" : "text" , "text" : "Partial." },
320313 {"type" : "text" , "text" : "Stopped." },
321314 ],
322- "role " : "model " ,
315+ "type " : "model_output " ,
323316 }
324317 ]
325318 validate_google_interaction_params (payload )
0 commit comments