Skip to content

Commit b8c5d4a

Browse files
committed
run
1 parent 29d3fd4 commit b8c5d4a

File tree

3 files changed

+167
-209
lines changed

3 files changed

+167
-209
lines changed

cachy.jsonl

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,3 +84,13 @@
8484
{"key": "a24177c4", "response": "event: message_start\ndata: {\"type\":\"message_start\",\"message\":{\"model\":\"claude-sonnet-4-20250514\",\"id\":\"msg_01Vm8uGV9jri2YVWj7pWPTZX\",\"type\":\"message\",\"role\":\"assistant\",\"content\":[],\"stop_reason\":null,\"stop_sequence\":null,\"usage\":{\"input_tokens\":1134,\"cache_creation_input_tokens\":0,\"cache_read_input_tokens\":0,\"cache_creation\":{\"ephemeral_5m_input_tokens\":0,\"ephemeral_1h_input_tokens\":0},\"output_tokens\":2,\"service_tier\":\"standard\"}} }\n\nevent: content_block_start\ndata: {\"type\":\"content_block_start\",\"index\":0,\"content_block\":{\"type\":\"text\",\"text\":\"\"} }\n\nevent: content_block_delta\ndata: {\"type\":\"content_block_delta\",\"index\":0,\"delta\":{\"type\":\"text_delta\",\"text\":\"\\n\\nI\"} }\n\nevent: content_block_delta\ndata: {\"type\":\"content_block_delta\",\"index\":0,\"delta\":{\"type\":\"text_delta\",\"text\":\" don\"} }\n\nevent: ping\ndata: {\"type\": \"ping\"}\n\nevent: content_block_delta\ndata: {\"type\":\"content_block_delta\",\"index\":0,\"delta\":{\"type\":\"text_delta\",\"text\":\"'t have\"} }\n\nevent: content_block_delta\ndata: {\"type\":\"content_block_delta\",\"index\":0,\"delta\":{\"type\":\"text_delta\",\"text\":\" access\"} }\n\nevent: content_block_delta\ndata: {\"type\":\"content_block_delta\",\"index\":0,\"delta\":{\"type\":\"text_delta\",\"text\":\" to web\"} }\n\nevent: content_block_delta\ndata: {\"type\":\"content_block_delta\",\"index\":0,\"delta\":{\"type\":\"text_delta\",\"text\":\" search tools\"} }\n\nevent: content_block_delta\ndata: {\"type\":\"content_block_delta\",\"index\":0,\"delta\":{\"type\":\"text_delta\",\"text\":\".\"} }\n\nevent: content_block_delta\ndata: {\"type\":\"content_block_delta\",\"index\":0,\"delta\":{\"type\":\"text_delta\",\"text\":\" I\"} }\n\nevent: content_block_delta\ndata: {\"type\":\"content_block_delta\",\"index\":0,\"delta\":{\"type\":\"text_delta\",\"text\":\" can only ad\"} }\n\nevent: content_block_delta\ndata: {\"type\":\"content_block_delta\",\"index\":0,\"delta\":{\"type\":\"text_delta\",\"text\":\"d numbers.\"} }\n\nevent: content_block_delta\ndata: {\"type\":\"content_block_delta\",\"index\":0,\"delta\":{\"type\":\"text_delta\",\"text\":\" \"} }\n\nevent: content_block_delta\ndata: {\"type\":\"content_block_delta\",\"index\":0,\"delta\":{\"type\":\"text_delta\",\"text\":\"\\n\\nBase\"} }\n\nevent: content_block_delta\ndata: {\"type\":\"content_block_delta\",\"index\":0,\"delta\":{\"type\":\"text_delta\",\"text\":\"d on general\"} }\n\nevent: content_block_delta\ndata: {\"type\":\"content_block_delta\",\"index\":0,\"delta\":{\"type\":\"text_delta\",\"text\":\" knowledge:\"} }\n\nevent: content_block_delta\ndata: {\"type\":\"content_block_delta\",\"index\":0,\"delta\":{\"type\":\"text_delta\",\"text\":\"\\n- Male African elephants:\"} }\n\nevent: content_block_delta\ndata: {\"type\":\"content_block_delta\",\"index\":0,\"delta\":{\"type\":\"text_delta\",\"text\":\" ~5\"} }\n\nevent: content_block_delta\ndata: {\"type\":\"content_block_delta\",\"index\":0,\"delta\":{\"type\":\"text_delta\",\"text\":\",000 kg\\n- Male Asian\"} }\n\nevent: content_block_delta\ndata: {\"type\":\"content_block_delta\",\"index\":0,\"delta\":{\"type\":\"text_delta\",\"text\":\" elephants: ~3,600 \"} }\n\nevent: content_block_delta\ndata: {\"type\":\"content_block_delta\",\"index\":0,\"delta\":{\"type\":\"text_delta\",\"text\":\"kg\"} }\n\nevent: content_block_stop\ndata: {\"type\":\"content_block_stop\",\"index\":0 }\n\nevent: message_delta\ndata: {\"type\":\"message_delta\",\"delta\":{\"stop_reason\":\"end_turn\",\"stop_sequence\":null},\"usage\":{\"input_tokens\":1134,\"cache_creation_input_tokens\":0,\"cache_read_input_tokens\":0,\"output_tokens\":59} }\n\nevent: message_stop\ndata: {\"type\":\"message_stop\" }\n\n"}
8585
{"key": "3b23ce0e", "response": "{\"model\":\"claude-sonnet-4-5-20250929\",\"id\":\"msg_01XDeND6zQf8TkcYoE43TV5o\",\"type\":\"message\",\"role\":\"assistant\",\"content\":[{\"type\":\"text\",\"text\":\"1\"}],\"stop_reason\":\"end_turn\",\"stop_sequence\":null,\"usage\":{\"input_tokens\":3,\"cache_creation_input_tokens\":2070,\"cache_read_input_tokens\":0,\"cache_creation\":{\"ephemeral_5m_input_tokens\":2070,\"ephemeral_1h_input_tokens\":0},\"output_tokens\":5,\"service_tier\":\"standard\"}}"}
8686
{"key": "cb54980c", "response": "{\"model\":\"claude-sonnet-4-5-20250929\",\"id\":\"msg_01TDzKH7ALuE4ghxZBmRkhst\",\"type\":\"message\",\"role\":\"assistant\",\"content\":[{\"type\":\"text\",\"text\":\"2\"}],\"stop_reason\":\"end_turn\",\"stop_sequence\":null,\"usage\":{\"input_tokens\":3,\"cache_creation_input_tokens\":2074,\"cache_read_input_tokens\":2070,\"cache_creation\":{\"ephemeral_5m_input_tokens\":2074,\"ephemeral_1h_input_tokens\":0},\"output_tokens\":5,\"service_tier\":\"standard\"}}"}
87+
{"key": "9301496f", "response": "{\"model\":\"claude-sonnet-4-5-20250929\",\"id\":\"msg_01SYVgaXZB4MahZLGQeios9x\",\"type\":\"message\",\"role\":\"assistant\",\"content\":[{\"type\":\"tool_use\",\"id\":\"toolu_01XahXDByQa4CAG1p89xU6uQ\",\"name\":\"President\",\"input\":{\"first\":\"Thomas\",\"last\":\"Jefferson\",\"spouse\":\"Martha Wayles Skelton Jefferson\",\"years_in_office\":\"1801-1809\",\"birthplace\":\"Shadwell\",\"birth_year\":1743}}],\"stop_reason\":\"tool_use\",\"stop_sequence\":null,\"usage\":{\"input_tokens\":805,\"cache_creation_input_tokens\":0,\"cache_read_input_tokens\":0,\"cache_creation\":{\"ephemeral_5m_input_tokens\":0,\"ephemeral_1h_input_tokens\":0},\"output_tokens\":139,\"service_tier\":\"standard\"}}"}
88+
{"key": "3f00b5c6", "response": "{\n \"error\": {\n \"code\": 400,\n \"message\": \"API key expired. Please renew the API key.\",\n \"status\": \"INVALID_ARGUMENT\",\n \"details\": [\n {\n \"@type\": \"type.googleapis.com/google.rpc.ErrorInfo\",\n \"reason\": \"API_KEY_INVALID\",\n \"domain\": \"googleapis.com\",\n \"metadata\": {\n \"service\": \"generativelanguage.googleapis.com\"\n }\n },\n {\n \"@type\": \"type.googleapis.com/google.rpc.LocalizedMessage\",\n \"locale\": \"en-US\",\n \"message\": \"API key expired. Please renew the API key.\"\n }\n ]\n }\n}\n"}
89+
{"key": "4c1f939a", "response": "{\n \"candidates\": [\n {\n \"content\": {\n \"parts\": [\n {\n \"functionCall\": {\n \"name\": \"simple_add\",\n \"args\": {\n \"a\": 5,\n \"b\": 3\n }\n },\n \"thoughtSignature\": \"CvwBAXLI2nyF+wspV8OO5vtLUmKDHVBs2dVG5VtNjWapqlYV+NIF+EoobmyMtUK+9s7pm4+U4JNUGF0wlMwM8AxIBtGoMZ638Lnf0kmWs08ugAaijJWl2dXgzQbwbAYUh+g61Sivkj0lziCN/Ifjd4zTIBCfjkeqwK7PhlIFztvsErGkYx0Tpb1CAWvKJpm2d7XF8Tx7nLytB6EpeZmLsDECC4Eshilz9f64T+tVv2IJ7dtq0mo1Wy0lcQDOHbsj0s7PRZW+XP2xMXd9pjOKo4OYpRQBz5lBotuHI/vHATA0r1nz+BvCH5dSv1iVdtGTtqB3I7e/ylfA5BZ/NXWa\"\n }\n ],\n \"role\": \"model\"\n },\n \"finishReason\": \"STOP\",\n \"index\": 0,\n \"finishMessage\": \"Model generated function call(s).\"\n }\n ],\n \"usageMetadata\": {\n \"promptTokenCount\": 86,\n \"candidatesTokenCount\": 20,\n \"totalTokenCount\": 169,\n \"promptTokensDetails\": [\n {\n \"modality\": \"TEXT\",\n \"tokenCount\": 86\n }\n ],\n \"thoughtsTokenCount\": 63\n },\n \"modelVersion\": \"gemini-2.5-flash\",\n \"responseId\": \"9S42afTTFoeM4-EPhOHooAo\"\n}\n"}
90+
{"key": "56cab005", "response": "{\n \"candidates\": [\n {\n \"content\": {\n \"parts\": [\n {\n \"text\": \"\\nThe `simple_add` tool was used to calculate 5 + 3.\\n\\nThe result is 8.\"\n },\n {\n \"text\": \"The `simple_add` tool was used to calculate 5 + 3.\\n\\nThe result is 8.\"\n }\n ],\n \"role\": \"model\"\n },\n \"finishReason\": \"STOP\",\n \"index\": 0\n }\n ],\n \"usageMetadata\": {\n \"promptTokenCount\": 160,\n \"candidatesTokenCount\": 48,\n \"totalTokenCount\": 208,\n \"promptTokensDetails\": [\n {\n \"modality\": \"TEXT\",\n \"tokenCount\": 160\n }\n ]\n },\n \"modelVersion\": \"gemini-2.5-flash\",\n \"responseId\": \"9i42acTWHpyVg8UPhNzkwQs\"\n}\n"}
91+
{"key": "99f7ba1b", "response": "{\"model\":\"claude-sonnet-4-5-20250929\",\"id\":\"msg_01QwjyNkKSTMdviUXFnPNKGJ\",\"type\":\"message\",\"role\":\"assistant\",\"content\":[{\"type\":\"text\",\"text\":\"I'll use the `simple_add` tool to calculate 5 + 3.\"},{\"type\":\"tool_use\",\"id\":\"toolu_01UwxSnkwi3w87jAwXcyeKZD\",\"name\":\"simple_add\",\"input\":{\"a\":5,\"b\":3}}],\"stop_reason\":\"tool_use\",\"stop_sequence\":null,\"usage\":{\"input_tokens\":622,\"cache_creation_input_tokens\":0,\"cache_read_input_tokens\":0,\"cache_creation\":{\"ephemeral_5m_input_tokens\":0,\"ephemeral_1h_input_tokens\":0},\"output_tokens\":90,\"service_tier\":\"standard\"}}"}
92+
{"key": "2d52b55d", "response": "{\"model\":\"claude-sonnet-4-5-20250929\",\"id\":\"msg_01T8sDzTHZ726ronvqwpCR37\",\"type\":\"message\",\"role\":\"assistant\",\"content\":[{\"type\":\"text\",\"text\":\"\\n\\n**Answer: 5 + 3 = 8**\\n\\n**Explanation:**\\nI used the `simple_add` function with two parameters:\\n- `a = 5` (the first operand)\\n- `b = 3` (the second operand)\\n\\nThe function performed the addition operation and returned the result of **8**, which is the correct sum of 5 and 3.\"}],\"stop_reason\":\"end_turn\",\"stop_sequence\":null,\"usage\":{\"input_tokens\":765,\"cache_creation_input_tokens\":0,\"cache_read_input_tokens\":0,\"cache_creation\":{\"ephemeral_5m_input_tokens\":0,\"ephemeral_1h_input_tokens\":0},\"output_tokens\":93,\"service_tier\":\"standard\"}}"}
93+
{"key": "e989f236", "response": "{\n \"id\": \"chatcmpl-CkKgoeHVoPrJEBeQdoCsH9mXLXKwN\",\n \"object\": \"chat.completion\",\n \"created\": 1765158654,\n \"model\": \"gpt-4.1-2025-04-14\",\n \"choices\": [\n {\n \"index\": 0,\n \"message\": {\n \"role\": \"assistant\",\n \"content\": null,\n \"tool_calls\": [\n {\n \"id\": \"call_WIZwFdZAD61jCFnJaCnvBYpy\",\n \"type\": \"function\",\n \"function\": {\n \"name\": \"simple_add\",\n \"arguments\": \"{\\\"a\\\":5,\\\"b\\\":3}\"\n }\n }\n ],\n \"refusal\": null,\n \"annotations\": []\n },\n \"logprobs\": null,\n \"finish_reason\": \"tool_calls\"\n }\n ],\n \"usage\": {\n \"prompt_tokens\": 85,\n \"completion_tokens\": 18,\n \"total_tokens\": 103,\n \"prompt_tokens_details\": {\n \"cached_tokens\": 0,\n \"audio_tokens\": 0\n },\n \"completion_tokens_details\": {\n \"reasoning_tokens\": 0,\n \"audio_tokens\": 0,\n \"accepted_prediction_tokens\": 0,\n \"rejected_prediction_tokens\": 0\n }\n },\n \"service_tier\": \"default\",\n \"system_fingerprint\": \"fp_09249d7c7b\"\n}\n"}
94+
{"key": "6ca5db66", "response": "{\n \"id\": \"chatcmpl-CkKgq3Ov2DdanOxEYNwJrCzej7dQ8\",\n \"object\": \"chat.completion\",\n \"created\": 1765158656,\n \"model\": \"gpt-4.1-2025-04-14\",\n \"choices\": [\n {\n \"index\": 0,\n \"message\": {\n \"role\": \"assistant\",\n \"content\": \"The result of 5 + 3 is 8.\\n\\nExplanation: The simple_add tool takes two numbers (in this case, 5 and 3) and adds them together. The sum of 5 and 3 is 8.\",\n \"refusal\": null,\n \"annotations\": []\n },\n \"logprobs\": null,\n \"finish_reason\": \"stop\"\n }\n ],\n \"usage\": {\n \"prompt_tokens\": 156,\n \"completion_tokens\": 49,\n \"total_tokens\": 205,\n \"prompt_tokens_details\": {\n \"cached_tokens\": 0,\n \"audio_tokens\": 0\n },\n \"completion_tokens_details\": {\n \"reasoning_tokens\": 0,\n \"audio_tokens\": 0,\n \"accepted_prediction_tokens\": 0,\n \"rejected_prediction_tokens\": 0\n }\n },\n \"service_tier\": \"default\",\n \"system_fingerprint\": \"fp_09249d7c7b\"\n}\n"}
95+
{"key": "ce36a9f7", "response": "{\n \"id\": \"chatcmpl-CkKgxlKn9WDEtVAzIQCj5x5IXLRFb\",\n \"object\": \"chat.completion\",\n \"created\": 1765158663,\n \"model\": \"gpt-4.1-2025-04-14\",\n \"choices\": [\n {\n \"index\": 0,\n \"message\": {\n \"role\": \"assistant\",\n \"content\": null,\n \"tool_calls\": [\n {\n \"id\": \"call_osF7ih5fUnuMrWC0PAae8ik4\",\n \"type\": \"function\",\n \"function\": {\n \"name\": \"multiply\",\n \"arguments\": \"{\\\"a\\\":8,\\\"b\\\":9}\"\n }\n }\n ],\n \"refusal\": null,\n \"annotations\": []\n },\n \"logprobs\": null,\n \"finish_reason\": \"tool_calls\"\n }\n ],\n \"usage\": {\n \"prompt_tokens\": 178,\n \"completion_tokens\": 17,\n \"total_tokens\": 195,\n \"prompt_tokens_details\": {\n \"cached_tokens\": 0,\n \"audio_tokens\": 0\n },\n \"completion_tokens_details\": {\n \"reasoning_tokens\": 0,\n \"audio_tokens\": 0,\n \"accepted_prediction_tokens\": 0,\n \"rejected_prediction_tokens\": 0\n }\n },\n \"service_tier\": \"default\",\n \"system_fingerprint\": \"fp_09249d7c7b\"\n}\n"}
96+
{"key": "e0458695", "response": "{\n \"id\": \"chatcmpl-CkKgyUKZG6IOx5T0ds9S47BWLhMkZ\",\n \"object\": \"chat.completion\",\n \"created\": 1765158664,\n \"model\": \"gpt-4.1-2025-04-14\",\n \"choices\": [\n {\n \"index\": 0,\n \"message\": {\n \"role\": \"assistant\",\n \"content\": \"(5 + 3) = 8 and (7 + 2) = 9. Multiplying them gives 8 \u00d7 9 = 72. \\n\\nSo, (5 + 3) * (7 + 2) = 72.\",\n \"refusal\": null,\n \"annotations\": []\n },\n \"logprobs\": null,\n \"finish_reason\": \"stop\"\n }\n ],\n \"usage\": {\n \"prompt_tokens\": 203,\n \"completion_tokens\": 54,\n \"total_tokens\": 257,\n \"prompt_tokens_details\": {\n \"cached_tokens\": 0,\n \"audio_tokens\": 0\n },\n \"completion_tokens_details\": {\n \"reasoning_tokens\": 0,\n \"audio_tokens\": 0,\n \"accepted_prediction_tokens\": 0,\n \"rejected_prediction_tokens\": 0\n }\n },\n \"service_tier\": \"default\",\n \"system_fingerprint\": \"fp_09249d7c7b\"\n}\n"}

