diff --git a/00_core.ipynb b/00_core.ipynb index 3c5acae..38213ba 100644 --- a/00_core.ipynb +++ b/00_core.ipynb @@ -38,7 +38,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 1, "id": "f1ad998e-4bb1-4bed-abf4-6e8606cb2453", "metadata": {}, "outputs": [], @@ -57,7 +57,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 2, "id": "033c76fd", "metadata": {}, "outputs": [], @@ -79,17 +79,18 @@ "\n", "from fastcore.meta import delegates\n", "from fastcore.utils import *\n", - "from msglm import mk_msg_anthropic as mk_msg, mk_msgs_anthropic as mk_msgs" + "from msglm import mk_msg_anthropic as mk_msg, mk_msgs_anthropic as mk_msgs, mk_ant_doc as mk_doc" ] }, { "cell_type": "code", - "execution_count": null, + "execution_count": 3, "id": "13866a72", "metadata": {}, "outputs": [], "source": [ "#| hide\n", + "from httpx import get as xget\n", "from nbdev import show_doc\n", "\n", "# Used to show available models from the anthropic SDK\n", @@ -100,7 +101,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 4, "id": "c1cefa1e", "metadata": {}, "outputs": [], @@ -111,7 +112,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 5, "id": "f5fa6b92", "metadata": {}, "outputs": [], @@ -136,7 +137,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 6, "id": "0fff8869", "metadata": {}, "outputs": [], @@ -166,7 +167,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 7, "id": "6e9da53c", "metadata": {}, "outputs": [ @@ -174,7 +175,7 @@ "name": "stdout", "output_type": "stream", "text": [ - "Available models as of 2025-02-24:\n", + "Available models as of 2025-02-25:\n", "\n" ] }, @@ -194,7 +195,7 @@ " 'claude-2.0']" ] }, - "execution_count": null, + "execution_count": 7, "metadata": {}, "output_type": "execute_result" } @@ -209,7 +210,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 8, "id": "4f03dcad", "metadata": {}, "outputs": [], @@ -220,7 +221,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 10, "id": "669696aa", "metadata": {}, "outputs": [], @@ -231,7 +232,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 11, "id": "2411f28d", "metadata": {}, "outputs": [], @@ -244,7 +245,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 12, "id": "980bfdfb", "metadata": {}, "outputs": [ @@ -265,7 +266,7 @@ " 'claude-3-sonnet@20240229'}" ] }, - "execution_count": null, + "execution_count": 12, "metadata": {}, "output_type": "execute_result" } @@ -276,7 +277,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 13, "id": "12a68d54", "metadata": {}, "outputs": [], @@ -298,7 +299,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 14, "id": "55036062", "metadata": {}, "outputs": [], @@ -316,7 +317,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 9, "id": "dacf2bd2", "metadata": {}, "outputs": [ @@ -326,7 +327,7 @@ "'claude-3-5-sonnet-20241022'" ] }, - "execution_count": null, + "execution_count": 9, "metadata": {}, "output_type": "execute_result" } @@ -353,7 +354,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 16, "id": "70b53a51", "metadata": {}, "outputs": [], @@ -383,33 +384,33 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 17, "id": "6ec40731", "metadata": {}, "outputs": [ { "data": { "text/markdown": [ - "Hi Jeremy! Nice to meet you. I'm Claude. How can I help you today?\n", + "Hi Jeremy! Nice to meet you. I'm Claude, an AI assistant. How can I help you today?\n", "\n", "
\n", "\n", - "- id: `msg_01XUgk5vUP7FNF9w1GJqt6kN`\n", - "- content: `[{'text': \"Hi Jeremy! Nice to meet you. I'm Claude. How can I help you today?\", 'type': 'text'}]`\n", + "- id: `msg_01EPZvaQKs14NzX3nA1deSqx`\n", + "- content: `[{'citations': None, 'text': \"Hi Jeremy! Nice to meet you. I'm Claude, an AI assistant. How can I help you today?\", 'type': 'text'}]`\n", "- model: `claude-3-5-sonnet-20241022`\n", "- role: `assistant`\n", "- stop_reason: `end_turn`\n", "- stop_sequence: `None`\n", "- type: `message`\n", - "- usage: `{'cache_creation_input_tokens': 0, 'cache_read_input_tokens': 0, 'input_tokens': 10, 'output_tokens': 22}`\n", + "- usage: `{'cache_creation_input_tokens': 0, 'cache_read_input_tokens': 0, 'input_tokens': 10, 'output_tokens': 26}`\n", "\n", "
" ], "text/plain": [ - "Message(id='msg_01XUgk5vUP7FNF9w1GJqt6kN', content=[TextBlock(text=\"Hi Jeremy! Nice to meet you. I'm Claude. How can I help you today?\", type='text')], model='claude-3-5-sonnet-20241022', role='assistant', stop_reason='end_turn', stop_sequence=None, type='message', usage=In: 10; Out: 22; Cache create: 0; Cache read: 0; Total: 32)" + "Message(id='msg_01EPZvaQKs14NzX3nA1deSqx', content=[TextBlock(citations=None, text=\"Hi Jeremy! Nice to meet you. I'm Claude, an AI assistant. How can I help you today?\", type='text')], model='claude-3-5-sonnet-20241022', role='assistant', stop_reason='end_turn', stop_sequence=None, type='message', usage=In: 10; Out: 26; Cache create: 0; Cache read: 0; Total: 36)" ] }, - "execution_count": null, + "execution_count": 17, "metadata": {}, "output_type": "execute_result" } @@ -458,7 +459,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 18, "id": "eba620ce", "metadata": {}, "outputs": [], @@ -481,17 +482,17 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 19, "id": "10af0e65", "metadata": {}, "outputs": [ { "data": { "text/plain": [ - "TextBlock(text=\"Hi Jeremy! Nice to meet you. I'm Claude. How can I help you today?\", type='text')" + "TextBlock(citations=None, text=\"Hi Jeremy! Nice to meet you. I'm Claude, an AI assistant. How can I help you today?\", type='text')" ] }, - "execution_count": null, + "execution_count": 19, "metadata": {}, "output_type": "execute_result" } @@ -502,7 +503,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 20, "id": "ae99799d", "metadata": {}, "outputs": [], @@ -524,17 +525,17 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 21, "id": "6d5f2107", "metadata": {}, "outputs": [ { "data": { "text/plain": [ - "\"Hi Jeremy! Nice to meet you. I'm Claude. How can I help you today?\"" + "\"Hi Jeremy! Nice to meet you. I'm Claude, an AI assistant. How can I help you today?\"" ] }, - "execution_count": null, + "execution_count": 21, "metadata": {}, "output_type": "execute_result" } @@ -545,7 +546,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 22, "id": "17924d0c", "metadata": {}, "outputs": [], @@ -837,19 +838,19 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 30, "id": "0ffa2c14", "metadata": {}, "outputs": [ { "data": { "text/markdown": [ - "Hi Jeremy! Nice to meet you. I'm Claude. How can I help you today?\n", + "Hi Jeremy, nice to meet you! I'm Claude. How can I help you today?\n", "\n", "
\n", "\n", - "- id: `msg_01VAqrPtTzD1uraEnzQMt194`\n", - "- content: `[{'text': \"Hi Jeremy! Nice to meet you. I'm Claude. How can I help you today?\", 'type': 'text'}]`\n", + "- id: `msg_01GkzrxKr3x22fWHVj7Sdjsa`\n", + "- content: `[{'citations': None, 'text': \"Hi Jeremy, nice to meet you! I'm Claude. How can I help you today?\", 'type': 'text'}]`\n", "- model: `claude-3-5-sonnet-20241022`\n", "- role: `assistant`\n", "- stop_reason: `end_turn`\n", @@ -860,10 +861,10 @@ "
" ], "text/plain": [ - "Message(id='msg_01VAqrPtTzD1uraEnzQMt194', content=[TextBlock(text=\"Hi Jeremy! Nice to meet you. I'm Claude. How can I help you today?\", type='text')], model='claude-3-5-sonnet-20241022', role='assistant', stop_reason='end_turn', stop_sequence=None, type='message', usage=In: 10; Out: 22; Cache create: 0; Cache read: 0; Total: 32)" + "Message(id='msg_01GkzrxKr3x22fWHVj7Sdjsa', content=[TextBlock(citations=None, text=\"Hi Jeremy, nice to meet you! I'm Claude. How can I help you today?\", type='text')], model='claude-3-5-sonnet-20241022', role='assistant', stop_reason='end_turn', stop_sequence=None, type='message', usage=In: 10; Out: 22; Cache create: 0; Cache read: 0; Total: 32)" ] }, - "execution_count": null, + "execution_count": 30, "metadata": {}, "output_type": "execute_result" } @@ -921,7 +922,7 @@ "text/plain": [ "[{'role': 'user', 'content': \"I'm Jeremy\"},\n", " {'role': 'assistant',\n", - " 'content': [TextBlock(text=\"Hi Jeremy! Nice to meet you. I'm Claude. How can I help you today?\", type='text')]},\n", + " 'content': [TextBlock(citations=None, text='Hi Jeremy! Nice to meet you. How can I help you today?', type='text')]},\n", " {'role': 'user', 'content': 'I forgot my name. Can you remind me please?'}]" ] }, @@ -948,19 +949,19 @@ "\n", "
\n", "\n", - "- id: `msg_01LikwNGzibWT2cWAytNDyF6`\n", - "- content: `[{'text': 'You just told me your name is Jeremy.', 'type': 'text'}]`\n", + "- id: `msg_01G8UnB8CoUFHAj4WwXSEerB`\n", + "- content: `[{'citations': None, 'text': 'You just told me your name is Jeremy.', 'type': 'text'}]`\n", "- model: `claude-3-5-sonnet-20241022`\n", "- role: `assistant`\n", "- stop_reason: `end_turn`\n", "- stop_sequence: `None`\n", "- type: `message`\n", - "- usage: `{'cache_creation_input_tokens': 0, 'cache_read_input_tokens': 0, 'input_tokens': 46, 'output_tokens': 12}`\n", + "- usage: `{'cache_creation_input_tokens': 0, 'cache_read_input_tokens': 0, 'input_tokens': 42, 'output_tokens': 12}`\n", "\n", "
" ], "text/plain": [ - "Message(id='msg_01LikwNGzibWT2cWAytNDyF6', content=[TextBlock(text='You just told me your name is Jeremy.', type='text')], model='claude-3-5-sonnet-20241022', role='assistant', stop_reason='end_turn', stop_sequence=None, type='message', usage=In: 46; Out: 12; Cache create: 0; Cache read: 0; Total: 58)" + "Message(id='msg_01G8UnB8CoUFHAj4WwXSEerB', content=[TextBlock(citations=None, text='You just told me your name is Jeremy.', type='text')], model='claude-3-5-sonnet-20241022', role='assistant', stop_reason='end_turn', stop_sequence=None, type='message', usage=In: 42; Out: 12; Cache create: 0; Cache read: 0; Total: 54)" ] }, "execution_count": null, @@ -1068,7 +1069,7 @@ { "data": { "text/plain": [ - "In: 10; Out: 22; Cache create: 0; Cache read: 0; Total: 32" + "In: 10; Out: 18; Cache create: 0; Cache read: 0; Total: 28" ] }, "execution_count": null, @@ -1220,8 +1221,8 @@ "\n", "
\n", "\n", - "- id: `msg_01Qfmtq6ChdKqiPcTeUku8Vv`\n", - "- content: `[{'text': 'Hello! How can I help you today?', 'type': 'text'}]`\n", + "- id: `msg_016JUne3YG5eZWM1zJMnvDux`\n", + "- content: `[{'citations': None, 'text': 'Hello! How can I help you today?', 'type': 'text'}]`\n", "- model: `claude-3-5-sonnet-20241022`\n", "- role: `assistant`\n", "- stop_reason: `end_turn`\n", @@ -1232,7 +1233,7 @@ "
" ], "text/plain": [ - "Message(id='msg_01Qfmtq6ChdKqiPcTeUku8Vv', content=[TextBlock(text='Hello! How can I help you today?', type='text')], model='claude-3-5-sonnet-20241022', role='assistant', stop_reason='end_turn', stop_sequence=None, type='message', usage=In: 8; Out: 12; Cache create: 0; Cache read: 0; Total: 20)" + "Message(id='msg_016JUne3YG5eZWM1zJMnvDux', content=[TextBlock(citations=None, text='Hello! How can I help you today?', type='text')], model='claude-3-5-sonnet-20241022', role='assistant', stop_reason='end_turn', stop_sequence=None, type='message', usage=In: 8; Out: 12; Cache create: 0; Cache read: 0; Total: 20)" ] }, "execution_count": null, @@ -1293,23 +1294,23 @@ { "data": { "text/markdown": [ - "According to Douglas Adams, it's 42. More seriously, there's no universal answer - it's deeply personal. Common perspectives include: finding happiness, making meaningful connections, pursuing purpose through work/creativity, helping others, or simply experiencing and appreciating existence.\n", + "According to Douglas Adams, it's 42. More seriously, there's no universal answer - it's deeply personal. Common perspectives include: finding happiness, making meaningful connections, pursuing purpose through work/creativity, helping others, or simply experiencing existence fully. You get to decide what gives your life meaning.\n", "\n", "
\n", "\n", - "- id: `msg_01Tog71KkCb89GPFhQqYtMBs`\n", - "- content: `[{'text': \"According to Douglas Adams, it's 42. More seriously, there's no universal answer - it's deeply personal. Common perspectives include: finding happiness, making meaningful connections, pursuing purpose through work/creativity, helping others, or simply experiencing and appreciating existence.\", 'type': 'text'}]`\n", + "- id: `msg_01UqabBj6uN5LB7xvSrV3NgH`\n", + "- content: `[{'citations': None, 'text': \"According to Douglas Adams, it's 42. More seriously, there's no universal answer - it's deeply personal. Common perspectives include: finding happiness, making meaningful connections, pursuing purpose through work/creativity, helping others, or simply experiencing existence fully. You get to decide what gives your life meaning.\", 'type': 'text'}]`\n", "- model: `claude-3-5-sonnet-20241022`\n", "- role: `assistant`\n", "- stop_reason: `end_turn`\n", "- stop_sequence: `None`\n", "- type: `message`\n", - "- usage: `{'cache_creation_input_tokens': 0, 'cache_read_input_tokens': 0, 'input_tokens': 24, 'output_tokens': 52}`\n", + "- usage: `{'cache_creation_input_tokens': 0, 'cache_read_input_tokens': 0, 'input_tokens': 24, 'output_tokens': 60}`\n", "\n", "
" ], "text/plain": [ - "Message(id='msg_01Tog71KkCb89GPFhQqYtMBs', content=[TextBlock(text=\"According to Douglas Adams, it's 42. More seriously, there's no universal answer - it's deeply personal. Common perspectives include: finding happiness, making meaningful connections, pursuing purpose through work/creativity, helping others, or simply experiencing and appreciating existence.\", type='text')], model='claude-3-5-sonnet-20241022', role='assistant', stop_reason='end_turn', stop_sequence=None, type='message', usage=In: 24; Out: 52; Cache create: 0; Cache read: 0; Total: 76)" + "Message(id='msg_01UqabBj6uN5LB7xvSrV3NgH', content=[TextBlock(citations=None, text=\"According to Douglas Adams, it's 42. More seriously, there's no universal answer - it's deeply personal. Common perspectives include: finding happiness, making meaningful connections, pursuing purpose through work/creativity, helping others, or simply experiencing existence fully. You get to decide what gives your life meaning.\", type='text')], model='claude-3-5-sonnet-20241022', role='assistant', stop_reason='end_turn', stop_sequence=None, type='message', usage=In: 24; Out: 60; Cache create: 0; Cache read: 0; Total: 84)" ] }, "execution_count": null, @@ -1356,7 +1357,7 @@ { "data": { "text/plain": [ - "In: 40; Out: 76; Cache create: 0; Cache read: 0; Total: 116" + "In: 40; Out: 84; Cache create: 0; Cache read: 0; Total: 124" ] }, "execution_count": null, @@ -1395,7 +1396,7 @@ { "data": { "text/plain": [ - "In: 64; Out: 128; Cache create: 0; Cache read: 0; Total: 192" + "In: 64; Out: 136; Cache create: 0; Cache read: 0; Total: 200" ] }, "execution_count": null, @@ -1431,8 +1432,8 @@ "\n", "
\n", "\n", - "- id: `msg_01KB6ubA6wfHxRLnvUgn786J`\n", - "- content: `[{'text': '1\\n2\\n3\\n4\\n', 'type': 'text'}]`\n", + "- id: `msg_01XMsSKp7vvGwKK3KdwntS6o`\n", + "- content: `[{'citations': None, 'text': '1\\n2\\n3\\n4\\n', 'type': 'text'}]`\n", "- model: `claude-3-5-sonnet-20241022`\n", "- role: `assistant`\n", "- stop_reason: `stop_sequence`\n", @@ -1443,7 +1444,7 @@ "
" ], "text/plain": [ - "Message(id='msg_01KB6ubA6wfHxRLnvUgn786J', content=[TextBlock(text='1\\n2\\n3\\n4\\n', type='text')], model='claude-3-5-sonnet-20241022', role='assistant', stop_reason='stop_sequence', stop_sequence='5', type='message', usage=In: 15; Out: 10; Cache create: 0; Cache read: 0; Total: 25)" + "Message(id='msg_01XMsSKp7vvGwKK3KdwntS6o', content=[TextBlock(citations=None, text='1\\n2\\n3\\n4\\n', type='text')], model='claude-3-5-sonnet-20241022', role='assistant', stop_reason='stop_sequence', stop_sequence='5', type='message', usage=In: 15; Out: 10; Cache create: 0; Cache read: 0; Total: 25)" ] }, "execution_count": null, @@ -1511,8 +1512,8 @@ " 'temp': None,\n", " 'stream': None,\n", " 'stop': None,\n", - " 'result': Message(id='msg_01VKoHjmRpftXSyNnmGPMVo6', content=[TextBlock(text='1\\n', type='text')], model='claude-3-5-sonnet-20241022', role='assistant', stop_reason='stop_sequence', stop_sequence='2', type='message', usage=In: 15; Out: 4; Cache create: 0; Cache read: 0; Total: 19),\n", - " 'use': In: 94; Out: 142; Cache create: 0; Cache read: 0; Total: 236,\n", + " 'result': Message(id='msg_01LoW6Q4P2MT6ZRrdAbW25zc', content=[TextBlock(citations=None, text='1\\n', type='text')], model='claude-3-5-sonnet-20241022', role='assistant', stop_reason='stop_sequence', stop_sequence='2', type='message', usage=In: 15; Out: 4; Cache create: 0; Cache read: 0; Total: 19),\n", + " 'use': In: 94; Out: 150; Cache create: 0; Cache read: 0; Total: 244,\n", " 'stop_reason': 'stop_sequence',\n", " 'stop_sequence': '2'}" ] @@ -1653,9 +1654,9 @@ "| Metric | Count | Cost (USD) |\n", "|--------|------:|-----:|\n", "| Input tokens | 94 | 0.000282 |\n", - "| Output tokens | 142 | 0.002130 |\n", + "| Output tokens | 150 | 0.002250 |\n", "| Cache tokens | 0 | 0.000000 |\n", - "| **Total** | **236** | **$0.002412** |" + "| **Total** | **244** | **$0.002532** |" ], "text/plain": [ "<__main__.Client>" @@ -1795,12 +1796,12 @@ { "data": { "text/markdown": [ - "ToolUseBlock(id='toolu_013kKHHY4ZiosgowjMSyedDZ', input={'a': 604542, 'b': 6458932}, name='sums', type='tool_use')\n", + "ToolUseBlock(id='toolu_01SGncLRoRAZiifb77xJZmme', input={'a': 604542, 'b': 6458932}, name='sums', type='tool_use')\n", "\n", "
\n", "\n", - "- id: `msg_01MwcKqATQ9JGkneu9aa83ZS`\n", - "- content: `[{'id': 'toolu_013kKHHY4ZiosgowjMSyedDZ', 'input': {'a': 604542, 'b': 6458932}, 'name': 'sums', 'type': 'tool_use'}]`\n", + "- id: `msg_0187spgiiTooRU1adsy7st3e`\n", + "- content: `[{'id': 'toolu_01SGncLRoRAZiifb77xJZmme', 'input': {'a': 604542, 'b': 6458932}, 'name': 'sums', 'type': 'tool_use'}]`\n", "- model: `claude-3-5-sonnet-20241022`\n", "- role: `assistant`\n", "- stop_reason: `tool_use`\n", @@ -1811,7 +1812,7 @@ "
" ], "text/plain": [ - "Message(id='msg_01MwcKqATQ9JGkneu9aa83ZS', content=[ToolUseBlock(id='toolu_013kKHHY4ZiosgowjMSyedDZ', input={'a': 604542, 'b': 6458932}, name='sums', type='tool_use')], model='claude-3-5-sonnet-20241022', role='assistant', stop_reason='tool_use', stop_sequence=None, type='message', usage=In: 442; Out: 53; Cache create: 0; Cache read: 0; Total: 495)" + "Message(id='msg_0187spgiiTooRU1adsy7st3e', content=[ToolUseBlock(id='toolu_01SGncLRoRAZiifb77xJZmme', input={'a': 604542, 'b': 6458932}, name='sums', type='tool_use')], model='claude-3-5-sonnet-20241022', role='assistant', stop_reason='tool_use', stop_sequence=None, type='message', usage=In: 442; Out: 53; Cache create: 0; Cache read: 0; Total: 495)" ] }, "execution_count": null, @@ -1895,7 +1896,7 @@ "data": { "text/plain": [ "{'type': 'tool_result',\n", - " 'tool_use_id': 'toolu_013kKHHY4ZiosgowjMSyedDZ',\n", + " 'tool_use_id': 'toolu_01SGncLRoRAZiifb77xJZmme',\n", " 'content': '7063474'}" ] }, @@ -1974,10 +1975,10 @@ "data": { "text/plain": [ "[{'role': 'assistant',\n", - " 'content': [ToolUseBlock(id='toolu_013kKHHY4ZiosgowjMSyedDZ', input={'a': 604542, 'b': 6458932}, name='sums', type='tool_use')]},\n", + " 'content': [ToolUseBlock(id='toolu_01SGncLRoRAZiifb77xJZmme', input={'a': 604542, 'b': 6458932}, name='sums', type='tool_use')]},\n", " {'role': 'user',\n", " 'content': [{'type': 'tool_result',\n", - " 'tool_use_id': 'toolu_013kKHHY4ZiosgowjMSyedDZ',\n", + " 'tool_use_id': 'toolu_01SGncLRoRAZiifb77xJZmme',\n", " 'content': '7063474'}]}]" ] }, @@ -2179,12 +2180,12 @@ { "data": { "text/markdown": [ - "ToolUseBlock(id='toolu_012Y8gR5cDgoaizxu8trNLUC', input={'a': 604542, 'b': 6458932}, name='sums', type='tool_use')\n", + "ToolUseBlock(id='toolu_015G8SH2TJv7Zn2S3apWWmRW', input={'a': 604542, 'b': 6458932}, name='sums', type='tool_use')\n", "\n", "
\n", "\n", - "- id: `msg_013RKbZMVt95c6iBJNnqo35W`\n", - "- content: `[{'id': 'toolu_012Y8gR5cDgoaizxu8trNLUC', 'input': {'a': 604542, 'b': 6458932}, 'name': 'sums', 'type': 'tool_use'}]`\n", + "- id: `msg_0196CctuJotK2KrUkkGtdCWe`\n", + "- content: `[{'id': 'toolu_015G8SH2TJv7Zn2S3apWWmRW', 'input': {'a': 604542, 'b': 6458932}, 'name': 'sums', 'type': 'tool_use'}]`\n", "- model: `claude-3-5-sonnet-20241022`\n", "- role: `assistant`\n", "- stop_reason: `tool_use`\n", @@ -2195,7 +2196,7 @@ "
" ], "text/plain": [ - "Message(id='msg_013RKbZMVt95c6iBJNnqo35W', content=[ToolUseBlock(id='toolu_012Y8gR5cDgoaizxu8trNLUC', input={'a': 604542, 'b': 6458932}, name='sums', type='tool_use')], model='claude-3-5-sonnet-20241022', role='assistant', stop_reason='tool_use', stop_sequence=None, type='message', usage=In: 438; Out: 57; Cache create: 0; Cache read: 0; Total: 495)" + "Message(id='msg_0196CctuJotK2KrUkkGtdCWe', content=[ToolUseBlock(id='toolu_015G8SH2TJv7Zn2S3apWWmRW', input={'a': 604542, 'b': 6458932}, name='sums', type='tool_use')], model='claude-3-5-sonnet-20241022', role='assistant', stop_reason='tool_use', stop_sequence=None, type='message', usage=In: 438; Out: 57; Cache create: 0; Cache read: 0; Total: 495)" ] }, "execution_count": null, @@ -2297,14 +2298,14 @@ { "data": { "text/markdown": [ - "ToolUseBlock(id='toolu_01R5bcUxFQqywZ7apeUappUF', input={'a': 604542, 'b': 6458932}, name='sums', type='tool_use')\n", + "ToolUseBlock(id='toolu_01SZAKZhgJ85FGxWgLTMZQiQ', input={'a': 604542, 'b': 6458932}, name='sums', type='tool_use')\n", "\n", "| Metric | Count | Cost (USD) |\n", "|--------|------:|-----:|\n", "| Input tokens | 2,981 | 0.008943 |\n", - "| Output tokens | 408 | 0.006120 |\n", + "| Output tokens | 416 | 0.006240 |\n", "| Cache tokens | 0 | 0.000000 |\n", - "| **Total** | **3,389** | **$0.015063** |" + "| **Total** | **3,397** | **$0.015183** |" ], "text/plain": [ "<__main__.Client>" @@ -2619,7 +2620,7 @@ { "data": { "text/plain": [ - "ToolUseBlock(id='toolu_01JzUT3tc3vmnE1GZA97b937', input={'book': {'title': 'War and Peace', 'pages': 950}, 'percent': 50}, name='find_page', type='tool_use')" + "ToolUseBlock(id='toolu_01C8tx2xfbiF5vrg69dkRdaD', input={'book': {'title': 'War and Peace', 'pages': 950}, 'percent': 50}, name='find_page', type='tool_use')" ] }, "execution_count": null, @@ -2882,8 +2883,8 @@ "\n", "
\n", "\n", - "- id: `msg_01LfygfxpJVTz8tetRWsXyHE`\n", - "- content: `[{'text': 'Your name is Jeremy.', 'type': 'text'}]`\n", + "- id: `msg_01JFK4McaHBTQPWLMDfqGRU4`\n", + "- content: `[{'citations': None, 'text': 'Your name is Jeremy.', 'type': 'text'}]`\n", "- model: `claude-3-5-sonnet-20241022`\n", "- role: `assistant`\n", "- stop_reason: `end_turn`\n", @@ -2894,7 +2895,7 @@ "
" ], "text/plain": [ - "Message(id='msg_01LfygfxpJVTz8tetRWsXyHE', content=[TextBlock(text='Your name is Jeremy.', type='text')], model='claude-3-5-sonnet-20241022', role='assistant', stop_reason='end_turn', stop_sequence=None, type='message', usage=In: 41; Out: 8; Cache create: 0; Cache read: 0; Total: 49)" + "Message(id='msg_01JFK4McaHBTQPWLMDfqGRU4', content=[TextBlock(citations=None, text='Your name is Jeremy.', type='text')], model='claude-3-5-sonnet-20241022', role='assistant', stop_reason='end_turn', stop_sequence=None, type='message', usage=In: 41; Out: 8; Cache create: 0; Cache read: 0; Total: 49)" ] }, "execution_count": null, @@ -2960,8 +2961,8 @@ "\n", "
\n", "\n", - "- id: `msg_01LfygfxpJVTz8tetRWsXyHE`\n", - "- content: `[{'text': 'Your name is Jeremy.', 'type': 'text'}]`\n", + "- id: `msg_01JFK4McaHBTQPWLMDfqGRU4`\n", + "- content: `[{'citations': None, 'text': 'Your name is Jeremy.', 'type': 'text'}]`\n", "- model: `claude-3-5-sonnet-20241022`\n", "- role: `assistant`\n", "- stop_reason: `end_turn`\n", @@ -2972,7 +2973,7 @@ "
" ], "text/plain": [ - "Message(id='msg_01LfygfxpJVTz8tetRWsXyHE', content=[TextBlock(text='Your name is Jeremy.', type='text')], model='claude-3-5-sonnet-20241022', role='assistant', stop_reason='end_turn', stop_sequence=None, type='message', usage=In: 41; Out: 8; Cache create: 0; Cache read: 0; Total: 49)" + "Message(id='msg_01JFK4McaHBTQPWLMDfqGRU4', content=[TextBlock(citations=None, text='Your name is Jeremy.', type='text')], model='claude-3-5-sonnet-20241022', role='assistant', stop_reason='end_turn', stop_sequence=None, type='message', usage=In: 41; Out: 8; Cache create: 0; Cache read: 0; Total: 49)" ] }, "execution_count": null, @@ -2993,23 +2994,23 @@ { "data": { "text/markdown": [ - "According to Douglas Adams,42. But seriously: To find purpose, create meaning, love, grow, and make a positive impact while experiencing life's journey.\n", + "According to Douglas Adams, 42. But more seriously: to find purpose, create meaning, and make positive connections during our time here.\n", "\n", "
\n", "\n", - "- id: `msg_01LmC3pCsJq2RwydmbsDTP2v`\n", - "- content: `[{'text': \"According to Douglas Adams,42. But seriously: To find purpose, create meaning, love, grow, and make a positive impact while experiencing life's journey.\", 'type': 'text'}]`\n", + "- id: `msg_014sCFXU6YgynT7k6RcB2uQn`\n", + "- content: `[{'citations': None, 'text': 'According to Douglas Adams, 42. But more seriously: to find purpose, create meaning, and make positive connections during our time here.', 'type': 'text'}]`\n", "- model: `claude-3-5-sonnet-20241022`\n", "- role: `assistant`\n", "- stop_reason: `end_turn`\n", "- stop_sequence: `None`\n", "- type: `message`\n", - "- usage: `{'cache_creation_input_tokens': 0, 'cache_read_input_tokens': 0, 'input_tokens': 69, 'output_tokens': 30}`\n", + "- usage: `{'cache_creation_input_tokens': 0, 'cache_read_input_tokens': 0, 'input_tokens': 69, 'output_tokens': 26}`\n", "\n", "
" ], "text/plain": [ - "Message(id='msg_01LmC3pCsJq2RwydmbsDTP2v', content=[TextBlock(text=\"According to Douglas Adams,42. But seriously: To find purpose, create meaning, love, grow, and make a positive impact while experiencing life's journey.\", type='text')], model='claude-3-5-sonnet-20241022', role='assistant', stop_reason='end_turn', stop_sequence=None, type='message', usage=In: 69; Out: 30; Cache create: 0; Cache read: 0; Total: 99)" + "Message(id='msg_014sCFXU6YgynT7k6RcB2uQn', content=[TextBlock(citations=None, text='According to Douglas Adams, 42. But more seriously: to find purpose, create meaning, and make positive connections during our time here.', type='text')], model='claude-3-5-sonnet-20241022', role='assistant', stop_reason='end_turn', stop_sequence=None, type='message', usage=In: 69; Out: 26; Cache create: 0; Cache read: 0; Total: 95)" ] }, "execution_count": null, @@ -3065,23 +3066,23 @@ { "data": { "text/markdown": [ - "To build meaningful relationships, pursue passions, learn continuously, help others, appreciate beauty, overcome challenges, leave a positive legacy, and find personal fulfillment through both small daily moments and larger life achievements. Each person ultimately defines their own unique meaning.\n", + "To grow, learn, love, help others, experience joy and beauty, leave the world better than we found it, and discover our own unique way of contributing to the grand tapestry of existence.\n", "\n", "
\n", "\n", - "- id: `msg_01BhhYTBp4v33C7XK911jkBY`\n", - "- content: `[{'text': 'To build meaningful relationships, pursue passions, learn continuously, help others, appreciate beauty, overcome challenges, leave a positive legacy, and find personal fulfillment through both small daily moments and larger life achievements. Each person ultimately defines their own unique meaning.', 'type': 'text'}]`\n", + "- id: `msg_01J4G2MqStkSnGeLGwgwvuid`\n", + "- content: `[{'citations': None, 'text': 'To grow, learn, love, help others, experience joy and beauty, leave the world better than we found it, and discover our own unique way of contributing to the grand tapestry of existence.', 'type': 'text'}]`\n", "- model: `claude-3-5-sonnet-20241022`\n", "- role: `assistant`\n", "- stop_reason: `end_turn`\n", "- stop_sequence: `None`\n", "- type: `message`\n", - "- usage: `{'cache_creation_input_tokens': 0, 'cache_read_input_tokens': 0, 'input_tokens': 105, 'output_tokens': 54}`\n", + "- usage: `{'cache_creation_input_tokens': 0, 'cache_read_input_tokens': 0, 'input_tokens': 101, 'output_tokens': 44}`\n", "\n", "
" ], "text/plain": [ - "Message(id='msg_01BhhYTBp4v33C7XK911jkBY', content=[TextBlock(text='To build meaningful relationships, pursue passions, learn continuously, help others, appreciate beauty, overcome challenges, leave a positive legacy, and find personal fulfillment through both small daily moments and larger life achievements. Each person ultimately defines their own unique meaning.', type='text')], model='claude-3-5-sonnet-20241022', role='assistant', stop_reason='end_turn', stop_sequence=None, type='message', usage=In: 105; Out: 54; Cache create: 0; Cache read: 0; Total: 159)" + "Message(id='msg_01J4G2MqStkSnGeLGwgwvuid', content=[TextBlock(citations=None, text='To grow, learn, love, help others, experience joy and beauty, leave the world better than we found it, and discover our own unique way of contributing to the grand tapestry of existence.', type='text')], model='claude-3-5-sonnet-20241022', role='assistant', stop_reason='end_turn', stop_sequence=None, type='message', usage=In: 101; Out: 44; Cache create: 0; Cache read: 0; Total: 145)" ] }, "execution_count": null, @@ -3131,7 +3132,7 @@ "name": "stdout", "output_type": "stream", "text": [ - "According to Douglas Adams, 42. More seriously: to find purpose, create meaning, and positively impact others while experiencing personal growth and fulfillment." + "According to Douglas Adams, 42. More seriously: to find purpose, create meaning, and positively impact others while experiencing joy and growth." ] } ], @@ -3197,8 +3198,8 @@ "\n", "
\n", "\n", - "- id: `msg_01JhbFVyHVVHLnZ4ahFcN4Ek`\n", - "- content: `[{'text': 'Let me calculate that sum for you.', 'type': 'text'}, {'id': 'toolu_01Qhqk7qbueJgL6gPxQwVrW3', 'input': {'a': 604542, 'b': 6458932}, 'name': 'sums', 'type': 'tool_use'}]`\n", + "- id: `msg_01LqienMJFhpf9uhXNFC7fao`\n", + "- content: `[{'citations': None, 'text': 'Let me calculate that sum for you.', 'type': 'text'}, {'id': 'toolu_01MM7WyvuQTwgBKCgMEtDfnM', 'input': {'a': 604542, 'b': 6458932}, 'name': 'sums', 'type': 'tool_use'}]`\n", "- model: `claude-3-5-sonnet-20241022`\n", "- role: `assistant`\n", "- stop_reason: `tool_use`\n", @@ -3209,7 +3210,7 @@ "
" ], "text/plain": [ - "Message(id='msg_01JhbFVyHVVHLnZ4ahFcN4Ek', content=[TextBlock(text='Let me calculate that sum for you.', type='text'), ToolUseBlock(id='toolu_01Qhqk7qbueJgL6gPxQwVrW3', input={'a': 604542, 'b': 6458932}, name='sums', type='tool_use')], model='claude-3-5-sonnet-20241022', role='assistant', stop_reason='tool_use', stop_sequence=None, type='message', usage=In: 437; Out: 81; Cache create: 0; Cache read: 0; Total: 518)" + "Message(id='msg_01LqienMJFhpf9uhXNFC7fao', content=[TextBlock(citations=None, text='Let me calculate that sum for you.', type='text'), ToolUseBlock(id='toolu_01MM7WyvuQTwgBKCgMEtDfnM', input={'a': 604542, 'b': 6458932}, name='sums', type='tool_use')], model='claude-3-5-sonnet-20241022', role='assistant', stop_reason='tool_use', stop_sequence=None, type='message', usage=In: 437; Out: 81; Cache create: 0; Cache read: 0; Total: 518)" ] }, "execution_count": null, @@ -3244,8 +3245,8 @@ "\n", "
\n", "\n", - "- id: `msg_01CLF5FTpcfAJcgXQqYY1mSX`\n", - "- content: `[{'text': '604542 + 6458932 = 7063474', 'type': 'text'}]`\n", + "- id: `msg_01Q2QvV7cpKRjd7M8uCMmqQo`\n", + "- content: `[{'citations': None, 'text': '604542 + 6458932 = 7063474', 'type': 'text'}]`\n", "- model: `claude-3-5-sonnet-20241022`\n", "- role: `assistant`\n", "- stop_reason: `end_turn`\n", @@ -3256,7 +3257,7 @@ "
" ], "text/plain": [ - "Message(id='msg_01CLF5FTpcfAJcgXQqYY1mSX', content=[TextBlock(text='604542 + 6458932 = 7063474', type='text')], model='claude-3-5-sonnet-20241022', role='assistant', stop_reason='end_turn', stop_sequence=None, type='message', usage=In: 532; Out: 18; Cache create: 0; Cache read: 0; Total: 550)" + "Message(id='msg_01Q2QvV7cpKRjd7M8uCMmqQo', content=[TextBlock(citations=None, text='604542 + 6458932 = 7063474', type='text')], model='claude-3-5-sonnet-20241022', role='assistant', stop_reason='end_turn', stop_sequence=None, type='message', usage=In: 532; Out: 18; Cache create: 0; Cache read: 0; Total: 550)" ] }, "execution_count": null, @@ -3318,8 +3319,8 @@ "\n", "
\n", "\n", - "- id: `msg_01QfbZeGoo37NEKz4GuH6h6k`\n", - "- content: `[{'text': 'Let me find the page number that represents 75% of your book.', 'type': 'text'}, {'id': 'toolu_01FzjeEVmHxsEsr1fkroHR6F', 'input': {'book': {'title': 'Tao Te Ching', 'pages': 80}, 'percent': 75}, 'name': 'find_page', 'type': 'tool_use'}]`\n", + "- id: `msg_012yY5CbPV8NRpTJ4pu7Kiap`\n", + "- content: `[{'citations': None, 'text': 'Let me find the page number that represents 75% of your book.', 'type': 'text'}, {'id': 'toolu_019DERahLJ7YZiqTb5gEy1eZ', 'input': {'book': {'title': 'Tao Te Ching', 'pages': 80}, 'percent': 75}, 'name': 'find_page', 'type': 'tool_use'}]`\n", "- model: `claude-3-5-sonnet-20241022`\n", "- role: `assistant`\n", "- stop_reason: `tool_use`\n", @@ -3330,7 +3331,7 @@ "
" ], "text/plain": [ - "Message(id='msg_01QfbZeGoo37NEKz4GuH6h6k', content=[TextBlock(text='Let me find the page number that represents 75% of your book.', type='text'), ToolUseBlock(id='toolu_01FzjeEVmHxsEsr1fkroHR6F', input={'book': {'title': 'Tao Te Ching', 'pages': 80}, 'percent': 75}, name='find_page', type='tool_use')], model='claude-3-5-sonnet-20241022', role='assistant', stop_reason='tool_use', stop_sequence=None, type='message', usage=In: 547; Out: 102; Cache create: 0; Cache read: 0; Total: 649)" + "Message(id='msg_012yY5CbPV8NRpTJ4pu7Kiap', content=[TextBlock(citations=None, text='Let me find the page number that represents 75% of your book.', type='text'), ToolUseBlock(id='toolu_019DERahLJ7YZiqTb5gEy1eZ', input={'book': {'title': 'Tao Te Ching', 'pages': 80}, 'percent': 75}, name='find_page', type='tool_use')], model='claude-3-5-sonnet-20241022', role='assistant', stop_reason='tool_use', stop_sequence=None, type='message', usage=In: 547; Out: 102; Cache create: 0; Cache read: 0; Total: 649)" ] }, "execution_count": null, @@ -3365,8 +3366,8 @@ "\n", "
\n", "\n", - "- id: `msg_011zPCK1REkf4EYsAEr7mtRP`\n", - "- content: `[{'text': 'Three quarters (75%) of the way through your 80-page edition of Tao Te Ching would be page 60.', 'type': 'text'}]`\n", + "- id: `msg_019zmzmw9zTakLGPtVNyE42c`\n", + "- content: `[{'citations': None, 'text': 'Three quarters (75%) of the way through your 80-page edition of Tao Te Ching would be page 60.', 'type': 'text'}]`\n", "- model: `claude-3-5-sonnet-20241022`\n", "- role: `assistant`\n", "- stop_reason: `end_turn`\n", @@ -3377,7 +3378,7 @@ "
" ], "text/plain": [ - "Message(id='msg_011zPCK1REkf4EYsAEr7mtRP', content=[TextBlock(text='Three quarters (75%) of the way through your 80-page edition of Tao Te Ching would be page 60.', type='text')], model='claude-3-5-sonnet-20241022', role='assistant', stop_reason='end_turn', stop_sequence=None, type='message', usage=In: 661; Out: 33; Cache create: 0; Cache read: 0; Total: 694)" + "Message(id='msg_019zmzmw9zTakLGPtVNyE42c', content=[TextBlock(citations=None, text='Three quarters (75%) of the way through your 80-page edition of Tao Te Ching would be page 60.', type='text')], model='claude-3-5-sonnet-20241022', role='assistant', stop_reason='end_turn', stop_sequence=None, type='message', usage=In: 661; Out: 33; Cache create: 0; Cache read: 0; Total: 694)" ] }, "execution_count": null, @@ -3598,8 +3599,8 @@ "\n", "
\n", "\n", - "- id: `msg_0183vbseGKbMhMmk3rhCT5yy`\n", - "- content: `[{'text': 'In the background of this adorable Cavalier King Charles Spaniel puppy, there are purple/lavender colored flowers, which appear to be some type of aster or daisy-like blooms.', 'type': 'text'}]`\n", + "- id: `msg_01F7LGpjMYPN48qAmjDqTXcj`\n", + "- content: `[{'citations': None, 'text': 'In the background of this adorable Cavalier King Charles Spaniel puppy, there are purple/lavender colored flowers, which appear to be some type of aster or daisy-like blooms.', 'type': 'text'}]`\n", "- model: `claude-3-5-sonnet-20241022`\n", "- role: `assistant`\n", "- stop_reason: `end_turn`\n", @@ -3610,7 +3611,7 @@ "
" ], "text/plain": [ - "Message(id='msg_0183vbseGKbMhMmk3rhCT5yy', content=[TextBlock(text='In the background of this adorable Cavalier King Charles Spaniel puppy, there are purple/lavender colored flowers, which appear to be some type of aster or daisy-like blooms.', type='text')], model='claude-3-5-sonnet-20241022', role='assistant', stop_reason='end_turn', stop_sequence=None, type='message', usage=In: 110; Out: 47; Cache create: 0; Cache read: 0; Total: 157)" + "Message(id='msg_01F7LGpjMYPN48qAmjDqTXcj', content=[TextBlock(citations=None, text='In the background of this adorable Cavalier King Charles Spaniel puppy, there are purple/lavender colored flowers, which appear to be some type of aster or daisy-like blooms.', type='text')], model='claude-3-5-sonnet-20241022', role='assistant', stop_reason='end_turn', stop_sequence=None, type='message', usage=In: 110; Out: 47; Cache create: 0; Cache read: 0; Total: 157)" ] }, "execution_count": null, @@ -3653,8 +3654,8 @@ "\n", "
\n", "\n", - "- id: `msg_01BBcUWJ1uMcpf5671LDBrtV`\n", - "- content: `[{'text': 'In the background of this adorable Cavalier King Charles Spaniel puppy, there are purple/lavender colored flowers, which appear to be some type of aster or daisy-like blooms.', 'type': 'text'}]`\n", + "- id: `msg_01AHfAMWArVmE5mmJNpm6U57`\n", + "- content: `[{'citations': None, 'text': 'In the background of this adorable Cavalier King Charles Spaniel puppy, there are purple/lavender colored flowers, which appear to be some type of aster or daisy-like blooms.', 'type': 'text'}]`\n", "- model: `claude-3-5-sonnet-20241022`\n", "- role: `assistant`\n", "- stop_reason: `end_turn`\n", @@ -3665,7 +3666,7 @@ "
" ], "text/plain": [ - "Message(id='msg_01BBcUWJ1uMcpf5671LDBrtV', content=[TextBlock(text='In the background of this adorable Cavalier King Charles Spaniel puppy, there are purple/lavender colored flowers, which appear to be some type of aster or daisy-like blooms.', type='text')], model='claude-3-5-sonnet-20241022', role='assistant', stop_reason='end_turn', stop_sequence=None, type='message', usage=In: 110; Out: 47; Cache create: 0; Cache read: 0; Total: 157)" + "Message(id='msg_01AHfAMWArVmE5mmJNpm6U57', content=[TextBlock(citations=None, text='In the background of this adorable Cavalier King Charles Spaniel puppy, there are purple/lavender colored flowers, which appear to be some type of aster or daisy-like blooms.', type='text')], model='claude-3-5-sonnet-20241022', role='assistant', stop_reason='end_turn', stop_sequence=None, type='message', usage=In: 110; Out: 47; Cache create: 0; Cache read: 0; Total: 157)" ] }, "execution_count": null, @@ -3685,7 +3686,6 @@ "metadata": {}, "outputs": [], "source": [ - "#| exports\n", "def contents(r):\n", " \"Helper to get the contents from Claude response `r`.\"\n", " blk = find_block(r)\n", @@ -3864,8 +3864,8 @@ "\n", "
\n", "\n", - "- id: `msg_016R6pkyWN1KqmTj81F5mMeA`\n", - "- content: `[{'text': 'Hello Jeremy! Nice to meet you. How are you today?', 'type': 'text'}]`\n", + "- id: `msg_01N4PALinLf25zjzE8gFe9PQ`\n", + "- content: `[{'citations': None, 'text': 'Hello Jeremy! Nice to meet you. How are you today?', 'type': 'text'}]`\n", "- model: `claude-3-5-sonnet-20241022`\n", "- role: `assistant`\n", "- stop_reason: `end_turn`\n", @@ -3876,7 +3876,7 @@ "
" ], "text/plain": [ - "Message(id='msg_016R6pkyWN1KqmTj81F5mMeA', content=[TextBlock(text='Hello Jeremy! Nice to meet you. How are you today?', type='text')], model='claude-3-5-sonnet-20241022', role='assistant', stop_reason='end_turn', stop_sequence=None, type='message', usage=In: 20; Out: 16; Cache create: 0; Cache read: 0; Total: 36)" + "Message(id='msg_01N4PALinLf25zjzE8gFe9PQ', content=[TextBlock(citations=None, text='Hello Jeremy! Nice to meet you. How are you today?', type='text')], model='claude-3-5-sonnet-20241022', role='assistant', stop_reason='end_turn', stop_sequence=None, type='message', usage=In: 20; Out: 16; Cache create: 0; Cache read: 0; Total: 36)" ] }, "execution_count": null, @@ -3905,23 +3905,23 @@ { "data": { "text/markdown": [ - "I notice you've shared a very long block of \"Lorem ipsum\" placeholder text. While I can process this text, it doesn't contain any meaningful content for us to discuss. Is there something specific you'd like to talk about or ask me? I'm happy to help with any real questions or topics you have in mind.\n", + "I notice you've shared a very long block of \"Lorem ipsum\" placeholder text. While I can process this text, it would be more productive to have a real conversation. Is there something specific you'd like to discuss or ask about?\n", "\n", "
\n", "\n", - "- id: `msg_01Nvt4GVBDq9oGatCWd3D2qx`\n", - "- content: `[{'text': 'I notice you\\'ve shared a very long block of \"Lorem ipsum\" placeholder text. While I can process this text, it doesn\\'t contain any meaningful content for us to discuss. Is there something specific you\\'d like to talk about or ask me? I\\'m happy to help with any real questions or topics you have in mind.', 'type': 'text'}]`\n", + "- id: `msg_011o7CmtmEFL3yqR5HuX6JAY`\n", + "- content: `[{'citations': None, 'text': 'I notice you\\'ve shared a very long block of \"Lorem ipsum\" placeholder text. While I can process this text, it would be more productive to have a real conversation. Is there something specific you\\'d like to discuss or ask about?', 'type': 'text'}]`\n", "- model: `claude-3-5-sonnet-20241022`\n", "- role: `assistant`\n", "- stop_reason: `end_turn`\n", "- stop_sequence: `None`\n", "- type: `message`\n", - "- usage: `{'cache_creation_input_tokens': 1083, 'cache_read_input_tokens': 0, 'input_tokens': 4, 'output_tokens': 69}`\n", + "- usage: `{'cache_creation_input_tokens': 1083, 'cache_read_input_tokens': 0, 'input_tokens': 4, 'output_tokens': 51}`\n", "\n", "
" ], "text/plain": [ - "Message(id='msg_01Nvt4GVBDq9oGatCWd3D2qx', content=[TextBlock(text='I notice you\\'ve shared a very long block of \"Lorem ipsum\" placeholder text. While I can process this text, it doesn\\'t contain any meaningful content for us to discuss. Is there something specific you\\'d like to talk about or ask me? I\\'m happy to help with any real questions or topics you have in mind.', type='text')], model='claude-3-5-sonnet-20241022', role='assistant', stop_reason='end_turn', stop_sequence=None, type='message', usage=In: 4; Out: 69; Cache create: 1083; Cache read: 0; Total: 1156)" + "Message(id='msg_011o7CmtmEFL3yqR5HuX6JAY', content=[TextBlock(citations=None, text='I notice you\\'ve shared a very long block of \"Lorem ipsum\" placeholder text. While I can process this text, it would be more productive to have a real conversation. Is there something specific you\\'d like to discuss or ask about?', type='text')], model='claude-3-5-sonnet-20241022', role='assistant', stop_reason='end_turn', stop_sequence=None, type='message', usage=In: 4; Out: 51; Cache create: 1083; Cache read: 0; Total: 1138)" ] }, "execution_count": null, @@ -3950,23 +3950,23 @@ { "data": { "text/markdown": [ - "No problem at all! It happens! At least it wasn't a cat walking across your keyboard - those make even less sense! 😄 What would you like to chat about?\n", + "No problem at all! It happens! At least it wasn't a cat walking across your keyboard 😄 What would you like to chat about?\n", "\n", "
\n", "\n", - "- id: `msg_016yZKKx5aBKewzzmbyYt6E2`\n", - "- content: `[{'text': \"No problem at all! It happens! At least it wasn't a cat walking across your keyboard - those make even less sense! 😄 What would you like to chat about?\", 'type': 'text'}]`\n", + "- id: `msg_01H1itZnJM9BPca1AJg4Tjnj`\n", + "- content: `[{'citations': None, 'text': \"No problem at all! It happens! At least it wasn't a cat walking across your keyboard 😄 What would you like to chat about?\", 'type': 'text'}]`\n", "- model: `claude-3-5-sonnet-20241022`\n", "- role: `assistant`\n", "- stop_reason: `end_turn`\n", "- stop_sequence: `None`\n", "- type: `message`\n", - "- usage: `{'cache_creation_input_tokens': 87, 'cache_read_input_tokens': 1083, 'input_tokens': 4, 'output_tokens': 41}`\n", + "- usage: `{'cache_creation_input_tokens': 69, 'cache_read_input_tokens': 1083, 'input_tokens': 4, 'output_tokens': 34}`\n", "\n", "
" ], "text/plain": [ - "Message(id='msg_016yZKKx5aBKewzzmbyYt6E2', content=[TextBlock(text=\"No problem at all! It happens! At least it wasn't a cat walking across your keyboard - those make even less sense! 😄 What would you like to chat about?\", type='text')], model='claude-3-5-sonnet-20241022', role='assistant', stop_reason='end_turn', stop_sequence=None, type='message', usage=In: 4; Out: 41; Cache create: 87; Cache read: 1083; Total: 1215)" + "Message(id='msg_01H1itZnJM9BPca1AJg4Tjnj', content=[TextBlock(citations=None, text=\"No problem at all! It happens! At least it wasn't a cat walking across your keyboard 😄 What would you like to chat about?\", type='text')], model='claude-3-5-sonnet-20241022', role='assistant', stop_reason='end_turn', stop_sequence=None, type='message', usage=In: 4; Out: 34; Cache create: 69; Cache read: 1083; Total: 1190)" ] }, "execution_count": null, @@ -3978,6 +3978,293 @@ "chat(\"Oh thank you! Sorry, my lorem ipsum generator got out of control!\")" ] }, + { + "cell_type": "markdown", + "id": "c07e0589", + "metadata": {}, + "source": [ + "## Citations" + ] + }, + { + "cell_type": "markdown", + "id": "fa6796f3", + "metadata": {}, + "source": [ + "Claude is capable of providing detailed citations when answering questions about documents, helping you track and verify information sources in responses.\n", + "\n", + "Claude expects a document to have the following structure.\n", + "\n", + "``` python\n", + "{\n", + " \"role\": \"user\",\n", + " \"content\": [\n", + " {\n", + " \"type\": \"document\",\n", + " \"source\": {\n", + " \"type\": \"text\",\n", + " \"media_type\": \"text/plain\",\n", + " \"data\": \"The grass is green. The sky is blue.\"\n", + " },\n", + " \"title\": \"My Document\",\n", + " \"context\": \"This is a trustworthy document.\",\n", + " \"citations\": {\"enabled\": True}\n", + " },\n", + " {\n", + " \"type\": \"text\",\n", + " \"text\": \"What color is the grass and sky?\"\n", + " }\n", + " ]\n", + "}\n", + "```" + ] + }, + { + "cell_type": "markdown", + "id": "82930a8b", + "metadata": {}, + "source": [ + "To create a document, we pass `citation=True` when calling `mk_doc` with any document. Claude supports plain text, PDF, and custom content." + ] + }, + { + "cell_type": "code", + "execution_count": 11, + "id": "7b3779b4", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "{'type': 'document',\n", + " 'source': {'type': 'text',\n", + " 'media_type': 'text/plain',\n", + " 'data': 'Things to remember when using Claudette:\\n\\n- You must set the `ANTHROPIC_API_KEY` environment variable with your Anthropic API key\\n- Claudette is designed to work with Claude 3 models (Opu'},\n", + " 'citations': {'enabled': True},\n", + " 'title': 'Claudette LLM Context',\n", + " 'context': 'This is a trustworthy document.'}" + ] + }, + "execution_count": 11, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "llms_ctx = xget(\"https://claudette.answer.ai/llms-ctx.txt\").text[:512]\n", + "doc = mk_doc(llms_ctx, title=\"Claudette LLM Context\", context=\"This is a trustworthy document.\", citation=True)\n", + "doc" + ] + }, + { + "cell_type": "markdown", + "id": "21a52343", + "metadata": {}, + "source": [ + "Let's use the document with a message. The response contains text and citations alternating back and forth." + ] + }, + { + "cell_type": "code", + "execution_count": 12, + "id": "31a575c4", + "metadata": {}, + "outputs": [ + { + "data": { + "text/markdown": [ + "Based on the provided document, Claudette is a Python library that provides a higher-level interface for Anthropic's Claude API. It helps developers create AI applications by automating common patterns while maintaining control, with features including stateful chat, prefill support, image handling, and streamlined tool use\n", + "> Claudette LLM Context - start: 0 end: 323\n", + "> \n", + "> > \n", + "\n", + "- id: `msg_01KVYtr5AqmHiHisvArFpExo`\n", + "- content: `[{'citations': None, 'text': 'Based on the provided document, ', 'type': 'text'}, {'citations': [{'cited_text': '" + ], + "text/plain": [ + "Message(id='msg_01KVYtr5AqmHiHisvArFpExo', content=[TextBlock(citations=None, text='Based on the provided document, ', type='text'), TextBlock(citations=[CitationCharLocation(cited_text=' str:\n", + " \"\"\"Render a Claude message with citations as markdown.\"\"\"\n", + " result = []\n", + " for block in msg.content:\n", + " result.append(block.text)\n", + " if block.citations:\n", + " for c in block.citations:\n", + " cite_desc = f'{c.document_title} - start: {c.start_char_index} end: {c.end_char_index}'\n", + " lines = c.cited_text.splitlines()\n", + " quoted_lines = '\\n'.join(f\"> {ln}\" for ln in lines)\n", + " f = f\"\\n> {cite_desc}\\n> \\n> {quoted_lines}\\n\\n\"\n", + " result.append(f)\n", + " return ''.join(result)" + ] + }, + { + "cell_type": "code", + "execution_count": 14, + "id": "da3c7b60", + "metadata": {}, + "outputs": [], + "source": [ + "#| exports\n", + "def has_citations(r):\n", + " \"\"\"Check if a Claude response contains any citation.\"\"\"\n", + " return any(getattr(block, 'citations', None) and isinstance(block.citations, list)\n", + " for block in r.content)" + ] + }, + { + "cell_type": "code", + "execution_count": 15, + "id": "aa168512", + "metadata": {}, + "outputs": [], + "source": [ + "#| exports\n", + "def contents(r):\n", + " \"Helper to get the contents from Claude response `r`.\"\n", + " blk = cite_md_msgs(r) if has_citations(r) else find_block(r)\n", + " if not blk and r.content: blk = r.content[0]\n", + " if hasattr(blk,'text'): return blk.text.strip()\n", + " elif hasattr(blk,'content'): return blk.content.strip()\n", + " elif hasattr(blk,'source'): return f'*Media Type - {blk.type}*'\n", + " return str(blk)" + ] + }, + { + "cell_type": "code", + "execution_count": 16, + "id": "4cb7e85a", + "metadata": {}, + "outputs": [ + { + "data": { + "text/markdown": [ + "Based on the provided document, Claudette is a Python library that provides a higher-level interface for Anthropic's Claude API. It helps developers create AI applications by automating common patterns while maintaining control, with features including stateful chat, prefill support, image handling, and streamlined tool use\n", + "> Claudette LLM Context - start: 0 end: 323\n", + "> \n", + "> > \n", + "\n", + "- id: `msg_016nSztUQx55w6j74NobbE2T`\n", + "- content: `[{'citations': None, 'text': 'Based on the provided document, ', 'type': 'text'}, {'citations': [{'cited_text': '" + ], + "text/plain": [ + "Message(id='msg_016nSztUQx55w6j74NobbE2T', content=[TextBlock(citations=None, text='Based on the provided document, ', type='text'), TextBlock(citations=[CitationCharLocation(cited_text='\n", + "History\n", + "\n", + "**user**: *Media Type - document*\n", + "\n", + "**assistant**: Based on the provided document, Claudette is a Python library that provides a higher-level interface for Anthropic's Claude API. It helps developers create AI applications by automating common patterns while maintaining control, with features including stateful chat, prefill support, image handling, and streamlined tool use\n", + "> Claudette LLM Context - start: 0 end: 323\n", + "> \n", + "> > \n", + "\n", + "| Metric | Count | Cost (USD) |\n", + "|--------|------:|-----:|\n", + "| Input tokens | 1,576 | 0.004728 |\n", + "| Output tokens | 98 | 0.001470 |\n", + "| Cache tokens | 0 | 0.000000 |\n", + "| **Total** | **1,674** | **$0.006198** |" + ], + "text/plain": [ + "" + ] + }, + "execution_count": 17, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "c('Hi')\n", + "c" + ] + }, { "cell_type": "markdown", "id": "b1580f5c", @@ -4163,9 +4450,21 @@ ], "metadata": { "kernelspec": { - "display_name": "python3", + "display_name": "Python 3 (ipykernel)", "language": "python", "name": "python3" + }, + "language_info": { + "codemirror_mode": { + "name": "ipython", + "version": 3 + }, + "file_extension": ".py", + "mimetype": "text/x-python", + "name": "python", + "nbconvert_exporter": "python", + "pygments_lexer": "ipython3", + "version": "3.11.11" } }, "nbformat": 4, diff --git a/claudette/_modidx.py b/claudette/_modidx.py index 1e7b148..71d1e70 100644 --- a/claudette/_modidx.py +++ b/claudette/_modidx.py @@ -45,11 +45,13 @@ 'claudette.core.can_set_system_prompt': ('core.html#can_set_system_prompt', 'claudette/core.py'), 'claudette.core.can_set_temperature': ('core.html#can_set_temperature', 'claudette/core.py'), 'claudette.core.can_stream': ('core.html#can_stream', 'claudette/core.py'), + 'claudette.core.cite_msgs': ('core.html#cite_msgs', 'claudette/core.py'), 'claudette.core.contents': ('core.html#contents', 'claudette/core.py'), 'claudette.core.find_block': ('core.html#find_block', 'claudette/core.py'), 'claudette.core.get_costs': ('core.html#get_costs', 'claudette/core.py'), 'claudette.core.get_pricing': ('core.html#get_pricing', 'claudette/core.py'), 'claudette.core.get_types': ('core.html#get_types', 'claudette/core.py'), + 'claudette.core.has_citations': ('core.html#has_citations', 'claudette/core.py'), 'claudette.core.mk_funcres': ('core.html#mk_funcres', 'claudette/core.py'), 'claudette.core.mk_tool_choice': ('core.html#mk_tool_choice', 'claudette/core.py'), 'claudette.core.mk_toolres': ('core.html#mk_toolres', 'claudette/core.py'), diff --git a/claudette/core.py b/claudette/core.py index e68cd65..8254a0e 100644 --- a/claudette/core.py +++ b/claudette/core.py @@ -4,7 +4,8 @@ __all__ = ['empty', 'model_types', 'all_models', 'models', 'models_aws', 'models_goog', 'text_only_models', 'has_streaming_models', 'has_system_prompt_models', 'has_temperature_models', 'pricing', 'can_stream', 'can_set_system_prompt', 'can_set_temperature', 'find_block', 'usage', 'Client', 'get_pricing', 'get_costs', - 'mk_tool_choice', 'mk_funcres', 'mk_toolres', 'get_types', 'tool', 'Chat', 'contents', 'mk_msg', 'mk_msgs'] + 'mk_tool_choice', 'mk_funcres', 'mk_toolres', 'get_types', 'tool', 'Chat', 'cite_msgs', 'has_citations', + 'contents', 'mk_msg', 'mk_msgs'] # %% ../00_core.ipynb import inspect, typing, json @@ -23,7 +24,7 @@ from fastcore.meta import delegates from fastcore.utils import * -from msglm import mk_msg_anthropic as mk_msg, mk_msgs_anthropic as mk_msgs +from msglm import mk_msg_anthropic as mk_msg, mk_msgs_anthropic as mk_msgs, mk_ant_doc as mk_doc # %% ../00_core.ipynb _all_ = ['mk_msg', 'mk_msgs'] @@ -406,10 +407,31 @@ def fmt_msg(m): {det}""" +# %% ../00_core.ipynb +def cite_msgs(msg) -> str: + """Render a Claude message with citations as markdown.""" + result = [] + for block in msg.content: + result.append(block.text) + if block.citations: + for c in block.citations: + cite_desc = f'{c.document_title} - start: {c.start_char_index} end: {c.end_char_index}' + lines = c.cited_text.splitlines() + quoted_lines = '\n'.join(f"> {ln}" for ln in lines) + f = f"\n> {cite_desc}\n> \n> {quoted_lines}\n\n" + result.append(f) + return ''.join(result) + +# %% ../00_core.ipynb +def has_citations(r): + """Check if a Claude response contains any citations""" + return any(getattr(block, 'citations', None) and isinstance(block.citations, list) + for block in r.content) + # %% ../00_core.ipynb def contents(r): "Helper to get the contents from Claude response `r`." - blk = find_block(r) + blk = cite_msgs(r) if has_citations(r) else find_block(r) if not blk and r.content: blk = r.content[0] if hasattr(blk,'text'): return blk.text.strip() elif hasattr(blk,'content'): return blk.content.strip()