File size: 2,835 Bytes
95f8c4b | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 | 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==",
}
]
|