Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
181 changes: 85 additions & 96 deletions cachy.jsonl

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions lisette/_modidx.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
'lisette.core._apply_cache_idxs': ('core.html#_apply_cache_idxs', 'lisette/core.py'),
'lisette.core._bytes2content': ('core.html#_bytes2content', 'lisette/core.py'),
'lisette.core._extract_tool': ('core.html#_extract_tool', 'lisette/core.py'),
'lisette.core._filter_srvtools': ('core.html#_filter_srvtools', 'lisette/core.py'),
'lisette.core._has_cache': ('core.html#_has_cache', 'lisette/core.py'),
'lisette.core._has_search': ('core.html#_has_search', 'lisette/core.py'),
'lisette.core._lite_call_func': ('core.html#_lite_call_func', 'lisette/core.py'),
Expand Down
5 changes: 5 additions & 0 deletions lisette/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,9 @@ def _has_search(m):
i = get_model_info(m)
return bool(i.get('search_context_cost_per_query') or i.get('supports_web_search'))

# %% ../nbs/00_core.ipynb
def _filter_srvtools(tcs): return L(tcs).filter(lambda o: not o.id.startswith('srvtoolu_')) if tcs else None

# %% ../nbs/00_core.ipynb
def cite_footnote(msg):
if not (delta:=nested_idx(msg, 'choices', 0, 'delta')): return
Expand Down Expand Up @@ -312,6 +315,7 @@ def _call(self, msg=None, prefill=None, temp=None, think=None, search=None, stre
res = yield from stream_with_complete(res,postproc=cite_footnotes)
m = contents(res)
if prefill: m.content = prefill + m.content
m.tool_calls = _filter_srvtools(m.tool_calls)
self.hist.append(m)
yield res

Expand Down Expand Up @@ -410,6 +414,7 @@ async def _call(self, msg=None, prefill=None, temp=None, think=None, search=None
m=contents(res)
if prefill: m.content = prefill + m.content
yield res
m.tool_calls = _filter_srvtools(m.tool_calls)
self.hist.append(m)

if tcs := m.tool_calls:
Expand Down
557 changes: 348 additions & 209 deletions nbs/00_core.ipynb

Large diffs are not rendered by default.

29 changes: 15 additions & 14 deletions nbs/01_usage.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -720,30 +720,25 @@
{
"data": {
"text/markdown": [
"Based on the current weather information for New York City:\n",
"Based on the current weather information for New York City today (December 9, 2025):\n",
"\n",
"**Today (December 2, 2025):**\n",
"Rain, 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",
"It's breezy and cold with intervals of clouds and sunshine, with a high of 31°F. Tonight will be variable clouds and very cold with a low of 19°F, making it one of the coldest nights of the season so far.\n",
"\n",
"**Tonight:**\n",
"A 20 percent chance of rain before 10pm, then cloudy during the early evening with gradual clearing and a low around 32°F.\n",
"Sunny skies this morning will give way to mostly cloudy skies during the afternoon, with a high around 35°F and winds from the southwest at 5 to 10 mph.\n",
"\n",
"**Air Quality:**\n",
"The air has reached a high level of pollution and is unhealthy for sensitive groups.\n",
"\n",
"The weather is rainy and cool today with temperatures in the low 40s, and it will clear up tonight with temperatures dropping to freezing.\n",
"It's definitely a day to bundle up and dress warmly for the cold winter weather!\n",
"\n",
"<details>\n",
"\n",
"- id: `chatcmpl-xxx`\n",
"- model: `claude-sonnet-4-5-20250929`\n",
"- finish_reason: `stop`\n",
"- 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",
"- usage: `Usage(completion_tokens=252, prompt_tokens=9945, total_tokens=10197, 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, tool_search_requests=None), cache_creation_input_tokens=0, cache_read_input_tokens=0)`\n",
"\n",
"</details>"
],
"text/plain": [
"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))"
"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 today (December 9, 2025):\\n\\nIt's breezy and cold with intervals of clouds and sunshine, with a high of 31°F. Tonight will be variable clouds and very cold with a low of 19°F, making it one of the coldest nights of the season so far.\\n\\nSunny skies this morning will give way to mostly cloudy skies during the afternoon, with a high around 35°F and winds from the southwest at 5 to 10 mph.\\n\\nIt's definitely a day to bundle up and dress warmly for the cold winter weather!\", role='assistant', tool_calls=[], function_call=None, provider_specific_fields={'citations': [[{'type': 'web_search_result_location', 'cited_text': 'Breezy and colder with intervals of clouds and sunshine; bundle up; it will feel like midwinter Hi: 31° · Tonight: Variable clouds and very cold; dres...', 'url': 'https://www.accuweather.com/en/us/new-york/10021/weather-forecast/349727', 'title': 'New York, NY Weather Forecast | AccuWeather', 'encrypted_index': 'Eo8BCioIChgCIiQ4ODk4YTFkYy0yMTNkLTRhNmYtOTljYi03ZTBlNTUzZDc0NWISDJlgmuV2L2aUxYE3tBoM73eQcwtgLQL9wpBUIjD4Zww4ps8UcOhZ6kew0MPnU1/VlrNpv4Wo8NTu0Bg5duju1/rlgZPyPEKQwQ8YTlUqE0pnBO37KEjH3r5nNaePq9GbZ70YBA==', 'supported_text': \"It's breezy and cold with intervals of clouds and sunshine, with a high of 31°F\"}], [{'type': 'web_search_result_location', 'cited_text': 'Breezy and colder with intervals of clouds and sunshine; bundle up; it will feel like midwinter Hi: 31° · Tonight: Variable clouds and very cold; dres...', 'url': 'https://www.accuweather.com/en/us/new-york/10021/weather-forecast/349727', 'title': 'New York, NY Weather Forecast | AccuWeather', 'encrypted_index': 'Eo8BCioIChgCIiQ4ODk4YTFkYy0yMTNkLTRhNmYtOTljYi03ZTBlNTUzZDc0NWISDOVUrcZwiLhWtRid8xoMokgl/o9pgbWKzha6IjB43wiuYQQg9bAPBsUBR0rprOflmOh6svCRTjkQagDGv/uolGdye66/SA09Mnglq78qE1B8BTqJTClTASpzrDumM58FQisYBA==', 'supported_text': 'Tonight will be variable clouds and very cold with a low of 19°F, making it one of the coldest nights of the season so far'}], [{'type': 'web_search_result_location', 'cited_text': 'Sunny skies this morning will give way to mostly cloudy skies during the afternoon. High around 35F. Winds SW at 5 to 10 mph. ', 'url': 'https://www.wunderground.com/hourly/us/ny/new-york-city', 'title': 'New York City, NY Hourly Weather Forecast | Weather Underground', 'encrypted_index': 'EpMBCioIChgCIiQ4ODk4YTFkYy0yMTNkLTRhNmYtOTljYi03ZTBlNTUzZDc0NWISDAQ6mxc++WTL2NM/KRoMsFO7LYwBI2HBVeL6IjBLxfDvTIgWwVbX1mS8ePA7iobCZK0H40/RXbxvwU4/3oObBsaeyRO9YYc+kzXyIJsqFzbtUP9/ryPJT6G80GURyCRMTegZ83NqGAQ=', 'supported_text': 'Sunny skies this morning will give way to mostly cloudy skies during the afternoon, with a high around 35°F and winds from the southwest at 5 to 10 mph'}]], 'thinking_blocks': None}))], usage=Usage(completion_tokens=252, prompt_tokens=9945, total_tokens=10197, 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, tool_search_requests=None), cache_creation_input_tokens=0, cache_read_input_tokens=0))"
]
},
"execution_count": null,
Expand All @@ -765,7 +760,7 @@
{
"data": {
"text/plain": [
"Usage(id=5, timestamp=UNSET, model='claude-sonnet-4-5-20250929', 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=1, response_cost=0.040805999999999995)"
"Usage(id=5, timestamp=UNSET, model='claude-sonnet-4-5-20250929', user_id='user-123', prompt_tokens=9945, completion_tokens=252, total_tokens=10197, cached_tokens=0, cache_creation_tokens=0, cache_read_tokens=0, web_search_requests=1, response_cost=0.033615)"
]
},
"execution_count": null,
Expand Down Expand Up @@ -846,7 +841,7 @@
{
"data": {
"text/plain": [
"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)"
"Usage(id=6, timestamp=UNSET, model='claude-sonnet-4-5', user_id='user-123', prompt_tokens=9945, completion_tokens=252, total_tokens=10197, cached_tokens=0, cache_creation_tokens=0, cache_read_tokens=0, web_search_requests=1, response_cost=0.033615)"
]
},
"execution_count": null,
Expand Down Expand Up @@ -965,7 +960,13 @@
"source": []
}
],
"metadata": {},
"metadata": {
"kernelspec": {
"display_name": "python",
"language": "python",
"name": "python"
}
},
"nbformat": 4,
"nbformat_minor": 5
}
Loading