lisette/core.py

Lines changed: 5 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,14 @@
1010

1111
# %% ../nbs/00_core.ipynb
1212
import asyncio, base64, json, litellm, mimetypes, random, string
13-
from typing import Optional
13+
from typing import Optional,Callable
1414
from html import escape
1515
from litellm import (acompletion, completion, stream_chunk_builder, Message,
1616
ModelResponse, ModelResponseStream, get_model_info, register_model, Usage)
1717
from litellm.utils import function_to_dict, StreamingChoices, Delta, ChatCompletionMessageToolCall, Function, Choices
1818
from toolslm.funccall import mk_ns, call_func, call_func_async, get_schema
1919
from fastcore.utils import *
20+
from fastcore.meta import delegates
2021
from fastcore import imghdr
2122
from dataclasses import dataclass
2223

@@ -213,26 +214,17 @@ def _lite_call_func(tc,ns,raise_on_err=True):
213214
else: res = str(res)
214215
return {"tool_call_id": tc.id, "role": "tool", "name": tc.function.name, "content": res}
215216

216-
# %% ../nbs/00_core.ipynb
217-
import json
218-
219-
# %% ../nbs/00_core.ipynb
220-
from fastcore.meta import delegates
221-
222217
# %% ../nbs/00_core.ipynb
223218
@delegates(completion)
224219
def structured(
225-
m, # The LiteLLM model string
226-
msgs:list, # A list of messages
227-
tool, # The tool to be used for creating the structured output. Can also be a class, dataclass or Pydantic model
220+
m:str, # LiteLLM model string
221+
msgs:list, # List of messages
222+
tool:Callable, # Tool to be used for creating the structured output (class, dataclass or Pydantic, function, etc)
228223
**kwargs):
229224
"Return the value of the tool call (generally used for structured outputs)"
230225
t = lite_mk_func(tool)
231-
232226
r = completion(m, msgs, tools=[t], tool_choice=t, **kwargs)
233-
234227
args = json.loads(r.choices[0].message.tool_calls[0].function.arguments)
235-
236228
return tool(**args)
237229

238230
# %% ../nbs/00_core.ipynb

0 commit comments

Comments
 (0)