Skip to content

Commit bc2e986

Browse files
committed
fix missing usage import
1 parent 10a296b commit bc2e986

File tree

2 files changed

+15
-25
lines changed

2 files changed

+15
-25
lines changed

lisette/usage.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,9 @@
77

88
# %% ../nbs/01_usage.ipynb
99
from litellm.integrations.custom_logger import CustomLogger
10-
from fastcore.utils import patch
10+
from fastcore.utils import *
1111
import time
12-
try:
13-
from fastlite import *
14-
from fastlite.core import dataclass
12+
try: from fastlite import *
1513
except ImportError: raise ImportError("Please install `fastlite` to use sqlite based lisette usage logging.")
1614

1715
# %% ../nbs/01_usage.ipynb

nbs/01_usage.ipynb

Lines changed: 13 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -29,11 +29,9 @@
2929
"source": [
3030
"#| export\n",
3131
"from litellm.integrations.custom_logger import CustomLogger\n",
32-
"from fastcore.utils import patch\n",
32+
"from fastcore.utils import *\n",
3333
"import time\n",
34-
"try: \n",
35-
" from fastlite import *\n",
36-
" from fastlite.core import dataclass\n",
34+
"try: from fastlite import *\n",
3735
"except ImportError: raise ImportError(\"Please install `fastlite` to use sqlite based lisette usage logging.\")"
3836
]
3937
},
@@ -46,8 +44,8 @@
4644
"source": [
4745
"import litellm, importlib, httpx\n",
4846
"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 *"
5149
]
5250
},
5351
{
@@ -461,12 +459,12 @@
461459
"- id: `chatcmpl-xxx`\n",
462460
"- model: `claude-sonnet-4-5-20250929`\n",
463461
"- 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",
465463
"\n",
466464
"</details>"
467465
],
468466
"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))"
470468
]
471469
},
472470
"execution_count": null,
@@ -595,12 +593,12 @@
595593
"- id: `chatcmpl-xxx`\n",
596594
"- model: `claude-sonnet-4-5-20250929`\n",
597595
"- 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",
599597
"\n",
600598
"</details>"
601599
],
602600
"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))"
604602
]
605603
},
606604
"execution_count": null,
@@ -663,7 +661,7 @@
663661
"name": "stdout",
664662
"output_type": "stream",
665663
"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"
667665
]
668666
}
669667
],
@@ -740,12 +738,12 @@
740738
"- id: `chatcmpl-xxx`\n",
741739
"- model: `claude-sonnet-4-5-20250929`\n",
742740
"- 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",
744742
"\n",
745743
"</details>"
746744
],
747745
"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))"
749747
]
750748
},
751749
"execution_count": null,
@@ -848,7 +846,7 @@
848846
{
849847
"data": {
850848
"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)"
852850
]
853851
},
854852
"execution_count": null,
@@ -967,13 +965,7 @@
967965
"source": []
968966
}
969967
],
970-
"metadata": {
971-
"kernelspec": {
972-
"display_name": "python3",
973-
"language": "python",
974-
"name": "python3"
975-
}
976-
},
968+
"metadata": {},
977969
"nbformat": 4,
978970
"nbformat_minor": 5
979971
}

0 commit comments

Comments
 (0)