From 079fb0568b60c093fe2546e924ef569aef141ee4 Mon Sep 17 00:00:00 2001 From: ncoop57 Date: Wed, 23 Oct 2024 11:32:28 -0500 Subject: [PATCH] Update structured function to use new mk_ns for everything --- 00_core.ipynb | 149 ++++++++++++++++++++++++---------------------- claudette/core.py | 4 +- 2 files changed, 81 insertions(+), 72 deletions(-) diff --git a/00_core.ipynb b/00_core.ipynb index 41ab39a..fc11b58 100644 --- a/00_core.ipynb +++ b/00_core.ipynb @@ -229,23 +229,23 @@ { "data": { "text/markdown": [ - "Hi Jeremy! Nice to meet you. I'm Claude, an AI assistant created by Anthropic. 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_01XxUSvYVChc7pXgo7qwWaTx`\n", - "- content: `[{'text': \"Hi Jeremy! Nice to meet you. I'm Claude, an AI assistant created by Anthropic. How can I help you today?\", 'type': 'text'}]`\n", + "- id: `msg_01N7BpbVNmZHMv4aF4Vgperz`\n", + "- content: `[{'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", "- stop_sequence: `None`\n", "- type: `message`\n", - "- usage: `{'input_tokens': 10, 'output_tokens': 31}`\n", + "- usage: `{'input_tokens': 10, 'output_tokens': 22}`\n", "\n", "
" ], "text/plain": [ - "Message(id='msg_01XxUSvYVChc7pXgo7qwWaTx', content=[TextBlock(text=\"Hi Jeremy! Nice to meet you. I'm Claude, an AI assistant created by Anthropic. 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: 31; Cache create: 0; Cache read: 0; Total: 41)" + "Message(id='msg_01N7BpbVNmZHMv4aF4Vgperz', 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)" ] }, "execution_count": null, @@ -327,7 +327,7 @@ { "data": { "text/plain": [ - "TextBlock(text=\"Hi Jeremy! Nice to meet you. I'm Claude, an AI assistant created by Anthropic. How can I help you today?\", type='text')" + "TextBlock(text=\"Hi Jeremy! Nice to meet you. I'm Claude. How can I help you today?\", type='text')" ] }, "execution_count": null, @@ -371,7 +371,7 @@ { "data": { "text/plain": [ - "\"Hi Jeremy! Nice to meet you. I'm Claude, an AI assistant created by Anthropic. How can I help you today?\"" + "\"Hi Jeremy! Nice to meet you. I'm Claude. How can I help you today?\"" ] }, "execution_count": null, @@ -421,23 +421,23 @@ { "data": { "text/markdown": [ - "Hi Jeremy! Nice to meet you. I'm Claude, an AI assistant created by Anthropic. 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_01XxUSvYVChc7pXgo7qwWaTx`\n", - "- content: `[{'text': \"Hi Jeremy! Nice to meet you. I'm Claude, an AI assistant created by Anthropic. How can I help you today?\", 'type': 'text'}]`\n", + "- id: `msg_01N7BpbVNmZHMv4aF4Vgperz`\n", + "- content: `[{'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", "- stop_sequence: `None`\n", "- type: `message`\n", - "- usage: `{'input_tokens': 10, 'output_tokens': 31}`\n", + "- usage: `{'input_tokens': 10, 'output_tokens': 22}`\n", "\n", "
" ], "text/plain": [ - "Message(id='msg_01XxUSvYVChc7pXgo7qwWaTx', content=[TextBlock(text=\"Hi Jeremy! Nice to meet you. I'm Claude, an AI assistant created by Anthropic. 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: 31; Cache create: 0; Cache read: 0; Total: 41)" + "Message(id='msg_01N7BpbVNmZHMv4aF4Vgperz', 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)" ] }, "execution_count": null, @@ -468,7 +468,7 @@ { "data": { "text/plain": [ - "In: 10; Out: 31; Cache create: 0; Cache read: 0; Total: 41" + "In: 10; Out: 22; Cache create: 0; Cache read: 0; Total: 32" ] }, "execution_count": null, @@ -639,7 +639,7 @@ { "data": { "text/plain": [ - "In: 20; Out: 62; Cache create: 0; Cache read: 0; Total: 82" + "In: 20; Out: 44; Cache create: 0; Cache read: 0; Total: 64" ] }, "execution_count": null, @@ -730,23 +730,23 @@ { "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 created by Anthropic. How can I help you today?\n", "\n", "
\n", "\n", - "- id: `msg_01B66nGEWHYNbi13ghEyLEjJ`\n", - "- content: `[{'text': \"Hi Jeremy! Nice to meet you. I'm Claude. How can I help you today?\", 'type': 'text'}]`\n", + "- id: `msg_013taKXp67CXLBKtDjRUURFU`\n", + "- content: `[{'text': \"Hi Jeremy! Nice to meet you. I'm Claude, an AI assistant created by Anthropic. 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: `{'input_tokens': 10, 'output_tokens': 22}`\n", + "- usage: `{'input_tokens': 10, 'output_tokens': 31}`\n", "\n", "
" ], "text/plain": [ - "Message(id='msg_01B66nGEWHYNbi13ghEyLEjJ', 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_013taKXp67CXLBKtDjRUURFU', content=[TextBlock(text=\"Hi Jeremy! Nice to meet you. I'm Claude, an AI assistant created by Anthropic. 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: 31; Cache create: 0; Cache read: 0; Total: 41)" ] }, "execution_count": null, @@ -821,7 +821,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(text=\"Hi Jeremy! Nice to meet you. I'm Claude, an AI assistant created by Anthropic. How can I help you today?\", type='text')]},\n", " {'role': 'user', 'content': 'I forgot my name. Can you remind me please?'}]" ] }, @@ -856,19 +856,19 @@ "\n", "
\n", "\n", - "- id: `msg_01NteWDbgnvj3p5QL7QK4yYs`\n", + "- id: `msg_01EPrgHY2bRNcRBj6RJzGLCr`\n", "- content: `[{'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: `{'input_tokens': 46, 'output_tokens': 12}`\n", + "- usage: `{'input_tokens': 55, 'output_tokens': 12}`\n", "\n", "
" ], "text/plain": [ - "Message(id='msg_01NteWDbgnvj3p5QL7QK4yYs', 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_01EPrgHY2bRNcRBj6RJzGLCr', 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: 55; Out: 12; Cache create: 0; Cache read: 0; Total: 67)" ] }, "execution_count": null, @@ -974,7 +974,7 @@ { "data": { "text/plain": [ - "In: 10; Out: 22; Cache create: 0; Cache read: 0; Total: 32" + "In: 10; Out: 31; Cache create: 0; Cache read: 0; Total: 41" ] }, "execution_count": null, @@ -1136,7 +1136,7 @@ "\n", "
\n", "\n", - "- id: `msg_019RqXy8qeC49aaEXWyB7X1S`\n", + "- id: `msg_01B7RhgVrvQTB9riLkwWg1ie`\n", "- content: `[{'text': 'Hello! How can I assist you today?', 'type': 'text'}]`\n", "- model: `claude-3-haiku-20240307`\n", "- role: `assistant`\n", @@ -1148,7 +1148,7 @@ "
" ], "text/plain": [ - "Message(id='msg_019RqXy8qeC49aaEXWyB7X1S', content=[TextBlock(text='Hello! How can I assist you today?', type='text')], model='claude-3-haiku-20240307', 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_01B7RhgVrvQTB9riLkwWg1ie', content=[TextBlock(text='Hello! How can I assist you today?', type='text')], model='claude-3-haiku-20240307', 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, @@ -1213,7 +1213,7 @@ "\n", "
\n", "\n", - "- id: `msg_01UEv2cNdGqrUiiC582GHAVh`\n", + "- id: `msg_015xKvUT8NSzzSFb7KXLwsNi`\n", "- content: `[{'text': 'According to Douglas Adams, \"The answer to the ultimate question of life, the universe, and everything is 42.\"', 'type': 'text'}]`\n", "- model: `claude-3-haiku-20240307`\n", "- role: `assistant`\n", @@ -1225,7 +1225,7 @@ "
" ], "text/plain": [ - "Message(id='msg_01UEv2cNdGqrUiiC582GHAVh', content=[TextBlock(text='According to Douglas Adams, \"The answer to the ultimate question of life, the universe, and everything is 42.\"', type='text')], model='claude-3-haiku-20240307', role='assistant', stop_reason='end_turn', stop_sequence=None, type='message', usage=In: 24; Out: 23; Cache create: 0; Cache read: 0; Total: 47)" + "Message(id='msg_015xKvUT8NSzzSFb7KXLwsNi', content=[TextBlock(text='According to Douglas Adams, \"The answer to the ultimate question of life, the universe, and everything is 42.\"', type='text')], model='claude-3-haiku-20240307', role='assistant', stop_reason='end_turn', stop_sequence=None, type='message', usage=In: 24; Out: 23; Cache create: 0; Cache read: 0; Total: 47)" ] }, "execution_count": null, @@ -1344,7 +1344,7 @@ "\n", "
\n", "\n", - "- id: `msg_013cCmYBKtFaaTSpunwQS22T`\n", + "- id: `msg_013HvMd3c1gNsLDRb4A9Lm6C`\n", "- content: `[{'text': '1, 2, 3, 4, ', 'type': 'text'}]`\n", "- model: `claude-3-haiku-20240307`\n", "- role: `assistant`\n", @@ -1356,7 +1356,7 @@ "
" ], "text/plain": [ - "Message(id='msg_013cCmYBKtFaaTSpunwQS22T', content=[TextBlock(text='1, 2, 3, 4, ', type='text')], model='claude-3-haiku-20240307', role='assistant', stop_reason='stop_sequence', stop_sequence='5', type='message', usage=In: 15; Out: 14; Cache create: 0; Cache read: 0; Total: 29)" + "Message(id='msg_013HvMd3c1gNsLDRb4A9Lm6C', content=[TextBlock(text='1, 2, 3, 4, ', type='text')], model='claude-3-haiku-20240307', role='assistant', stop_reason='stop_sequence', stop_sequence='5', type='message', usage=In: 15; Out: 14; Cache create: 0; Cache read: 0; Total: 29)" ] }, "execution_count": null, @@ -1423,7 +1423,7 @@ " 'temp': None,\n", " 'stream': None,\n", " 'stop': None,\n", - " 'result': Message(id='msg_013sJk7hM4CfBMkMzTxt1BTk', content=[TextBlock(text='1, ', type='text')], model='claude-3-haiku-20240307', role='assistant', stop_reason='stop_sequence', stop_sequence='2', type='message', usage=In: 15; Out: 5; Cache create: 0; Cache read: 0; Total: 20),\n", + " 'result': Message(id='msg_01KxXCh98wwUs9zQ9CSfY9Uf', content=[TextBlock(text='1, ', type='text')], model='claude-3-haiku-20240307', role='assistant', stop_reason='stop_sequence', stop_sequence='2', type='message', usage=In: 15; Out: 5; Cache create: 0; Cache read: 0; Total: 20),\n", " 'use': In: 94; Out: 89; Cache create: 0; Cache read: 0; Total: 183,\n", " 'stop_reason': 'stop_sequence',\n", " 'stop_sequence': '2'}" @@ -1563,12 +1563,12 @@ { "data": { "text/markdown": [ - "ToolUseBlock(id='toolu_018zHMQCmBPgHz4JpVG9xvMD', input={'a': 604542, 'b': 6458932}, name='sums', type='tool_use')\n", + "ToolUseBlock(id='toolu_01CWvR4gjtHZwp7maM2exdGr', input={'a': 604542, 'b': 6458932}, name='sums', type='tool_use')\n", "\n", "
\n", "\n", - "- id: `msg_01125EobSy7WBeZoV6asSf2o`\n", - "- content: `[{'id': 'toolu_018zHMQCmBPgHz4JpVG9xvMD', 'input': {'a': 604542, 'b': 6458932}, 'name': 'sums', 'type': 'tool_use'}]`\n", + "- id: `msg_01Pze5co7jijaGQDWykwx8WJ`\n", + "- content: `[{'id': 'toolu_01CWvR4gjtHZwp7maM2exdGr', 'input': {'a': 604542, 'b': 6458932}, 'name': 'sums', 'type': 'tool_use'}]`\n", "- model: `claude-3-haiku-20240307`\n", "- role: `assistant`\n", "- stop_reason: `tool_use`\n", @@ -1579,7 +1579,7 @@ "
" ], "text/plain": [ - "Message(id='msg_01125EobSy7WBeZoV6asSf2o', content=[ToolUseBlock(id='toolu_018zHMQCmBPgHz4JpVG9xvMD', input={'a': 604542, 'b': 6458932}, name='sums', type='tool_use')], model='claude-3-haiku-20240307', role='assistant', stop_reason='tool_use', stop_sequence=None, type='message', usage=In: 483; Out: 53; Cache create: 0; Cache read: 0; Total: 536)" + "Message(id='msg_01Pze5co7jijaGQDWykwx8WJ', content=[ToolUseBlock(id='toolu_01CWvR4gjtHZwp7maM2exdGr', input={'a': 604542, 'b': 6458932}, name='sums', type='tool_use')], model='claude-3-haiku-20240307', role='assistant', stop_reason='tool_use', stop_sequence=None, type='message', usage=In: 483; Out: 53; Cache create: 0; Cache read: 0; Total: 536)" ] }, "execution_count": null, @@ -1663,7 +1663,7 @@ "data": { "text/plain": [ "{'type': 'tool_result',\n", - " 'tool_use_id': 'toolu_018zHMQCmBPgHz4JpVG9xvMD',\n", + " 'tool_use_id': 'toolu_01CWvR4gjtHZwp7maM2exdGr',\n", " 'content': '7063474'}" ] }, @@ -1726,10 +1726,10 @@ "data": { "text/plain": [ "[{'role': 'assistant',\n", - " 'content': [ToolUseBlock(id='toolu_018zHMQCmBPgHz4JpVG9xvMD', input={'a': 604542, 'b': 6458932}, name='sums', type='tool_use')]},\n", + " 'content': [ToolUseBlock(id='toolu_01CWvR4gjtHZwp7maM2exdGr', input={'a': 604542, 'b': 6458932}, name='sums', type='tool_use')]},\n", " {'role': 'user',\n", " 'content': [{'type': 'tool_result',\n", - " 'tool_use_id': 'toolu_018zHMQCmBPgHz4JpVG9xvMD',\n", + " 'tool_use_id': 'toolu_01CWvR4gjtHZwp7maM2exdGr',\n", " 'content': '7063474'}]}]" ] }, @@ -1784,10 +1784,10 @@ "text/plain": [ "[{'role': 'user', 'content': 'What is 604542+6458932?'},\n", " {'role': 'assistant',\n", - " 'content': [ToolUseBlock(id='toolu_018zHMQCmBPgHz4JpVG9xvMD', input={'a': 604542, 'b': 6458932}, name='sums', type='tool_use')]},\n", + " 'content': [ToolUseBlock(id='toolu_01CWvR4gjtHZwp7maM2exdGr', input={'a': 604542, 'b': 6458932}, name='sums', type='tool_use')]},\n", " {'role': 'user',\n", " 'content': [{'type': 'tool_result',\n", - " 'tool_use_id': 'toolu_018zHMQCmBPgHz4JpVG9xvMD',\n", + " 'tool_use_id': 'toolu_01CWvR4gjtHZwp7maM2exdGr',\n", " 'content': '7063474'}]}]" ] }, @@ -1898,12 +1898,12 @@ { "data": { "text/markdown": [ - "ToolUseBlock(id='toolu_01Loy8ekmhtHGYGJZHwrbw3Q', input={'a': 604542, 'b': 6458932}, name='sums', type='tool_use')\n", + "ToolUseBlock(id='toolu_01NRuky7TuvTXwc4h5LE5YVz', input={'a': 604542, 'b': 6458932}, name='sums', type='tool_use')\n", "\n", "
\n", "\n", - "- id: `msg_01Pb6Dg1rxcAFNFyZJ24Eb9b`\n", - "- content: `[{'id': 'toolu_01Loy8ekmhtHGYGJZHwrbw3Q', 'input': {'a': 604542, 'b': 6458932}, 'name': 'sums', 'type': 'tool_use'}]`\n", + "- id: `msg_01HGow4rQdU82LYFfzty4tJj`\n", + "- content: `[{'id': 'toolu_01NRuky7TuvTXwc4h5LE5YVz', 'input': {'a': 604542, 'b': 6458932}, 'name': 'sums', 'type': 'tool_use'}]`\n", "- model: `claude-3-haiku-20240307`\n", "- role: `assistant`\n", "- stop_reason: `tool_use`\n", @@ -1914,7 +1914,7 @@ "
" ], "text/plain": [ - "Message(id='msg_01Pb6Dg1rxcAFNFyZJ24Eb9b', content=[ToolUseBlock(id='toolu_01Loy8ekmhtHGYGJZHwrbw3Q', input={'a': 604542, 'b': 6458932}, name='sums', type='tool_use')], model='claude-3-haiku-20240307', role='assistant', stop_reason='tool_use', stop_sequence=None, type='message', usage=In: 479; Out: 57; Cache create: 0; Cache read: 0; Total: 536)" + "Message(id='msg_01HGow4rQdU82LYFfzty4tJj', content=[ToolUseBlock(id='toolu_01NRuky7TuvTXwc4h5LE5YVz', input={'a': 604542, 'b': 6458932}, name='sums', type='tool_use')], model='claude-3-haiku-20240307', role='assistant', stop_reason='tool_use', stop_sequence=None, type='message', usage=In: 479; Out: 57; Cache create: 0; Cache read: 0; Total: 536)" ] }, "execution_count": null, @@ -1964,8 +1964,8 @@ " \"Return the value of all tool calls (generally used for structured outputs)\"\n", " tools = listify(tools)\n", " res = self(msgs, tools=tools, tool_choice=tools, **kwargs)\n", - " if ns is None: ns=tools\n", - " if obj is not None: ns = obj2ns(obj)\n", + " if ns is None: ns=mk_ns(*tools)\n", + " if obj is not None: ns = mk_ns(obj)\n", " cts = getattr(res, 'content', [])\n", " tcs = [call_func(o.name, o.input, ns=ns) for o in cts if isinstance(o,ToolUseBlock)]\n", " return tcs" @@ -2293,7 +2293,7 @@ "\n", "
\n", "\n", - "- id: `msg_01EU4g7grnyxBEcJ7iozVrAR`\n", + "- id: `msg_013A37GK3ecgKVPFmH8sbzSe`\n", "- content: `[{'text': 'Your name is Jeremy.', 'type': 'text'}]`\n", "- model: `claude-3-5-sonnet-20241022`\n", "- role: `assistant`\n", @@ -2305,7 +2305,7 @@ "
" ], "text/plain": [ - "Message(id='msg_01EU4g7grnyxBEcJ7iozVrAR', 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_013A37GK3ecgKVPFmH8sbzSe', 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)" ] }, "execution_count": null, @@ -2367,12 +2367,12 @@ { "data": { "text/markdown": [ - "According to Douglas Adams, 42. But more seriously: to find purpose, create meaning, and make connections with others while experiencing what life has to offer.\n", + "According to Douglas Adams, 42. But in reality, it's to find personal meaning through experiences, relationships, and pursuing what brings you fulfillment.\n", "\n", "
\n", "\n", - "- id: `msg_01XLo4qvauzGDs7yeDGGE9SZ`\n", - "- content: `[{'text': 'According to Douglas Adams, 42. But more seriously: to find purpose, create meaning, and make connections with others while experiencing what life has to offer.', 'type': 'text'}]`\n", + "- id: `msg_01NXx8tt1UeMViqa6vwybbVb`\n", + "- content: `[{'text': \"According to Douglas Adams, 42. But in reality, it's to find personal meaning through experiences, relationships, and pursuing what brings you fulfillment.\", 'type': 'text'}]`\n", "- model: `claude-3-5-sonnet-20241022`\n", "- role: `assistant`\n", "- stop_reason: `end_turn`\n", @@ -2383,7 +2383,7 @@ "
" ], "text/plain": [ - "Message(id='msg_01XLo4qvauzGDs7yeDGGE9SZ', content=[TextBlock(text='According to Douglas Adams, 42. But more seriously: to find purpose, create meaning, and make connections with others while experiencing what life has to offer.', 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_01NXx8tt1UeMViqa6vwybbVb', content=[TextBlock(text=\"According to Douglas Adams, 42. But in reality, it's to find personal meaning through experiences, relationships, and pursuing what brings you fulfillment.\", 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)" ] }, "execution_count": null, @@ -2439,23 +2439,32 @@ { "data": { "text/markdown": [ - "To grow, learn, love, help others, leave the world better than you found it, and find joy in both life's big moments and small everyday experiences. Ultimately, each person must discover their own unique meaning and purpose.\n", + "Beyond personal fulfillment, life's meaning involves:\n", + "- Making a positive impact on others\n", + "- Learning and growing continuously\n", + "- Creating something lasting\n", + "- Finding love and connection\n", + "- Discovering your unique purpose\n", + "- Contributing to something bigger than yourself\n", + "- Experiencing joy and wonder\n", + "- Overcoming challenges\n", + "- Leaving the world better than you found it\n", "\n", "
\n", "\n", - "- id: `msg_019Xw5krXvY9CY1yeNV3mLEd`\n", - "- content: `[{'text': \"To grow, learn, love, help others, leave the world better than you found it, and find joy in both life's big moments and small everyday experiences. Ultimately, each person must discover their own unique meaning and purpose.\", 'type': 'text'}]`\n", + "- id: `msg_01QjG7pJyx8cW1gpthHinPo8`\n", + "- content: `[{'text': \"Beyond personal fulfillment, life's meaning involves:\\n- Making a positive impact on others\\n- Learning and growing continuously\\n- Creating something lasting\\n- Finding love and connection\\n- Discovering your unique purpose\\n- Contributing to something bigger than yourself\\n- Experiencing joy and wonder\\n- Overcoming challenges\\n- Leaving the world better than you found it\", '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: `{'input_tokens': 105, 'output_tokens': 50, 'cache_creation_input_tokens': 0, 'cache_read_input_tokens': 0}`\n", + "- usage: `{'input_tokens': 105, 'output_tokens': 78, 'cache_creation_input_tokens': 0, 'cache_read_input_tokens': 0}`\n", "\n", "
" ], "text/plain": [ - "Message(id='msg_019Xw5krXvY9CY1yeNV3mLEd', content=[TextBlock(text=\"To grow, learn, love, help others, leave the world better than you found it, and find joy in both life's big moments and small everyday experiences. Ultimately, each person must discover their own unique meaning and purpose.\", type='text')], model='claude-3-5-sonnet-20241022', role='assistant', stop_reason='end_turn', stop_sequence=None, type='message', usage=In: 105; Out: 50; Cache create: 0; Cache read: 0; Total: 155)" + "Message(id='msg_01QjG7pJyx8cW1gpthHinPo8', content=[TextBlock(text=\"Beyond personal fulfillment, life's meaning involves:\\n- Making a positive impact on others\\n- Learning and growing continuously\\n- Creating something lasting\\n- Finding love and connection\\n- Discovering your unique purpose\\n- Contributing to something bigger than yourself\\n- Experiencing joy and wonder\\n- Overcoming challenges\\n- Leaving the world better than you found it\", type='text')], model='claude-3-5-sonnet-20241022', role='assistant', stop_reason='end_turn', stop_sequence=None, type='message', usage=In: 105; Out: 78; Cache create: 0; Cache read: 0; Total: 183)" ] }, "execution_count": null, @@ -2505,7 +2514,7 @@ "name": "stdout", "output_type": "stream", "text": [ - "According to Douglas Adams, it's 42. More seriously: to find purpose, grow, love, and make a positive impact while experiencing what existence has to offer." + "According to Douglas Adams, 42. More seriously: to find purpose, love, grow, and make a positive impact while experiencing life's journey." ] } ], @@ -2571,8 +2580,8 @@ "\n", "
\n", "\n", - "- id: `msg_01PY6M58kwtggDaBU4PSDJHM`\n", - "- content: `[{'text': 'Let me calculate that sum for you.', 'type': 'text'}, {'id': 'toolu_01NPzCbmA3VZXvkPadTcta3q', 'input': {'a': 604542, 'b': 6458932}, 'name': 'sums', 'type': 'tool_use'}]`\n", + "- id: `msg_014s7mQQoAHsnUKTEzttxQT7`\n", + "- content: `[{'text': 'Let me calculate that sum for you.', 'type': 'text'}, {'id': 'toolu_013cYwwW3JfQoWe6qWntsbdw', '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", @@ -2583,7 +2592,7 @@ "
" ], "text/plain": [ - "Message(id='msg_01PY6M58kwtggDaBU4PSDJHM', content=[TextBlock(text='Let me calculate that sum for you.', type='text'), ToolUseBlock(id='toolu_01NPzCbmA3VZXvkPadTcta3q', 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_014s7mQQoAHsnUKTEzttxQT7', content=[TextBlock(text='Let me calculate that sum for you.', type='text'), ToolUseBlock(id='toolu_013cYwwW3JfQoWe6qWntsbdw', 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, @@ -2614,23 +2623,23 @@ { "data": { "text/markdown": [ - "604542 + 6458932 = 7063474\n", + "The sum of 604542 and 6458932 is 7063474.\n", "\n", "
\n", "\n", - "- id: `msg_01LXrCDXvRV8vevwWzCBaNEd`\n", - "- content: `[{'text': '604542 + 6458932 = 7063474', 'type': 'text'}]`\n", + "- id: `msg_01QHCJ4Su1dqm22WzbNNhgQ9`\n", + "- content: `[{'text': 'The sum of 604542 and 6458932 is 7063474.', '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: `{'input_tokens': 532, 'output_tokens': 18, 'cache_creation_input_tokens': 0, 'cache_read_input_tokens': 0}`\n", + "- usage: `{'input_tokens': 532, 'output_tokens': 23, 'cache_creation_input_tokens': 0, 'cache_read_input_tokens': 0}`\n", "\n", "
" ], "text/plain": [ - "Message(id='msg_01LXrCDXvRV8vevwWzCBaNEd', 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_01QHCJ4Su1dqm22WzbNNhgQ9', content=[TextBlock(text='The sum of 604542 and 6458932 is 7063474.', type='text')], model='claude-3-5-sonnet-20241022', role='assistant', stop_reason='end_turn', stop_sequence=None, type='message', usage=In: 532; Out: 23; Cache create: 0; Cache read: 0; Total: 555)" ] }, "execution_count": null, @@ -2816,7 +2825,7 @@ "\n", "
\n", "\n", - "- id: `msg_0115myE2t6tczcqRrcQHBCjD`\n", + "- id: `msg_01D3bn7VFvPe7YofhjecQ2q9`\n", "- content: `[{'text': 'The image contains purple or lavender-colored flowers, which appear to be daisies or a similar type of flower.', 'type': 'text'}]`\n", "- model: `claude-3-haiku-20240307`\n", "- role: `assistant`\n", @@ -2828,7 +2837,7 @@ "
" ], "text/plain": [ - "Message(id='msg_0115myE2t6tczcqRrcQHBCjD', content=[TextBlock(text='The image contains purple or lavender-colored flowers, which appear to be daisies or a similar type of flower.', type='text')], model='claude-3-haiku-20240307', role='assistant', stop_reason='end_turn', stop_sequence=None, type='message', usage=In: 110; Out: 28; Cache create: 0; Cache read: 0; Total: 138)" + "Message(id='msg_01D3bn7VFvPe7YofhjecQ2q9', content=[TextBlock(text='The image contains purple or lavender-colored flowers, which appear to be daisies or a similar type of flower.', type='text')], model='claude-3-haiku-20240307', role='assistant', stop_reason='end_turn', stop_sequence=None, type='message', usage=In: 110; Out: 28; Cache create: 0; Cache read: 0; Total: 138)" ] }, "execution_count": null, @@ -2968,7 +2977,7 @@ "\n", "
\n", "\n", - "- id: `msg_01FLpr3M29NiwydNq6v7gY8j`\n", + "- id: `msg_01St3vzBb7aR4DiHcmZgohkb`\n", "- content: `[{'text': 'The image contains purple or lavender-colored flowers, which appear to be daisies or a similar type of flower.', 'type': 'text'}]`\n", "- model: `claude-3-haiku-20240307`\n", "- role: `assistant`\n", @@ -2980,7 +2989,7 @@ "
" ], "text/plain": [ - "Message(id='msg_01FLpr3M29NiwydNq6v7gY8j', content=[TextBlock(text='The image contains purple or lavender-colored flowers, which appear to be daisies or a similar type of flower.', type='text')], model='claude-3-haiku-20240307', role='assistant', stop_reason='end_turn', stop_sequence=None, type='message', usage=In: 110; Out: 28; Cache create: 0; Cache read: 0; Total: 138)" + "Message(id='msg_01St3vzBb7aR4DiHcmZgohkb', content=[TextBlock(text='The image contains purple or lavender-colored flowers, which appear to be daisies or a similar type of flower.', type='text')], model='claude-3-haiku-20240307', role='assistant', stop_reason='end_turn', stop_sequence=None, type='message', usage=In: 110; Out: 28; Cache create: 0; Cache read: 0; Total: 138)" ] }, "execution_count": null, diff --git a/claudette/core.py b/claudette/core.py index 7f902bb..e231598 100644 --- a/claudette/core.py +++ b/claudette/core.py @@ -219,8 +219,8 @@ def structured(self:Client, "Return the value of all tool calls (generally used for structured outputs)" tools = listify(tools) res = self(msgs, tools=tools, tool_choice=tools, **kwargs) - if ns is None: ns=tools - if obj is not None: ns = obj2ns(obj) + if ns is None: ns=mk_ns(*tools) + if obj is not None: ns = mk_ns(obj) cts = getattr(res, 'content', []) tcs = [call_func(o.name, o.input, ns=ns) for o in cts if isinstance(o,ToolUseBlock)] return tcs