|
108 | 108 | "outputs": [], |
109 | 109 | "source": [ |
110 | 110 | "#| export\n", |
111 | | - "def patch_litellm():\n", |
| 111 | + "def patch_litellm(seed=0):\n", |
112 | 112 | " \"Patch litellm.ModelResponseBase such that `id` and `created` are fixed.\"\n", |
113 | 113 | " from litellm.types.utils import ModelResponseBase\n", |
114 | 114 | " @patch\n", |
|
119 | 119 | " def __setattr__(self: ModelResponseBase, name, value):\n", |
120 | 120 | " if name == 'id': value = 'chatcmpl-xxx'\n", |
121 | 121 | " elif name == 'created': value = 1000000000\n", |
122 | | - " self._orig___setattr__(name, value)" |
| 122 | + " self._orig___setattr__(name, value)\n", |
| 123 | + "\n", |
| 124 | + " if seed is not None: random.seed(seed) # ensures random ids like tool call ids are deterministic" |
123 | 125 | ] |
124 | 126 | }, |
125 | 127 | { |
|
2012 | 2014 | { |
2013 | 2015 | "data": { |
2014 | 2016 | "text/plain": [ |
2015 | | - "'toolu_uGSrbSMWW0GImQFyEbrRj8Omp'" |
| 2017 | + "'toolu_0UAqFzWsDK4FrUMp48Y3tT3QD'" |
2016 | 2018 | ] |
2017 | 2019 | }, |
2018 | 2020 | "execution_count": null, |
|
2058 | 2060 | "text/plain": [ |
2059 | 2061 | "{'index': 1,\n", |
2060 | 2062 | " 'function': {'arguments': '{\"a\": 5, \"b\": 7}', 'name': 'simple_add'},\n", |
2061 | | - " 'id': 'toolu_9UH5zWCU7UdQvyEklvJkxzHW6',\n", |
| 2063 | + " 'id': 'toolu_gAL47D1qXIaSyZPaE1pu1lJo7',\n", |
2062 | 2064 | " 'type': 'function'}" |
2063 | 2065 | ] |
2064 | 2066 | }, |
|
2099 | 2101 | { |
2100 | 2102 | "data": { |
2101 | 2103 | "text/plain": [ |
2102 | | - "Message(content=\"I'll use the simple_add tool to calculate 5 + 7 for you.\", role='assistant', tool_calls=[ChatCompletionMessageToolCall(index=1, function=Function(arguments='{\"a\": 5, \"b\": 7}', name='simple_add'), id='toolu_9UH5zWCU7UdQvyEklvJkxzHW6', type='function')], function_call=None, provider_specific_fields=None)" |
| 2104 | + "Message(content=\"I'll use the simple_add tool to calculate 5 + 7 for you.\", role='assistant', tool_calls=[ChatCompletionMessageToolCall(index=1, function=Function(arguments='{\"a\": 5, \"b\": 7}', name='simple_add'), id='toolu_gAL47D1qXIaSyZPaE1pu1lJo7', type='function')], function_call=None, provider_specific_fields=None)" |
2103 | 2105 | ] |
2104 | 2106 | }, |
2105 | 2107 | "execution_count": null, |
|
2145 | 2147 | { |
2146 | 2148 | "data": { |
2147 | 2149 | "text/plain": [ |
2148 | | - "Message(content=\"I'll use the simple_add tool to calculate 5 + 7 for you.\", role='assistant', tool_calls=[{'index': 1, 'function': {'arguments': '{\"a\": 5, \"b\": 7}', 'name': 'simple_add'}, 'id': 'toolu_9UH5zWCU7UdQvyEklvJkxzHW6', 'type': 'function'}], function_call=None, provider_specific_fields=None)" |
| 2150 | + "Message(content=\"I'll use the simple_add tool to calculate 5 + 7 for you.\", role='assistant', tool_calls=[{'index': 1, 'function': {'arguments': '{\"a\": 5, \"b\": 7}', 'name': 'simple_add'}, 'id': 'toolu_gAL47D1qXIaSyZPaE1pu1lJo7', 'type': 'function'}], function_call=None, provider_specific_fields=None)" |
2149 | 2151 | ] |
2150 | 2152 | }, |
2151 | 2153 | "execution_count": null, |
|
2180 | 2182 | "text": [ |
2181 | 2183 | "{'role': 'user', 'content': 'What is 5 + 7? Use the tool to calculate it.'}\n", |
2182 | 2184 | "\n", |
2183 | | - "Message(content=\"I'll use the simple_add tool to calculate 5 + 7 for you.\", role='assistant', tool_calls=[{'index': 1, 'function': {'arguments': '{\"a\": 5, \"b\": 7}', 'name': 'simple_add'}, 'id': 'toolu_9UH5zWCU7UdQvyEklvJkxzHW6', 'type': 'function'}], function_call=None, provider_specific_fields=None)\n", |
| 2185 | + "Message(content=\"I'll use the simple_add tool to calculate 5 + 7 for you.\", role='assistant', tool_calls=[{'index': 1, 'function': {'arguments': '{\"a\": 5, \"b\": 7}', 'name': 'simple_add'}, 'id': 'toolu_gAL47D1qXIaSyZPaE1pu1lJo7', 'type': 'function'}], function_call=None, provider_specific_fields=None)\n", |
2184 | 2186 | "\n" |
2185 | 2187 | ] |
2186 | 2188 | } |
|
2227 | 2229 | "text/plain": [ |
2228 | 2230 | "{'index': 1,\n", |
2229 | 2231 | " 'function': {'arguments': '{\"a\": 5, \"b\": 7}', 'name': 'simple_add'},\n", |
2230 | | - " 'id': 'toolu_9UH5zWCU7UdQvyEklvJkxzHW6',\n", |
| 2232 | + " 'id': 'toolu_gAL47D1qXIaSyZPaE1pu1lJo7',\n", |
2231 | 2233 | " 'type': 'function'}" |
2232 | 2234 | ] |
2233 | 2235 | }, |
|
2249 | 2251 | { |
2250 | 2252 | "data": { |
2251 | 2253 | "text/plain": [ |
2252 | | - "{'tool_call_id': 'toolu_9UH5zWCU7UdQvyEklvJkxzHW6',\n", |
| 2254 | + "{'tool_call_id': 'toolu_gAL47D1qXIaSyZPaE1pu1lJo7',\n", |
2253 | 2255 | " 'role': 'tool',\n", |
2254 | 2256 | " 'name': 'simple_add',\n", |
2255 | 2257 | " 'content': '12'}" |
|
2292 | 2294 | { |
2293 | 2295 | "data": { |
2294 | 2296 | "text/plain": [ |
2295 | | - "Message(content=\"I'll use the simple_add tool to calculate 5 + 7 for you.\", role='assistant', tool_calls=[{'index': 1, 'function': {'arguments': '{\"a\": 5, \"b\": 7}', 'name': 'simple_add'}, 'id': 'toolu_cuVdHN21LcyRt6MOrWsT2UKGU', 'type': 'function'}], function_call=None, provider_specific_fields=None)" |
| 2297 | + "Message(content=\"I'll use the simple_add tool to calculate 5 + 7 for you.\", role='assistant', tool_calls=[{'index': 1, 'function': {'arguments': '{\"a\": 5, \"b\": 7}', 'name': 'simple_add'}, 'id': 'toolu_gAL47D1qXIaSyZPaE1pu1lJo7', 'type': 'function'}], function_call=None, provider_specific_fields=None)" |
2296 | 2298 | ] |
2297 | 2299 | }, |
2298 | 2300 | "execution_count": null, |
|
2313 | 2315 | { |
2314 | 2316 | "data": { |
2315 | 2317 | "text/plain": [ |
2316 | | - "[{'tool_call_id': 'toolu_cuVdHN21LcyRt6MOrWsT2UKGU',\n", |
| 2318 | + "[{'tool_call_id': 'toolu_gAL47D1qXIaSyZPaE1pu1lJo7',\n", |
2317 | 2319 | " 'role': 'tool',\n", |
2318 | 2320 | " 'name': 'simple_add',\n", |
2319 | 2321 | " 'content': '12'}]" |
|
2382 | 2384 | "text": [ |
2383 | 2385 | "{'role': 'user', 'content': 'What is 5 + 7? Use the tool to calculate it.'}\n", |
2384 | 2386 | "\n", |
2385 | | - "Message(content=\"I'll use the simple_add tool to calculate 5 + 7 for you.\", role='assistant', tool_calls=[{'index': 1, 'function': {'arguments': '{\"a\": 5, \"b\": 7}', 'name': 'simple_add'}, 'id': 'toolu_cuVdHN21LcyRt6MOrWsT2UKGU', 'type': 'function'}], function_call=None, provider_specific_fields=None)\n", |
| 2387 | + "Message(content=\"I'll use the simple_add tool to calculate 5 + 7 for you.\", role='assistant', tool_calls=[{'index': 1, 'function': {'arguments': '{\"a\": 5, \"b\": 7}', 'name': 'simple_add'}, 'id': 'toolu_gAL47D1qXIaSyZPaE1pu1lJo7', 'type': 'function'}], function_call=None, provider_specific_fields=None)\n", |
2386 | 2388 | "\n", |
2387 | | - "{'tool_call_id': 'toolu_cuVdHN21LcyRt6MOrWsT2UKGU', 'role': 'tool', 'name': 'simple_add', 'content': '12'}\n", |
| 2389 | + "{'tool_call_id': 'toolu_gAL47D1qXIaSyZPaE1pu1lJo7', 'role': 'tool', 'name': 'simple_add', 'content': '12'}\n", |
2388 | 2390 | "\n", |
2389 | 2391 | "Message(content='The result of 5 + 7 is **12**.', role='assistant', tool_calls=None, function_call=None, provider_specific_fields={'citations': None, 'thinking_blocks': None})\n", |
2390 | 2392 | "\n" |
|
2422 | 2424 | { |
2423 | 2425 | "data": { |
2424 | 2426 | "text/plain": [ |
2425 | | - "[{'tool_call_id': 'toolu_cuVdHN21LcyRt6MOrWsT2UKGU',\n", |
| 2427 | + "[{'tool_call_id': 'toolu_gAL47D1qXIaSyZPaE1pu1lJo7',\n", |
2426 | 2428 | " 'role': 'tool',\n", |
2427 | 2429 | " 'name': 'simple_add',\n", |
2428 | 2430 | " 'content': '13'}]" |
|
2498 | 2500 | { |
2499 | 2501 | "data": { |
2500 | 2502 | "text/plain": [ |
2501 | | - "Message(content='I will calculate these for you!', role='assistant', tool_calls=[{'index': 1, 'function': {'arguments': '{\"a\": 5, \"b\": 7}', 'name': 'simple_add'}, 'id': 'toolu_qretEWrUWV7xLLLIJbUV2257H', 'type': 'function'}, {'index': 1, 'function': {'arguments': '{\"a\": 6, \"b\": 7}', 'name': 'simple_add'}, 'id': 'toolu_uRfaA9XJcaKJtRX81UZwXZAP0', 'type': 'function'}], function_call=None, provider_specific_fields=None)" |
| 2503 | + "Message(content='I will calculate these for you!', role='assistant', tool_calls=[{'index': 1, 'function': {'arguments': '{\"a\": 5, \"b\": 7}', 'name': 'simple_add'}, 'id': 'toolu_XBetF5gIRHYH7LKBKxJsllLOD', 'type': 'function'}, {'index': 1, 'function': {'arguments': '{\"a\": 6, \"b\": 7}', 'name': 'simple_add'}, 'id': 'toolu_fU25035HyRrY03K6JBO94XfLE', 'type': 'function'}], function_call=None, provider_specific_fields=None)" |
2502 | 2504 | ] |
2503 | 2505 | }, |
2504 | 2506 | "execution_count": null, |
|
2576 | 2578 | "text": [ |
2577 | 2579 | "{'role': 'user', 'content': 'What is 5 + 7? Use the tool to calculate it.'}\n", |
2578 | 2580 | "\n", |
2579 | | - "Message(content='I will calculate these for you!', role='assistant', tool_calls=[{'index': 1, 'function': {'arguments': '{\"a\": 5, \"b\": 7}', 'name': 'simple_add'}, 'id': 'toolu_qretEWrUWV7xLLLIJbUV2257H', 'type': 'function'}, {'index': 1, 'function': {'arguments': '{\"a\": 6, \"b\": 7}', 'name': 'simple_add'}, 'id': 'toolu_uRfaA9XJcaKJtRX81UZwXZAP0', 'type': 'function'}], function_call=None, provider_specific_fields=None)\n", |
| 2581 | + "Message(content='I will calculate these for you!', role='assistant', tool_calls=[{'index': 1, 'function': {'arguments': '{\"a\": 5, \"b\": 7}', 'name': 'simple_add'}, 'id': 'toolu_XBetF5gIRHYH7LKBKxJsllLOD', 'type': 'function'}, {'index': 1, 'function': {'arguments': '{\"a\": 6, \"b\": 7}', 'name': 'simple_add'}, 'id': 'toolu_fU25035HyRrY03K6JBO94XfLE', 'type': 'function'}], function_call=None, provider_specific_fields=None)\n", |
2580 | 2582 | "\n", |
2581 | | - "{'tool_call_id': 'toolu_qretEWrUWV7xLLLIJbUV2257H', 'role': 'tool', 'name': 'simple_add', 'content': '12'}\n", |
| 2583 | + "{'tool_call_id': 'toolu_XBetF5gIRHYH7LKBKxJsllLOD', 'role': 'tool', 'name': 'simple_add', 'content': '12'}\n", |
2582 | 2584 | "\n", |
2583 | | - "{'tool_call_id': 'toolu_uRfaA9XJcaKJtRX81UZwXZAP0', 'role': 'tool', 'name': 'simple_add', 'content': '13'}\n", |
| 2585 | + "{'tool_call_id': 'toolu_fU25035HyRrY03K6JBO94XfLE', 'role': 'tool', 'name': 'simple_add', 'content': '13'}\n", |
2584 | 2586 | "\n", |
2585 | 2587 | "Message(content='The answer is **12**. 5 + 7 = 12', role='assistant', tool_calls=None, function_call=None, provider_specific_fields={'citations': None, 'thinking_blocks': None})\n", |
2586 | 2588 | "\n" |
|
4467 | 4469 | } |
4468 | 4470 | ], |
4469 | 4471 | "metadata": { |
4470 | | - "language_info": { |
4471 | | - "name": "python" |
| 4472 | + "kernelspec": { |
| 4473 | + "display_name": "python3", |
| 4474 | + "language": "python", |
| 4475 | + "name": "python3" |
4472 | 4476 | } |
4473 | 4477 | }, |
4474 | 4478 | "nbformat": 4, |
|
0 commit comments