|
29 | 29 | "source": [ |
30 | 30 | "#| export\n", |
31 | 31 | "from litellm.integrations.custom_logger import CustomLogger\n", |
32 | | - "from fastcore.utils import patch\n", |
| 32 | + "from fastcore.utils import *\n", |
33 | 33 | "import time\n", |
34 | | - "try: \n", |
35 | | - " from fastlite import *\n", |
36 | | - " from fastlite.core import dataclass\n", |
| 34 | + "try: from fastlite import *\n", |
37 | 35 | "except ImportError: raise ImportError(\"Please install `fastlite` to use sqlite based lisette usage logging.\")" |
38 | 36 | ] |
39 | 37 | }, |
|
46 | 44 | "source": [ |
47 | 45 | "import litellm, importlib, httpx\n", |
48 | 46 | "from lisette.core import Chat, AsyncChat, patch_litellm\n", |
49 | | - "from fastcore.all import *\n", |
50 | | - "from cachy import enable_cachy" |
| 47 | + "from cachy import enable_cachy\n", |
| 48 | + "from fastcore.test import *" |
51 | 49 | ] |
52 | 50 | }, |
53 | 51 | { |
|
461 | 459 | "- id: `chatcmpl-xxx`\n", |
462 | 460 | "- model: `claude-sonnet-4-5-20250929`\n", |
463 | 461 | "- finish_reason: `stop`\n", |
464 | | - "- usage: `Usage(completion_tokens=11, prompt_tokens=14, total_tokens=25, completion_tokens_details=None, prompt_tokens_details=PromptTokensDetailsWrapper(audio_tokens=None, cached_tokens=0, text_tokens=None, image_tokens=None), cache_creation_input_tokens=0, cache_read_input_tokens=0)`\n", |
| 462 | + "- usage: `Usage(completion_tokens=11, prompt_tokens=14, total_tokens=25, completion_tokens_details=None, prompt_tokens_details=PromptTokensDetailsWrapper(audio_tokens=None, cached_tokens=0, text_tokens=None, image_tokens=None, cache_creation_tokens=0, cache_creation_token_details=CacheCreationTokenDetails(ephemeral_5m_input_tokens=0, ephemeral_1h_input_tokens=0)), cache_creation_input_tokens=0, cache_read_input_tokens=0)`\n", |
465 | 463 | "\n", |
466 | 464 | "</details>" |
467 | 465 | ], |
468 | 466 | "text/plain": [ |
469 | | - "ModelResponse(id='chatcmpl-xxx', created=1000000000, model='claude-sonnet-4-5-20250929', object='chat.completion', system_fingerprint=None, choices=[Choices(finish_reason='stop', index=0, message=Message(content='2+2 = 4', role='assistant', tool_calls=None, function_call=None, provider_specific_fields={'citations': None, 'thinking_blocks': None}))], usage=Usage(completion_tokens=11, prompt_tokens=14, total_tokens=25, completion_tokens_details=None, prompt_tokens_details=PromptTokensDetailsWrapper(audio_tokens=None, cached_tokens=0, text_tokens=None, image_tokens=None), cache_creation_input_tokens=0, cache_read_input_tokens=0))" |
| 467 | + "ModelResponse(id='chatcmpl-xxx', created=1000000000, model='claude-sonnet-4-5-20250929', object='chat.completion', system_fingerprint=None, choices=[Choices(finish_reason='stop', index=0, message=Message(content='2+2 = 4', role='assistant', tool_calls=None, function_call=None, provider_specific_fields={'citations': None, 'thinking_blocks': None}))], usage=Usage(completion_tokens=11, prompt_tokens=14, total_tokens=25, completion_tokens_details=None, prompt_tokens_details=PromptTokensDetailsWrapper(audio_tokens=None, cached_tokens=0, text_tokens=None, image_tokens=None, cache_creation_tokens=0, cache_creation_token_details=CacheCreationTokenDetails(ephemeral_5m_input_tokens=0, ephemeral_1h_input_tokens=0)), cache_creation_input_tokens=0, cache_read_input_tokens=0))" |
470 | 468 | ] |
471 | 469 | }, |
472 | 470 | "execution_count": null, |
|
595 | 593 | "- id: `chatcmpl-xxx`\n", |
596 | 594 | "- model: `claude-sonnet-4-5-20250929`\n", |
597 | 595 | "- finish_reason: `stop`\n", |
598 | | - "- usage: `Usage(completion_tokens=13, prompt_tokens=14, total_tokens=27, completion_tokens_details=None, prompt_tokens_details=PromptTokensDetailsWrapper(audio_tokens=None, cached_tokens=0, text_tokens=None, image_tokens=None), cache_creation_input_tokens=0, cache_read_input_tokens=0)`\n", |
| 596 | + "- usage: `Usage(completion_tokens=13, prompt_tokens=14, total_tokens=27, completion_tokens_details=None, prompt_tokens_details=PromptTokensDetailsWrapper(audio_tokens=None, cached_tokens=0, text_tokens=None, image_tokens=None, cache_creation_tokens=0, cache_creation_token_details=CacheCreationTokenDetails(ephemeral_5m_input_tokens=0, ephemeral_1h_input_tokens=0)), cache_creation_input_tokens=0, cache_read_input_tokens=0)`\n", |
599 | 597 | "\n", |
600 | 598 | "</details>" |
601 | 599 | ], |
602 | 600 | "text/plain": [ |
603 | | - "ModelResponse(id='chatcmpl-xxx', created=1000000000, model='claude-sonnet-4-5-20250929', object='chat.completion', system_fingerprint=None, choices=[Choices(finish_reason='stop', index=0, message=Message(content='3 + 3 = 6', role='assistant', tool_calls=None, function_call=None, provider_specific_fields={'citations': None, 'thinking_blocks': None}))], usage=Usage(completion_tokens=13, prompt_tokens=14, total_tokens=27, completion_tokens_details=None, prompt_tokens_details=PromptTokensDetailsWrapper(audio_tokens=None, cached_tokens=0, text_tokens=None, image_tokens=None), cache_creation_input_tokens=0, cache_read_input_tokens=0))" |
| 601 | + "ModelResponse(id='chatcmpl-xxx', created=1000000000, model='claude-sonnet-4-5-20250929', object='chat.completion', system_fingerprint=None, choices=[Choices(finish_reason='stop', index=0, message=Message(content='3 + 3 = 6', role='assistant', tool_calls=None, function_call=None, provider_specific_fields={'citations': None, 'thinking_blocks': None}))], usage=Usage(completion_tokens=13, prompt_tokens=14, total_tokens=27, completion_tokens_details=None, prompt_tokens_details=PromptTokensDetailsWrapper(audio_tokens=None, cached_tokens=0, text_tokens=None, image_tokens=None, cache_creation_tokens=0, cache_creation_token_details=CacheCreationTokenDetails(ephemeral_5m_input_tokens=0, ephemeral_1h_input_tokens=0)), cache_creation_input_tokens=0, cache_read_input_tokens=0))" |
604 | 602 | ] |
605 | 603 | }, |
606 | 604 | "execution_count": null, |
|
663 | 661 | "name": "stdout", |
664 | 662 | "output_type": "stream", |
665 | 663 | "text": [ |
666 | | - "ModelResponse(id='chatcmpl-xxx', created=1000000000, model='claude-sonnet-4-5-20250929', object='chat.completion', system_fingerprint=None, choices=[Choices(finish_reason='stop', index=0, message=Message(content='10, 11, 12, 13, 14, 15', role='assistant', tool_calls=None, function_call=None, provider_specific_fields=None))], usage=Usage(completion_tokens=20, prompt_tokens=38, total_tokens=58, completion_tokens_details=CompletionTokensDetailsWrapper(accepted_prediction_tokens=None, audio_tokens=None, reasoning_tokens=0, rejected_prediction_tokens=None, text_tokens=None), prompt_tokens_details=None))\n" |
| 664 | + "ModelResponse(id='chatcmpl-xxx', created=1000000000, model='claude-sonnet-4-5-20250929', object='chat.completion', system_fingerprint=None, choices=[Choices(finish_reason='stop', index=0, message=Message(content='10, 11, 12, 13, 14, 15', role='assistant', tool_calls=None, function_call=None, provider_specific_fields=None))], usage=Usage(completion_tokens=20, prompt_tokens=38, total_tokens=58, completion_tokens_details=CompletionTokensDetailsWrapper(accepted_prediction_tokens=None, audio_tokens=None, reasoning_tokens=0, rejected_prediction_tokens=None, text_tokens=None, image_tokens=None), prompt_tokens_details=None))\n" |
667 | 665 | ] |
668 | 666 | } |
669 | 667 | ], |
|
740 | 738 | "- id: `chatcmpl-xxx`\n", |
741 | 739 | "- model: `claude-sonnet-4-5-20250929`\n", |
742 | 740 | "- finish_reason: `stop`\n", |
743 | | - "- usage: `Usage(completion_tokens=318, prompt_tokens=12012, total_tokens=12330, completion_tokens_details=None, prompt_tokens_details=PromptTokensDetailsWrapper(audio_tokens=None, cached_tokens=0, text_tokens=None, image_tokens=None), server_tool_use=ServerToolUse(web_search_requests=1), cache_creation_input_tokens=0, cache_read_input_tokens=0)`\n", |
| 741 | + "- usage: `Usage(completion_tokens=318, prompt_tokens=12012, total_tokens=12330, completion_tokens_details=None, prompt_tokens_details=PromptTokensDetailsWrapper(audio_tokens=None, cached_tokens=0, text_tokens=None, image_tokens=None, cache_creation_tokens=0, cache_creation_token_details=CacheCreationTokenDetails(ephemeral_5m_input_tokens=0, ephemeral_1h_input_tokens=0)), server_tool_use=ServerToolUse(web_search_requests=1), cache_creation_input_tokens=0, cache_read_input_tokens=0)`\n", |
744 | 742 | "\n", |
745 | 743 | "</details>" |
746 | 744 | ], |
747 | 745 | "text/plain": [ |
748 | | - "ModelResponse(id='chatcmpl-xxx', created=1000000000, model='claude-sonnet-4-5-20250929', object='chat.completion', system_fingerprint=None, choices=[Choices(finish_reason='stop', index=0, message=Message(content='Based on the current weather information for New York City:\\n\\n**Today (December 2, 2025):**\\nRain, mainly after 7am, with a high near 43°F. Chance of precipitation is 100% with new precipitation amounts between three quarters and one inch possible. North wind 5 to 13 mph.\\n\\n**Tonight:**\\nA 20 percent chance of rain before 10pm, then cloudy during the early evening with gradual clearing and a low around 32°F.\\n\\n**Air Quality:**\\nThe air has reached a high level of pollution and is unhealthy for sensitive groups.\\n\\nThe weather is rainy and cool today with temperatures in the low 40s, and it will clear up tonight with temperatures dropping to freezing.', role='assistant', tool_calls=None, function_call=None, provider_specific_fields={'citations': [[{'type': 'web_search_result_location', 'cited_text': 'Rain, mainly after 7am. High near 43. ', 'url': 'https://forecast.weather.gov/MapClick.php?lon=-73.99419&lat=40.71593', 'title': 'National Weather Service', 'encrypted_index': 'EpEBCioIChgCIiQ4ODk4YTFkYy0yMTNkLTRhNmYtOTljYi03ZTBlNTUzZDc0NWISDPut3lyE5unJezaGqxoMLq+4uYjJON8nKg1nIjA7lcAEX2A6D3a/veHjegcDsT0KulT7jKeP4y/2XC1DaHuFcvF7po/tURoRYaVmVSsqFXMRP85K6T1OnbQETLrgzILBi+j6VRgE'}], [{'type': 'web_search_result_location', 'cited_text': 'Chance of precipitation is 100%. New precipitation amounts between three quarters and one inch possible. ', 'url': 'https://forecast.weather.gov/MapClick.php?lon=-73.99419&lat=40.71593', 'title': 'National Weather Service', 'encrypted_index': 'EpIBCioIChgCIiQ4ODk4YTFkYy0yMTNkLTRhNmYtOTljYi03ZTBlNTUzZDc0NWISDBPyfYnD1KvAYxpJ7xoMQMIdjxheRZpRkKv9IjBIdn3trXl8W6Xl86I3+kdQCHC8I4Pu1zqxAGo6MpY99o1mgW/UwykEfsBJqf+nsHMqFgH22UUcNMVqgS72HaSINLjarvBKDpIYBA=='}], [{'type': 'web_search_result_location', 'cited_text': 'North wind 5 to 13 mph. ', 'url': 'https://forecast.weather.gov/MapClick.php?lon=-73.99419&lat=40.71593', 'title': 'National Weather Service', 'encrypted_index': 'Eo8BCioIChgCIiQ4ODk4YTFkYy0yMTNkLTRhNmYtOTljYi03ZTBlNTUzZDc0NWISDBttfpOIWWVA2INwUhoMnDpaPw9Qh4aSA5B1IjBt5Bg0tYYbwgOgPOSE9m0Mei7eKzvppWhJMe/OC/7l4xd6qBljbYA0KF7MVUpVUsMqE4kHtHeW8lFPOgtkPK4D/c9pPSIYBA=='}], [{'type': 'web_search_result_location', 'cited_text': '... A 20 percent chance of rain before 10pm. Cloudy during the early evening, then gradual clearing, with a low around 32. ', 'url': 'https://forecast.weather.gov/MapClick.php?lon=-73.99419&lat=40.71593', 'title': 'National Weather Service', 'encrypted_index': 'EpMBCioIChgCIiQ4ODk4YTFkYy0yMTNkLTRhNmYtOTljYi03ZTBlNTUzZDc0NWISDMQgy3vA/OPch/mlshoMkb0uiMHEj2IsSDADIjBs1ZmSgXe4vvNkuIJTrfiqMssxNE7WI2BsH6TOkP3Ju5I2aQcLQe0i2neuN/f3np4qF5Nfez6AxWSnoHdggd26t8ahsiGx+X20GAQ='}], [{'type': 'web_search_result_location', 'cited_text': 'The air has reached a high level of pollution and is unhealthy for sensitive groups. ', 'url': 'https://www.accuweather.com/en/us/new-york/10021/weather-forecast/14-349727_1_al', 'title': 'New York City, NY Weather Forecast | AccuWeather', 'encrypted_index': 'EpABCioIChgCIiQ4ODk4YTFkYy0yMTNkLTRhNmYtOTljYi03ZTBlNTUzZDc0NWISDGIn8NEKIH9Cs42ihBoMvrQe3BWWn1KfZUgiIjCD3kmwLyr+q0mUxgWBvQupYVn/WbLKqgsPKXiBo1UQUIciAUdF24B5UOMfMq8ES+cqFL2z+0v8U0GhAknxzr8NnuPslNllGAQ='}]], 'thinking_blocks': None}))], usage=Usage(completion_tokens=318, prompt_tokens=12012, total_tokens=12330, completion_tokens_details=None, prompt_tokens_details=PromptTokensDetailsWrapper(audio_tokens=None, cached_tokens=0, text_tokens=None, image_tokens=None), server_tool_use=ServerToolUse(web_search_requests=1), cache_creation_input_tokens=0, cache_read_input_tokens=0))" |
| 746 | + "ModelResponse(id='chatcmpl-xxx', created=1000000000, model='claude-sonnet-4-5-20250929', object='chat.completion', system_fingerprint=None, choices=[Choices(finish_reason='stop', index=0, message=Message(content='Based on the current weather information for New York City:\\n\\n**Today (December 2, 2025):**\\nRain, mainly after 7am, with a high near 43°F. Chance of precipitation is 100% with new precipitation amounts between three quarters and one inch possible. North wind 5 to 13 mph.\\n\\n**Tonight:**\\nA 20 percent chance of rain before 10pm, then cloudy during the early evening with gradual clearing and a low around 32°F.\\n\\n**Air Quality:**\\nThe air has reached a high level of pollution and is unhealthy for sensitive groups.\\n\\nThe weather is rainy and cool today with temperatures in the low 40s, and it will clear up tonight with temperatures dropping to freezing.', role='assistant', tool_calls=None, function_call=None, provider_specific_fields={'citations': [[{'type': 'web_search_result_location', 'cited_text': 'Rain, mainly after 7am. High near 43. ', 'url': 'https://forecast.weather.gov/MapClick.php?lon=-73.99419&lat=40.71593', 'title': 'National Weather Service', 'encrypted_index': 'EpEBCioIChgCIiQ4ODk4YTFkYy0yMTNkLTRhNmYtOTljYi03ZTBlNTUzZDc0NWISDPut3lyE5unJezaGqxoMLq+4uYjJON8nKg1nIjA7lcAEX2A6D3a/veHjegcDsT0KulT7jKeP4y/2XC1DaHuFcvF7po/tURoRYaVmVSsqFXMRP85K6T1OnbQETLrgzILBi+j6VRgE', 'supported_text': 'Rain, mainly after 7am, with a high near 43°F'}], [{'type': 'web_search_result_location', 'cited_text': 'Chance of precipitation is 100%. New precipitation amounts between three quarters and one inch possible. ', 'url': 'https://forecast.weather.gov/MapClick.php?lon=-73.99419&lat=40.71593', 'title': 'National Weather Service', 'encrypted_index': 'EpIBCioIChgCIiQ4ODk4YTFkYy0yMTNkLTRhNmYtOTljYi03ZTBlNTUzZDc0NWISDBPyfYnD1KvAYxpJ7xoMQMIdjxheRZpRkKv9IjBIdn3trXl8W6Xl86I3+kdQCHC8I4Pu1zqxAGo6MpY99o1mgW/UwykEfsBJqf+nsHMqFgH22UUcNMVqgS72HaSINLjarvBKDpIYBA==', 'supported_text': 'Chance of precipitation is 100% with new precipitation amounts between three quarters and one inch possible'}], [{'type': 'web_search_result_location', 'cited_text': 'North wind 5 to 13 mph. ', 'url': 'https://forecast.weather.gov/MapClick.php?lon=-73.99419&lat=40.71593', 'title': 'National Weather Service', 'encrypted_index': 'Eo8BCioIChgCIiQ4ODk4YTFkYy0yMTNkLTRhNmYtOTljYi03ZTBlNTUzZDc0NWISDBttfpOIWWVA2INwUhoMnDpaPw9Qh4aSA5B1IjBt5Bg0tYYbwgOgPOSE9m0Mei7eKzvppWhJMe/OC/7l4xd6qBljbYA0KF7MVUpVUsMqE4kHtHeW8lFPOgtkPK4D/c9pPSIYBA==', 'supported_text': 'North wind 5 to 13 mph'}], [{'type': 'web_search_result_location', 'cited_text': '... A 20 percent chance of rain before 10pm. Cloudy during the early evening, then gradual clearing, with a low around 32. ', 'url': 'https://forecast.weather.gov/MapClick.php?lon=-73.99419&lat=40.71593', 'title': 'National Weather Service', 'encrypted_index': 'EpMBCioIChgCIiQ4ODk4YTFkYy0yMTNkLTRhNmYtOTljYi03ZTBlNTUzZDc0NWISDMQgy3vA/OPch/mlshoMkb0uiMHEj2IsSDADIjBs1ZmSgXe4vvNkuIJTrfiqMssxNE7WI2BsH6TOkP3Ju5I2aQcLQe0i2neuN/f3np4qF5Nfez6AxWSnoHdggd26t8ahsiGx+X20GAQ=', 'supported_text': 'A 20 percent chance of rain before 10pm, then cloudy during the early evening with gradual clearing and a low around 32°F'}], [{'type': 'web_search_result_location', 'cited_text': 'The air has reached a high level of pollution and is unhealthy for sensitive groups. ', 'url': 'https://www.accuweather.com/en/us/new-york/10021/weather-forecast/14-349727_1_al', 'title': 'New York City, NY Weather Forecast | AccuWeather', 'encrypted_index': 'EpABCioIChgCIiQ4ODk4YTFkYy0yMTNkLTRhNmYtOTljYi03ZTBlNTUzZDc0NWISDGIn8NEKIH9Cs42ihBoMvrQe3BWWn1KfZUgiIjCD3kmwLyr+q0mUxgWBvQupYVn/WbLKqgsPKXiBo1UQUIciAUdF24B5UOMfMq8ES+cqFL2z+0v8U0GhAknxzr8NnuPslNllGAQ=', 'supported_text': 'The air has reached a high level of pollution and is unhealthy for sensitive groups'}]], 'thinking_blocks': None}))], usage=Usage(completion_tokens=318, prompt_tokens=12012, total_tokens=12330, completion_tokens_details=None, prompt_tokens_details=PromptTokensDetailsWrapper(audio_tokens=None, cached_tokens=0, text_tokens=None, image_tokens=None, cache_creation_tokens=0, cache_creation_token_details=CacheCreationTokenDetails(ephemeral_5m_input_tokens=0, ephemeral_1h_input_tokens=0)), server_tool_use=ServerToolUse(web_search_requests=1), cache_creation_input_tokens=0, cache_read_input_tokens=0))" |
749 | 747 | ] |
750 | 748 | }, |
751 | 749 | "execution_count": null, |
|
848 | 846 | { |
849 | 847 | "data": { |
850 | 848 | "text/plain": [ |
851 | | - "Usage(id=6, timestamp=UNSET, model='claude-sonnet-4-5', user_id='user-123', prompt_tokens=12012, completion_tokens=318, total_tokens=12330, cached_tokens=0, cache_creation_tokens=0, cache_read_tokens=0, web_search_requests=None, response_cost=None)" |
| 849 | + "Usage(id=6, timestamp=UNSET, model='claude-sonnet-4-5', user_id='user-123', prompt_tokens=12012, completion_tokens=318, total_tokens=12330, cached_tokens=0, cache_creation_tokens=0, cache_read_tokens=0, web_search_requests=None, response_cost=0.040805999999999995)" |
852 | 850 | ] |
853 | 851 | }, |
854 | 852 | "execution_count": null, |
|
967 | 965 | "source": [] |
968 | 966 | } |
969 | 967 | ], |
970 | | - "metadata": { |
971 | | - "kernelspec": { |
972 | | - "display_name": "python3", |
973 | | - "language": "python", |
974 | | - "name": "python3" |
975 | | - } |
976 | | - }, |
| 968 | + "metadata": {}, |
977 | 969 | "nbformat": 4, |
978 | 970 | "nbformat_minor": 5 |
979 | 971 | } |
0 commit comments