from aistudio_api.domain.models import parse_response_chunk def test_parse_response_chunk_keeps_raw_function_call_and_response(): chunk = [ [ [ [ [ [None, None, None, ["getWeather", '{"city":"Shanghai"}']], [None, None, None, None, ["getWeather", {"city": "Shanghai", "temperature": "24C"}]], ] ], 1, ] ], None, [5, 1, 6], None, None, None, None, "resp_123", ] candidate = parse_response_chunk(chunk) assert candidate.function_calls == [ { "type": "functionCall", "raw": ["getWeather", '{"city":"Shanghai"}'], "name": "getWeather", "args": {"city": "Shanghai"}, } ] assert candidate.function_responses == [ { "type": "functionResponse", "raw": ["getWeather", {"city": "Shanghai", "temperature": "24C"}], "name": "getWeather", "args": {"city": "Shanghai", "temperature": "24C"}, } ] def test_parse_response_chunk_extracts_real_aistudio_function_call_shape(): chunk = [ [ [ [ [ [ None, None, None, None, None, None, None, None, None, None, [ "getWeather", [[["city", [None, None, "Shanghai"]]]], "e6ni61kr", ], None, None, None, "EiYKJGUyNDgzMGE3LTVjZDYtNDJmZS05OThiLWVlNTM5ZTcyYjljMw==", ] ], "model", ] ] ], None, [52, 15, 147, None, [[1, 52]], None, None, None, None, 80], None, None, None, None, "resp_real", ] candidate = parse_response_chunk(chunk) assert candidate.function_calls == [ { "type": "functionCall", "raw": ["getWeather", [[["city", [None, None, "Shanghai"]]]], "e6ni61kr"], "name": "getWeather", "args": {"city": "Shanghai"}, "call_id": "e6ni61kr", "thought_signature": "EiYKJGUyNDgzMGE3LTVjZDYtNDJmZS05OThiLWVlNTM5ZTcyYjljMw==", } ]