- Notifications
You must be signed in to change notification settings - Fork41
Claudette is Claude's friend
License
AnswerDotAI/claudette
Folders and files
| Name | Name | Last commit message | Last commit date | |
|---|---|---|---|---|
Repository files navigation
NB: If you are reading this in GitHub’s readme, we recommend youinstead read the much more nicely formatteddocumentationformat of this tutorial.
Claudette is a wrapper for Anthropic’sPythonSDK.
The SDK works well, but it is quite low level – it leaves the developerto do a lot of stuff manually. That’s a lot of extra work andboilerplate! Claudette automates pretty much everything that can beautomated, whilst providing full control. Amongst the features provided:
- A
Chatclass thatcreates stateful dialogs - Support forprefill, which tells Claude what to use as the first fewwords of its response
- Convenient image support
- Simple and convenient support for Claude’s new Tool Use API.
You’ll need to set theANTHROPIC_API_KEY environment variable to thekey provided to you by Anthropic in order to use this library.
Note that this library is the first ever “literate nbdev” project. Thatmeans that the actual source code for the library is a rendered JupyterNotebook which includes callout notes and tips, HTML tables and images,detailed explanations, and teacheshow andwhy the code is writtenthe way it is. Even if you’ve never used the Anthropic Python SDK orClaude API before, you should be able to read the source code. ClickClaudette’s Source to read it,or clone the git repo and execute the notebook yourself to see everystep of the creation process in action. The tutorial below includeslinks to API details which will take you to relevant parts of thesource. The reason this project is a new kind of literal program isbecause we take seriously Knuth’s call to action, that we have a “moralcommitment” to never write an “illiterate program” – and so we have acommitment to making literate programming an easy and pleasantexperience. (For more on this, seethistalk from Hamel Husain.)
“Let us change our traditional attitude to the construction ofprograms: Instead of imagining that our main task is to instruct acomputer what to do, let us concentrate rather on explaining tohuman beings what we want a computer to do.” Donald E. Knuth,LiterateProgramming(1984)
pip install claudette
Anthropic’s Python SDK will automatically be installed with Claudette,if you don’t already have it.
importos# os.environ['ANTHROPIC_LOG'] = 'debug'
To print every HTTP request and response in full, uncomment the aboveline.
fromclaudetteimport*
Claudette only exports the symbols that are needed to use the library,so you can useimport * to import them. Alternatively, just use:
importclaudette
…and then add the prefixclaudette. to any usages of the module.
Claudette providesmodels, which is a list of models currentlyavailable from the SDK.
models['claude-opus-4-20250514', 'claude-sonnet-4-20250514', 'claude-3-opus-20240229', 'claude-3-7-sonnet-20250219', 'claude-3-5-sonnet-20241022']For these examples, we’ll use Sonnet 4, since it’s awesome!
model=models[1]model
'claude-sonnet-4-20250514'The main interface to Claudette is theChat class, whichprovides a stateful interface to Claude:
chat=Chat(model,sp="""You are a helpful and concise assistant.""")chat("I'm Jeremy")
Hello Jeremy! Nice to meet you. How can I help you today?
- id:
msg_01NNfbziMKnAULhH72Upzpzg - content:
[{'citations': None, 'text': 'Hello Jeremy! Nice to meet you. How can I help you today?', 'type': 'text'}] - model:
claude-sonnet-4-20250514 - role:
assistant - stop_reason:
end_turn - stop_sequence:
None - type:
message - usage:
{'cache_creation_input_tokens': 0, 'cache_read_input_tokens': 0, 'input_tokens': 19, 'output_tokens': 18, 'server_tool_use': None, 'service_tier': 'standard'}
r=chat("What's my name?")r
Your name is Jeremy.
- id:
msg_01HoboBZtq6dtocz2UWht9ia - content:
[{'citations': None, 'text': 'Your name is Jeremy.', 'type': 'text'}] - model:
claude-sonnet-4-20250514 - role:
assistant - stop_reason:
end_turn - stop_sequence:
None - type:
message - usage:
{'cache_creation_input_tokens': 0, 'cache_read_input_tokens': 0, 'input_tokens': 45, 'output_tokens': 8, 'server_tool_use': None, 'service_tier': 'standard'}
r=chat("What's my name?")r
Your name is Jeremy.
- id:
msg_01SUAYui6JS3Jf65KYfsGWhU - content:
[{'citations': None, 'text': 'Your name is Jeremy.', 'type': 'text'}] - model:
claude-sonnet-4-20250514 - role:
assistant - stop_reason:
end_turn - stop_sequence:
None - type:
message - usage:
{'cache_creation_input_tokens': 0, 'cache_read_input_tokens': 0, 'input_tokens': 61, 'output_tokens': 8, 'server_tool_use': None, 'service_tier': 'standard'}
As you see above, displaying the results of a call in a notebook showsjust the message contents, with the other details hidden behind acollapsible section. Alternatively you canprint the details:
print(r)
Message(id='msg_01SUAYui6JS3Jf65KYfsGWhU', content=[TextBlock(citations=None, text='Your name is Jeremy.', type='text')], model='claude-sonnet-4-20250514', role='assistant', stop_reason='end_turn', stop_sequence=None, type='message', usage=In: 61; Out: 8; Cache create: 0; Cache read: 0; Total Tokens: 69; Search: 0)Claude supports adding an extraassistant message at the end, whichcontains theprefill – i.e. the text we want Claude to assume theresponse starts with. Let’s try it out:
chat("Concisely, what is the meaning of life?",prefill='According to Douglas Adams,')
According to Douglas Adams,it’s 42. More seriously, many find meaningthrough relationships, personal growth, contributing to others, andpursuing what brings fulfillment.
- id:
msg_01UkHn37YePdXg8NVrXk9Qu3 - content:
[{'citations': None, 'text': "According to Douglas Adams,it's 42. More seriously, many find meaning through relationships, personal growth, contributing to others, and pursuing what brings fulfillment.", 'type': 'text'}] - model:
claude-sonnet-4-20250514 - role:
assistant - stop_reason:
end_turn - stop_sequence:
None - type:
message - usage:
{'cache_creation_input_tokens': 0, 'cache_read_input_tokens': 0, 'input_tokens': 89, 'output_tokens': 32, 'server_tool_use': None, 'service_tier': 'standard'}
You can addstream=True to stream the results as soon as they arrive(although you will only see the gradual generation if you execute thenotebook yourself, of course!)
foroinchat("Concisely, what book was that in?",prefill='It was in',stream=True):print(o,end='')
It was in "The Hitchhiker's Guide to the Galaxy."Alternatively, you can useAsyncChat (orAsyncClient) forthe async versions, e.g:
chat=AsyncChat(model)awaitchat("I'm Jeremy")
Nice to meet you, Jeremy! How are you doing today? Is there anything Ican help you with?
- id:
msg_01HyDqMjwcKEc2V39xLWTwFf - content:
[{'citations': None, 'text': 'Nice to meet you, Jeremy! How are you doing today? Is there anything I can help you with?', 'type': 'text'}] - model:
claude-sonnet-4-20250514 - role:
assistant - stop_reason:
end_turn - stop_sequence:
None - type:
message - usage:
{'cache_creation_input_tokens': 0, 'cache_read_input_tokens': 0, 'input_tokens': 10, 'output_tokens': 25, 'server_tool_use': None, 'service_tier': 'standard'}
Remember to useasync for when streaming in this case:
asyncforoinawaitchat("Concisely, what is the meaning of life?",prefill='According to Douglas Adams,',stream=True):print(o,end='')
According to Douglas Adams,it's 42. But more seriously, the meaning of life is likely something you create through your relationships, contributions, growth, and what brings you fulfillment - rather than something you discover pre-made.Claude supportspromptcaching,which can significantly reduce token usage costs when working with largecontexts or repetitive elements. When you usemk_msg(msg, cache=True),Claudette adds the necessary cache control headers to make that messagecacheable.
Prompt caching works by marking segments of your prompt for efficientreuse. When a cached segment is encountered again, Claude reads it fromthe cache rather than processing the full content, resulting in a 90%reduction in token costs for those segments.
Some key points about prompt caching: - Cache writes cost 25% more thannormal input tokens - Cache reads cost 90% less than normal inputtokens - Minimum cacheable length is model-dependent (1024-2048tokens) - Cached segments must be completely identical to be reused -Works well for system prompts, tool definitions, and large contextblocks
For instance, here we use caching when asking about Claudette’s readmefile:
chat=Chat(model,sp="""You are a helpful and concise assistant.""")
nbtxt=Path('README.txt').read_text()msg=f'''<README>{nbtxt}</README>In brief, what is the purpose of this project based on the readme?'''r=chat(mk_msg(msg,cache=True))r
Based on the README, Claudette is a high-level wrapper for Anthropic’sPython SDK that aims to simplify and automate working with Claude’s API.Its main purposes are:
Reduce boilerplate and manual work - It automates tasks thatwould otherwise require manual handling with the base SDK
Provide convenient features like:
- Stateful chat dialogs via the
Chatclass - Support for prefill (controlling Claude’s response start)
- Easy image handling
- Simplified tool use API
- Prompt caching support
- Stateful chat dialogs via the
Maintain full control while providing automation - you getconvenience without losing flexibility
Educational value - It’s the first “literate nbdev” project,meaning the source code is written as a readable Jupyter Notebookwith detailed explanations, making it both functional software and ateaching resource
The project essentially makes Claude’s API more ergonomic anduser-friendly while preserving all the underlying capabilities.
- id:
msg_011SNy9u95nspNq6PSnQuwBF - content:
[{'citations': None, 'text': 'Based on the README, Claudette is a high-level wrapper for Anthropic\'s Python SDK that aims to simplify and automate working with Claude\'s API. Its main purposes are:\n\n1. **Reduce boilerplate and manual work** - It automates tasks that would otherwise require manual handling with the base SDK\n2. **Provide convenient features** like:\n - Stateful chat dialogs via the [Chat](https://claudette.answer.ai/core.html#chat) class\n - Support for prefill (controlling Claude\'s response start)\n - Easy image handling\n - Simplified tool use API\n - Prompt caching support\n\n3. **Maintain full control** while providing automation - you get convenience without losing flexibility\n\n4. **Educational value** - It\'s the first "literate nbdev" project, meaning the source code is written as a readable Jupyter Notebook with detailed explanations, making it both functional software and a teaching resource\n\nThe project essentially makes Claude\'s API more ergonomic and user-friendly while preserving all the underlying capabilities.', 'type': 'text'}] - model:
claude-sonnet-4-20250514 - role:
assistant - stop_reason:
end_turn - stop_sequence:
None - type:
message - usage:
{'cache_creation_input_tokens': 0, 'cache_read_input_tokens': 9287, 'input_tokens': 4, 'output_tokens': 223, 'server_tool_use': None, 'service_tier': 'standard'}
The response records the a cache has been created using these inputtokens:
print(r.usage)
Usage(cache_creation_input_tokens=0, cache_read_input_tokens=9287, input_tokens=4, output_tokens=223, server_tool_use=None, service_tier='standard')We can now ask a followup question in this chat:
r=chat('How does it make tool use more ergonomic?')r
Based on the README, Claudette makes tool use more ergonomic in severalkey ways:
Uses docments to make Python function definitions more user-friendly -you just need type hints and comments:
defsums(a:int,# First thing to sumb:int=1# Second thing to sum)->int:# The sum of the inputs"Adds a + b."returna+b
Handles the tool calling process automatically. When Claude returns atool_use message, you just callchat() again and Claudette: - Callsthe tool with the provided parameters - Passes the result back toClaude - Returns Claude’s final response
No manual parameter extraction or result handling needed.
Thetoolloop method can handle multiple tool calls in sequence tosolve complex problems. For example, calculating(a+b)*2 automaticallyuses both addition and multiplication tools in the right order.
- Pass tools as a simple list to the
Chatconstructor - Optionally force tool usage with
tool_choiceparameter - Get structured data directly with
Client.structured()
Instead of manually handling tool use messages, parameter parsing,function calls, and result formatting that the base SDK requires,Claudette abstracts all of this away while maintaining fullfunctionality.
This makes tool use feel more like natural function calling rather thancomplex API orchestration.
- id:
msg_01XDJNpxiTkhTY9kbu17Q73L - content:
[{'citations': None, 'text': 'Based on the README, Claudette makes tool use more ergonomic in several key ways:\n\n## 1. **Simplified Function Definitions**\nUses docments to make Python function definitions more user-friendly - you just need type hints and comments:\n\n```python\ndef sums(\n a:int, # First thing to sum\n b:int=1 # Second thing to sum\n) -> int: # The sum of the inputs\n "Adds a + b."\n return a + b\n```\n\n## 2. **Automatic Tool Execution**\nHandles the tool calling process automatically. When Claude returns atool_usemessage, you just callchat()again and Claudette:\n- Calls the tool with the provided parameters\n- Passes the result back to Claude\n- Returns Claude\'s final response\n\nNo manual parameter extraction or result handling needed.\n\n## 3. **Multi-step Tool Workflows**\nThetoolloopmethod can handle multiple tool calls in sequence to solve complex problems. For example, calculating(a+b)*2automatically uses both addition and multiplication tools in the right order.\n\n## 4. **Easy Tool Integration**\n- Pass tools as a simple list to the [Chat](https://claudette.answer.ai/core.html#chat) constructor\n- Optionally force tool usage withtool_choiceparameter\n- Get structured data directly with [Client.structured()](https://claudette.answer.ai/core.html#client.structured)\n\n## 5. **Reduced Complexity**\nInstead of manually handling tool use messages, parameter parsing, function calls, and result formatting that the base SDK requires, Claudette abstracts all of this away while maintaining full functionality.\n\nThis makes tool use feel more like natural function calling rather than complex API orchestration.', 'type': 'text'}] - model:
claude-sonnet-4-20250514 - role:
assistant - stop_reason:
end_turn - stop_sequence:
None - type:
message - usage:
{'cache_creation_input_tokens': 0, 'cache_read_input_tokens': 9287, 'input_tokens': 241, 'output_tokens': 374, 'server_tool_use': None, 'service_tier': 'standard'}
We can see that this only used ~200 regular input tokens – the 7000+context tokens have been read from cache.
print(r.usage)
Usage(cache_creation_input_tokens=0, cache_read_input_tokens=9287, input_tokens=241, output_tokens=374, server_tool_use=None, service_tier='standard')chat.use
In: 245; Out: 597; Cache create: 0; Cache read: 18574; Total Tokens: 19416; Search: 0Tool use lets Claudeuse external tools.
We usedocments to makedefining Python functions as ergonomic as possible. Each parameter (andthe return value) should have a type, and a docments comment with thedescription of what it is. As an example we’ll write a simple functionthat adds numbers together, and will tell us when it’s being called:
defsums(a:int,# First thing to sumb:int=1# Second thing to sum)->int:# The sum of the inputs"Adds a + b."print(f"Finding the sum of{a} and{b}")returna+b
Sometimes Claude will try to add stuff up “in its head”, so we’ll use asystem prompt to ask it not to.
sp="Always use tools if math ops are needed."
We’ll get Claude to add up some long numbers:
a,b=604542,6458932pr=f"What is{a}+{b}?"pr
'What is 604542+6458932?'To use tools, pass a list of them toChat:
chat=Chat(model,sp=sp,tools=[sums])
To force Claude to always answer using a tool, settool_choice to thatfunction name. When Claude needs to use a tool, it doesn’t return theanswer, but instead returns atool_use message, which means we have tocall the named tool with the provided parameters.
r=chat(pr,tool_choice='sums')r
Finding the sum of 604542 and 6458932ToolUseBlock(id=‘toolu_01UUWNqtkMHQss345r1ir17q’, input={‘a’: 604542,‘b’: 6458932}, name=‘sums’, type=‘tool_use’)
- id:
msg_0199dXeVq11rc2veGNJVWc4k - content:
[{'id': 'toolu_01UUWNqtkMHQss345r1ir17q', 'input': {'a': 604542, 'b': 6458932}, 'name': 'sums', 'type': 'tool_use'}] - model:
claude-sonnet-4-20250514 - role:
assistant - stop_reason:
tool_use - stop_sequence:
None - type:
message - usage:
{'cache_creation_input_tokens': 0, 'cache_read_input_tokens': 0, 'input_tokens': 445, 'output_tokens': 53, 'server_tool_use': None, 'service_tier': 'standard'}
Claudette handles all that for us – we just call it again, and it allhappens automatically:
chat()604542 + 6458932 = 7,063,474
- id:
msg_014wmCxnwQpgvnqKKto3RrxA - content:
[{'citations': None, 'text': '604542 + 6458932 = 7,063,474', 'type': 'text'}] - model:
claude-sonnet-4-20250514 - role:
assistant - stop_reason:
end_turn - stop_sequence:
None - type:
message - usage:
{'cache_creation_input_tokens': 0, 'cache_read_input_tokens': 0, 'input_tokens': 527, 'output_tokens': 19, 'server_tool_use': None, 'service_tier': 'standard'}
You can see how many tokens have been used at any time by checking theuse property. Note that (as of May 2024) tool use in Claude uses alot of tokens, since it automatically adds a large system prompt.
chat.use
In: 972; Out: 72; Cache create: 0; Cache read: 0; Total Tokens: 1044; Search: 0We can do everything needed to use tools in a single step, by usingChat.toolloop.This can even call multiple tools as needed solve a problem. Forexample, let’s define a tool to handle multiplication:
defmults(a:int,# First thing to multiplyb:int=1# Second thing to multiply)->int:# The product of the inputs"Multiplies a * b."print(f"Finding the product of{a} and{b}")returna*b
Now with a single call we can calculate(a+b)*2 – by passingshow_trace we can see each response from Claude in the process:
chat=Chat(model,sp=sp,tools=[sums,mults])pr=f'Calculate ({a}+{b})*2'pr
'Calculate (604542+6458932)*2'foroinchat.toolloop(pr):display(o)
Finding the sum of 604542 and 6458932I’ll help you calculate (604542+6458932)*2. I need to first add the twonumbers, then multiply the result by 2.
- id:
msg_019DZznw7qiEM2uEEcpNTnKs - content:
[{'citations': None, 'text': "I'll help you calculate (604542+6458932)*2. I need to first add the two numbers, then multiply the result by 2.", 'type': 'text'}, {'id': 'toolu_016NZ7MtE8oWHs5BSkxMcAN7', 'input': {'a': 604542, 'b': 6458932}, 'name': 'sums', 'type': 'tool_use'}] - model:
claude-sonnet-4-20250514 - role:
assistant - stop_reason:
tool_use - stop_sequence:
None - type:
message - usage:
{'cache_creation_input_tokens': 0, 'cache_read_input_tokens': 0, 'input_tokens': 539, 'output_tokens': 105, 'server_tool_use': None, 'service_tier': 'standard'}
{'content': [ { 'content': '7063474','tool_use_id': 'toolu_016NZ7MtE8oWHs5BSkxMcAN7','type': 'tool_result'}],'role': 'user'}Finding the product of 7063474 and 2Now I’ll multiply that result by 2:
- id:
msg_01LmQiMRWAtTQz6sChqsbtMy - content:
[{'citations': None, 'text': "Now I'll multiply that result by 2:", 'type': 'text'}, {'id': 'toolu_019BQuhBzEkCWC1JMp6VtcfD', 'input': {'a': 7063474, 'b': 2}, 'name': 'mults', 'type': 'tool_use'}] - model:
claude-sonnet-4-20250514 - role:
assistant - stop_reason:
tool_use - stop_sequence:
None - type:
message - usage:
{'cache_creation_input_tokens': 0, 'cache_read_input_tokens': 0, 'input_tokens': 659, 'output_tokens': 82, 'server_tool_use': None, 'service_tier': 'standard'}
{'content': [ { 'content': '14126948','tool_use_id': 'toolu_019BQuhBzEkCWC1JMp6VtcfD','type': 'tool_result'}],'role': 'user'}The answer is14,126,948.
To break it down: - 604,542 + 6,458,932 = 7,063,474 - 7,063,474 × 2 =14,126,948
- id:
msg_0119DdeQ2goLFwGkXTXHFDsv - content:
[{'citations': None, 'text': 'The answer is **14,126,948**.\n\nTo break it down:\n- 604,542 + 6,458,932 = 7,063,474\n- 7,063,474 × 2 = 14,126,948', 'type': 'text'}] - model:
claude-sonnet-4-20250514 - role:
assistant - stop_reason:
end_turn - stop_sequence:
None - type:
message - usage:
{'cache_creation_input_tokens': 0, 'cache_read_input_tokens': 0, 'input_tokens': 756, 'output_tokens': 61, 'server_tool_use': None, 'service_tier': 'standard'}
If you just want the immediate result from a single tool, useClient.structured.
cli=Client(model)
defsums(a:int,# First thing to sumb:int=1# Second thing to sum)->int:# The sum of the inputs"Adds a + b."print(f"Finding the sum of{a} and{b}")returna+b
cli.structured("What is 604542+6458932",sums)
Finding the sum of 604542 and 6458932[7063474]This is particularly useful for getting back structured information,e.g:
classPresident:"Information about a president of the United States"def__init__(self,first:str,# first namelast:str,# last namespouse:str,# name of spouseyears_in_office:str,# format: "{start_year}-{end_year}"birthplace:str,# name of citybirth_year:int# year of birth, `0` if unknown ):assertre.match(r'\d{4}-\d{4}',years_in_office),"Invalid format: `years_in_office`"store_attr()__repr__=basic_repr('first, last, spouse, years_in_office, birthplace, birth_year')
cli.structured("Provide key information about the 3rd President of the United States",President)
[President(first='Thomas', last='Jefferson', spouse='Martha Wayles Skelton Jefferson', years_in_office='1801-1809', birthplace='Shadwell, Virginia', birth_year=1743)]Claude can handle image data as well. As everyone knows, when testingimage APIs you have to use a cute puppy.
fn=Path('samples/puppy.jpg')Image(filename=fn,width=200)
We create aChat objectas before:
chat=Chat(model)
Claudette expects images as a list of bytes, so we read in the file:
img=fn.read_bytes()
Prompts to Claudette can be lists, containing text, images, or both, eg:
chat([img,"In brief, what color flowers are in this image?"])
The flowers in this image are purple.
- id:
msg_01N2NCd5JW3gNsGysgmyMx9F - content:
[{'citations': None, 'text': 'The flowers in this image are purple.', 'type': 'text'}] - model:
claude-sonnet-4-20250514 - role:
assistant - stop_reason:
end_turn - stop_sequence:
None - type:
message - usage:
{'cache_creation_input_tokens': 0, 'cache_read_input_tokens': 0, 'input_tokens': 110, 'output_tokens': 11, 'server_tool_use': None, 'service_tier': 'standard'}
The image is included as input tokens.
chat.use
In: 110; Out: 11; Cache create: 0; Cache read: 0; Total Tokens: 121; Search: 0Alternatively, Claudette supports creating a multi-stage chat withseparate image and text prompts. For instance, you can pass just theimage as the initial prompt (in which case Claude will make some generalcomments about what it sees), and then follow up with questions inadditional prompts:
chat=Chat(model)chat(img)
What an adorable puppy! This looks like a Cavalier King Charles Spanielpuppy with the classic Blenheim coloring (chestnut and white markings).The puppy has those characteristic sweet, gentle eyes and silky coatthat the breed is known for. The setting with the purple flowers in thebackground makes for a lovely portrait - it really highlights thepuppy’s beautiful coloring and sweet expression. Cavalier King CharlesSpaniels are known for being friendly, affectionate companions. Is thisyour puppy?
- id:
msg_01Jat1obwo79eEz5JMFAF4Mh - content:
[{'citations': None, 'text': "What an adorable puppy! This looks like a Cavalier King Charles Spaniel puppy with the classic Blenheim coloring (chestnut and white markings). The puppy has those characteristic sweet, gentle eyes and silky coat that the breed is known for. The setting with the purple flowers in the background makes for a lovely portrait - it really highlights the puppy's beautiful coloring and sweet expression. Cavalier King Charles Spaniels are known for being friendly, affectionate companions. Is this your puppy?", 'type': 'text'}] - model:
claude-sonnet-4-20250514 - role:
assistant - stop_reason:
end_turn - stop_sequence:
None - type:
message - usage:
{'cache_creation_input_tokens': 0, 'cache_read_input_tokens': 0, 'input_tokens': 98, 'output_tokens': 118, 'server_tool_use': None, 'service_tier': 'standard'}
chat('What direction is the puppy facing?')
The puppy is facing toward the camera/viewer. You can see the puppy’sface straight-on, with both eyes visible and looking directly at thecamera. The puppy appears to be lying down with its head up and orientedforward, giving us a clear frontal view of its sweet face.
- id:
msg_018EqaD7EFveLCzSPbQmMMuE - content:
[{'citations': None, 'text': "The puppy is facing toward the camera/viewer. You can see the puppy's face straight-on, with both eyes visible and looking directly at the camera. The puppy appears to be lying down with its head up and oriented forward, giving us a clear frontal view of its sweet face.", 'type': 'text'}] - model:
claude-sonnet-4-20250514 - role:
assistant - stop_reason:
end_turn - stop_sequence:
None - type:
message - usage:
{'cache_creation_input_tokens': 0, 'cache_read_input_tokens': 0, 'input_tokens': 227, 'output_tokens': 65, 'server_tool_use': None, 'service_tier': 'standard'}
chat('What color is it?')
The puppy has a chestnut (reddish-brown) and white coat. The ears andpatches around the eyes are a rich chestnut or reddish-brown color,while the face has a white blaze down the center and the chest/frontappears to be white as well. This is the classic “Blenheim” colorpattern that’s common in Cavalier King Charles Spaniels - thecombination of chestnut and white markings.
- id:
msg_01HzUTvRziMrSfdEjbo1kHnh - content:
[{'citations': None, 'text': 'The puppy has a chestnut (reddish-brown) and white coat. The ears and patches around the eyes are a rich chestnut or reddish-brown color, while the face has a white blaze down the center and the chest/front appears to be white as well. This is the classic "Blenheim" color pattern that\'s common in Cavalier King Charles Spaniels - the combination of chestnut and white markings.', 'type': 'text'}] - model:
claude-sonnet-4-20250514 - role:
assistant - stop_reason:
end_turn - stop_sequence:
None - type:
message - usage:
{'cache_creation_input_tokens': 0, 'cache_read_input_tokens': 0, 'input_tokens': 300, 'output_tokens': 103, 'server_tool_use': None, 'service_tier': 'standard'}
Note that the image is passed in again for every input in the dialog, sothat number of input tokens increases quickly with this kind of chat.(For large images, using prompt caching might be a good idea.)
chat.use
In: 625; Out: 286; Cache create: 0; Cache read: 0; Total Tokens: 911; Search: 0Claude >=3.7 Sonnet and Opus have enhanced reasoning capabilitiesthroughextendedthinking.This feature allows Claude to think through complex problemsstep-by-step, making its reasoning process transparent and its finalanswers more reliable.
To enable extended thinking, simply specify the number of thinkingtokens using themaxthinktok parameter when making a call to Chat. Thethinking process will appear in a collapsible section in the response.
Some important notes about extended thinking:
- Only available with select models
- Automatically sets
temperature=1when enabled (required for thinkingto work) - Cannot be used with
prefill(these features are incompatible) - Thinking is presented in a separate collapsible block in the response
- The thinking tokens count toward your usage but help with complexreasoning
To access models that support extended thinking, you can usehas_extended_thinking_models.
has_extended_thinking_models{'claude-3-7-sonnet-20250219', 'claude-opus-4-20250514', 'claude-sonnet-4-20250514'}chat=Chat(model)
chat('Write a sentence about Python!',maxthinktok=1024)
Python is a versatile, high-level programming language known for itsreadable syntax and extensive libraries, making it popular foreverything from web development to data science and machine learning.
Thinking
The user is asking for a sentence about Python. Since they didn’tspecify, this could refer to either: 1. Python the programming language2. Python the snake
Given the context and common usage, they’re most likely referring to theprogramming language Python. I’ll write a sentence about Python theprogramming language that’s informative and concise.
- id:
msg_017EgYhUjsQxWkXN1zrRjFxK - content:
[{'signature': 'EokECkYIBBgCKkDNuftW7kYi6z6RSuzj4DNdtNRxcj486/U8U2NJHg51M+vGmQ1eN7ypz+w4/tpZCFHgWR9KFPXElnHrp3SkoWJrEgzJthIeSKqmoUbrP5YaDKGgUdib0TYhZriKcCIwDrQ2GTZ3D7zE0RVouKJLbzyRl+sQ6FQ+NwNQb5qrHw5Ylmzqxxk4Sa4GuzOEY8zVKvAC+7LfNqCd7jBjPVqaoSRmCubkKuWWeg60G39UCYm/W9VUsrDT1IHLTvOuK3KOYTQL1zqWt1XlBFj52haZIWRmjVU1w2S8EyKIJIThNRYFfT9CDuAeCYwUae8BFL4wm/MEUw+2tDNH3ei7JUvb4sk17cTrePvzpiQNtmHN8TctDBP2RgD7PpTUbjNUsvoRJFBSLLfNsd8wlvAkcph96fDV5dUJ/W3mkluG4XbTTY3ns/rlikAFLTphaoXeqM6buvm889Sep8BQdHuujHcuKWD3auTusayXE5O/9yYcWrU9qPxZ2bxF72tZ1Y65bTBYzhm9ohtB1LTy0x0XvOS76gfGZ8XaJ4vj3OMz1Cn5GSTCNbELTHHVBh5azPSCI9Qu44/ZBE2ZsFA0mtPCiP8cyhZmzAaHFnz2QaKwuTlfz5VnDPmNSNy8rqHywWlkMMA4g9+0SDZSxYJkCYBO+OUs1gNqlwwJQUyYOc1SEmpBkVQee2kYAQ==', 'thinking': "The user is asking for a sentence about Python. Since they didn't specify, this could refer to either:\n1. Python the programming language\n2. Python the snake\n\nGiven the context and common usage, they're most likely referring to the programming language Python. I'll write a sentence about Python the programming language that's informative and concise.", 'type': 'thinking'}, {'citations': None, 'text': 'Python is a versatile, high-level programming language known for its readable syntax and extensive libraries, making it popular for everything from web development to data science and machine learning.', 'type': 'text'}] - model:
claude-sonnet-4-20250514 - role:
assistant - stop_reason:
end_turn - stop_sequence:
None - type:
message - usage:
{'cache_creation_input_tokens': 0, 'cache_read_input_tokens': 0, 'input_tokens': 41, 'output_tokens': 119, 'server_tool_use': None, 'service_tier': 'standard'}
Claude supports server-side tools that run on Anthropic’sinfrastructure. The flagship example is the web search tool, whichallows Claude to search the web for up-to-date information to answerquestions.
Unlike client-side tools (where you provide functionality), server-sidetools are managed by Anthropic. Claudette makes these easy to use withhelper functions likesearch_conf().
chat=Chat(model,sp='Be concise in your responses.',tools=[search_conf()])pr='What is the current weather in San Diego?'r=chat(pr)r
Based on the search results, here’s the current weather information forSan Diego:
Today (Saturday, June 21st) has a high of 67°F12 with cloudyconditions early with partial sunshine expected later3. Winds arefrom the SSW at 10 to 15 mph4.
Tonight’s low will be around 62°F with overcast conditions and SSW windsat 10 to 15 mph5.
Temperatures are running about 4-7 degrees below normal for most areas6, making it a cooler day than typical for this time of year in SanDiego.
Air quality is currently at an unhealthy level for sensitive groups, sothose with breathing sensitivities should reduce outdoor time ifexperiencing symptoms7.
- id:
msg_01Kg3aNFF7ibUcWZxPpFNmu8 - content:
[{'id': 'srvtoolu_01YazfLE5GfK4ET2Z4rsfcuz', 'input': {'query': 'San Diego weather today'}, 'name': 'web_search', 'type': 'server_tool_use'}, {'content': [{'encrypted_content': 'EqcCCioIBBgCIiQ4ODk4YTFkYy0yMTNkLTRhNmYtOTljYi03ZTBlNTUzZDc0NWISDF5HWNC1GnRw10SRnBoMsafoy8BqdMy4chO3IjALzgdeA/d4dT1Qx7JKFu6XeXmrHYIe2lxVFl7TqZkRDnKmPpA6mnvpkwGh9eW8RJgqqgGtR4kEv8KoMeWf9VHjh1oYyscLkN5LJq00R4X3C/Cfw9oLLdIAiN9tvq9g2Rzm0Qb/IP5GcdVfiwx7w5dRfL67oaWQ5IFIXSvv9ByLW/ERFI30UKhhKFYumApVuZEIge6CL0j56OQFXAkPVENWIlSnro+9BIKgf866WWvRo0kx2d+SiX9p3ainG+Zqbl55Bq+mvyOUgVabtSEfr+oY6FQPJYYT9ad0QxYUOxgD', 'page_age': '3 days ago', 'title': '10-Day Weather Forecast for San Diego, CA - The Weather Channel | weather.com', 'type': 'web_search_result', 'url': 'https://weather.com/weather/tenday/l/San+Diego+CA?canonicalCityId=3b2b39ed755b459b725bf2a29c71d678'}, {'encrypted_content': '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', 'page_age': '3 days ago', 'title': 'San Diego, CA Weather Forecast | AccuWeather', 'type': 'web_search_result', 'url': 'https://www.accuweather.com/en/us/san-diego/92101/weather-forecast/347628'}, {'encrypted_content': 'Er0ECioIBBgCIiQ4ODk4YTFkYy0yMTNkLTRhNmYtOTljYi03ZTBlNTUzZDc0NWISDBGutrl0Yo/Ph3ytgxoMmv0PMZzhuX1bUMAaIjB8A47OiTekaB3+wTaHtqniXxv1Syc6JTwDJgaWgpy/MxfY+iOIS58xXsHOd7d/vrUqwAOQc9TMOqSb0LGZCGaGxIwiXICeBOu9KYGmqzNtUJm31yQlCGwdOFeznCgec0B2/jhLUZMpoDuoL3ayVUeBYC7IlyW4Lrh7DR8+MUOf27YxozzhkdWKDDDqCf0hN40Qn69bGemDOFejCWrTyCj8ffYa29MAKRcAvQv0TQUehsNOy0xKYzeBA2z9zjzZp9GOesvqBv5/2AxQrVwygU31bLYEeiqHqLrfeQ798HK9oDFlAiHaS/gWmpK1+0d3UA+Y5KCKipBmUxy15LkEmoG0MoG3/OEDZ7mOGuuY5RqCW4hkdT4dzm6OsKfmiLoDG/XI2HNkpcTnCd3tO0yUZdwY3lX4vSjAS2wvFxNsl7b8YbaKM/U8H3JaTVntwyh7GHWYezHYaYXNiMK05KcQMKJlP/bZx82sQkq83jl15k55Nf5NR/R/1PHi/fqzLDwPOSug5RJ8dwdduWd1SF4qcfStBaOZ4fRdTwbxJgiAC6gmxWMAGfXg29iVSNsTBYVaGk+GPrUSIFxU0x36xejO0Vaz7wHL6XPwjvXMhVrWbuf5xMXKRNW3XG3X0AEB7h40x+0MN23BmmJ9G6+JQ5Ngog6z2An4GAM=', 'page_age': '3 days ago', 'title': 'San Diego weather forecast – NBC 7 San Diego', 'type': 'web_search_result', 'url': 'https://www.nbcsandiego.com/weather/'}, {'encrypted_content': 'EpcCCioIBBgCIiQ4ODk4YTFkYy0yMTNkLTRhNmYtOTljYi03ZTBlNTUzZDc0NWISDGlljWS7qosG4mSt3BoM6gy+Gh0f2zdXJ8kAIjAL5PfnNZR7Vex2zcFoqLody/xA+Yyoob62LVGMQ4+EhXd4CKgvxQEfpQLQgVvIH3UqmgGByQGU45dvgEJrKexyCEvra2CIAoYOTUiKNt6p7dVfp8++dfq28UU2mt5h10bL8ul8y0xeBu6new/tfwFJ6+GS/Bh6p+M+p87Jy65QQ/dgMhV+M7q3EAQUZjh642YMayI4nimm2yIwbLzNRXEszsp2kdmKKhxDpO3C5wp8fWLy5UpWvimjh5WSMnAzEpMoVDqD99FavgHvaPF7GAM=', 'page_age': '3 days ago', 'title': 'Weather Forecast and Conditions for San Diego, CA - The Weather Channel | Weather.com', 'type': 'web_search_result', 'url': 'https://weather.com/weather/today/l/San+Diego+CA?canonicalCityId=3b2b39ed755b459b725bf2a29c71d678'}, {'encrypted_content': 'ErEDCioIBBgCIiQ4ODk4YTFkYy0yMTNkLTRhNmYtOTljYi03ZTBlNTUzZDc0NWISDKDodoc/BpOij6btVBoMdtlDIIQ1rjzAl3XyIjAUXhC+GWPaQwx74WpJR7Xo+cVP0RjwhWd5LPSL+skOIE8sHVqz0Ry9jmq5jGri3wcqtAJrH5qNCAGieGFHQijAS1lfA2rn0EDH/tLBmC4nKW0MGQz/NLn49FuAcJuEZrw2149zcJ88XQ18hVEhWTkZ/BNEBujb9+M+QthIUUOPf6RplEX+DThq1KIuqbR0XBh71qThLM5ZfBjcvYS4429hpEP5DJo2FP0nqr9Ps8GX/hvIik33EXc4X3x16d649qqcRFwByb1DhE+NZVTiuu4WfljWXWBs+17ezkxxWazj3E9GtLBIL98fnMoOf4p9oTI8EgWe4RjcGqEaI6DWqlGquNgkc4IeqlzVkjWP4v90HoI7oegcDKtK/n+8pNaGqyBQizgf1NglM2gRBj3cZ9kt7cDX8p1KpmXrGsOSEK3mn6RAnjlsFQ2x7UjM7l980KCVKnqeguR0ZkCsvB+KM0AputjxlU+KrBgD', 'page_age': '3 days ago', 'title': 'San Diego, CA', 'type': 'web_search_result', 'url': 'https://www.weather.gov/sgx/'}, {'encrypted_content': 'EpkCCioIBBgCIiQ4ODk4YTFkYy0yMTNkLTRhNmYtOTljYi03ZTBlNTUzZDc0NWISDLXJ+1Ii8XIJ7AwW/xoMMbTKEdT8hw2J9bdSIjBYWJur7pQQqNijCyZjeN+VSYcaZe7xE/09hGS23TOjFLdvrOhGAMVSd3e2IDGUHCEqnAG6GJZO/sDcDEeEn/sobNJbNjM9VfNoJZEg+f/lZ+KXtMJELQ2Q14ot0iqQ0qKEjDxz3OMLkAYJg3uqeVMOq5QLgz6MNANEoCU+koTqIiYGZ++8Y0tKdtVD/Xrm0QW0fFkdJcN1PVt+6fN8aDJ5+95phOw5vEmRS9FRWg6aLDIwpxaNJ6z+Wbpff8zoSGUcPZFaFIUjAAU6qnx8kRoYAw==', 'page_age': None, 'title': 'San Diego, CA Weather Forecast | KGTV | kgtv.com', 'type': 'web_search_result', 'url': 'https://www.10news.com/weather'}, {'encrypted_content': 'EpQCCioIBBgCIiQ4ODk4YTFkYy0yMTNkLTRhNmYtOTljYi03ZTBlNTUzZDc0NWISDHL0i7qnzUCM4zRRAhoMAv3yQhl4BrqFyb0nIjBsyvNyrS90lUKCO/9admV9eU8x96+nDdrodoVAe9lpT2fNstMu4pS2Aer192MKKnwqlwGnu1DfFtpu/sSeugS3SUtYxT+ulZYw+ZQwhqLMOf+UadP2PrCAEDh5CM2pF4fMHRdt9GBYTgOA/3ug6W2Ci30q5QXwdiNC/7X2KQV6QrU83m//vy92K8PO9dwqv4B0T8uCSY18O+BtHHlZrzmzPgIWm4OTP2+Blh+f3X+yRubR9JiBehxtgS/IGmdWhzv6QjIbcFy5bhNDGAM=', 'page_age': '1 week ago', 'title': 'Hourly Weather Forecast for San Diego, CA - The Weather Channel | Weather.com', 'type': 'web_search_result', 'url': 'https://weather.com/weather/hourbyhour/l/San+Diego+CA?canonicalCityId=3b2b39ed755b459b725bf2a29c71d678'}, {'encrypted_content': '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', 'page_age': None, 'title': 'San Diego, CA 10-Day Weather Forecast | Weather Underground', 'type': 'web_search_result', 'url': 'https://www.wunderground.com/forecast/us/ca/san-diego'}, {'encrypted_content': 'Ev0ECioIBBgCIiQ4ODk4YTFkYy0yMTNkLTRhNmYtOTljYi03ZTBlNTUzZDc0NWISDFqrWvXcDBaRhAEIERoMEMwkIlYRNrbpob8qIjAGpulVwN56DZ4z4+PuEB3gdYm6QZ5Qvq+6RFvOLnEGDg+mpsIvb2TL4iauDizcEsUqgAT3/Sza241GQ6OmRz38xfUdXYqE5zatMSVDZ8Pzsd11fgBJg8voUcxKfPRPQWlA8FYW8+K4vDvv5cahR9rbVN829R/VQxq7YdcMsD9D5pbk9WButOmQLwI5/MsvnKo0MJ2e6kVcI1DVTwwHxoF0AJdkXUm/9x5danZ35QmA3FIR+7AOBCgtlOmwwIO1nTB+x6+8gf8DB0Jsgv6scqI/PqYxTYH8pZUEs3sA0pXQWJIcbtbWPRqxvfr6KYTtBAKJcr4XmsOMdi4OhVxzXhed1OjB1Jvebhi7Z+CbOOEZBuL2T7inzxoNlHvd3rhuZoDzpb9IWEMx/29fjwWhy+ztWi4Fdl25QgpWokl9cjDtq+6DEkf97+5ks6oVZU1dKoKq2y6S7cT3SL30IOzpdNox9Nh9FrOZeui/aT2zD7imuB+dyx9ffHi07Ulje7R9UWwBvDzRPMP4Ilwe4nrcQWWloso80KTfIixUTmel1bPKxVdrag/2+4kD6ahHpm2cLazWqTc+GvVY5+IRb2C5Y6pve4tWPVZC584151GHbdDZB2FamZJsdBlVL5VAF7Cz2U2mukxcuFF7Vwh3lpvpuqkldp4yWf2UJVpGMOOgDMgRi9qn+fAqE9jEIKoqXRhrVnKlgAlMGpnFfxu1IvxOLQQRqCNRltm5whIy5YhZa+7bllx+NRgD', 'page_age': '3 days ago', 'title': 'San Diego, CA Weather Conditions | Weather Underground', 'type': 'web_search_result', 'url': 'https://www.wunderground.com/weather/us/ca/san-diego'}, {'encrypted_content': 'Ev8CCioIBBgCIiQ4ODk4YTFkYy0yMTNkLTRhNmYtOTljYi03ZTBlNTUzZDc0NWISDOOoeUPUoDED8O83ZhoM30uUue3UQ1WQ6At6IjD+k7S7lYoiPFc5urIX1kWyFxcLj14bmNmI9YackQTQAU27o6IGbFdwaU+40URG2xQqggLYvUzF4uC9bk9e+C5CbKLU1WAsE7Nsb3YpFYsFiwMKqPamqEVSZE/xxUGQZ9w5tbtftdchhIs0bupnPj+G3BgO+ivdO9VcHBrqJwOk+hQ+XhQp3kLRubgZ9ozPpTZDK0xhpuFh18mFwsHgi/dIH478C1yYA50B0d/qL5C4V6NdYfDYsOXL0Ce1y4L8JxlUi//BPq23m1FfJeVo0vPYKTWm0D2TGTEnLygV9ZI9/wUF5H+gDYimj/QJZW1MWWf7bUQl85I1AyroDE2h8pae6FT0VTVWWIUJiBOWr48xbjieS+LHRxP7/XhpZpI2x0zz3WLi1BYdxHH04yxnjxLcQILrOuoYAw==', 'page_age': '5 days ago', 'title': 'National Weather Service', 'type': 'web_search_result', 'url': 'https://forecast.weather.gov/zipcity.php?inputstring=San+Diego,CA/'}], 'tool_use_id': 'srvtoolu_01YazfLE5GfK4ET2Z4rsfcuz', 'type': 'web_search_tool_result'}, {'citations': None, 'text': "Based on the search results, here's the current weather information for San Diego:\n\n", 'type': 'text'}, {'citations': [{'cited_text': 'TomorrowSat 06/21 High · 67 °F · 14% Precip. ', 'encrypted_index': 'Eo8BCioIBBgCIiQ4ODk4YTFkYy0yMTNkLTRhNmYtOTljYi03ZTBlNTUzZDc0NWISDKwATF21Da6JaeprrRoMR4n2dYDzq6Grz6kOIjDubzeZ5yWRJE4JTY/En0I9Ue7hW3xNHVY1Nb651cmT84e3E/CK5IihYjOjT0ri+bMqEzkJobhLc+mcf18NFKDVD/eXWJkYBA==', 'title': 'San Diego, CA Weather Conditions | Weather Underground', 'type': 'web_search_result_location', 'url': 'https://www.wunderground.com/weather/us/ca/san-diego'}, {'cited_text': 'High 67F. ', 'encrypted_index': 'Eo8BCioIBBgCIiQ4ODk4YTFkYy0yMTNkLTRhNmYtOTljYi03ZTBlNTUzZDc0NWISDBZRJenhcEsF45RP3hoM9byW9q+/yaWr+G32IjAOpd1oMmv1j3abI8JHjvI1b5ZvEPvFR0RzxtY1jsxEyRv9IJkysuqnmbSwH3g32TgqE+VO+8ZZPNjG9foScv6WV79YDUAYBA==', 'title': 'San Diego, CA Weather Conditions | Weather Underground', 'type': 'web_search_result_location', 'url': 'https://www.wunderground.com/weather/us/ca/san-diego'}], 'text': 'Today (Saturday, June 21st) has a high of 67°F', 'type': 'text'}, {'citations': None, 'text': ' with ', 'type': 'text'}, {'citations': [{'cited_text': '/ 0.00 °in Cloudy early with partial sunshine expected late. ', 'encrypted_index': 'Eo8BCioIBBgCIiQ4ODk4YTFkYy0yMTNkLTRhNmYtOTljYi03ZTBlNTUzZDc0NWISDB4nMEZc/F7OchMulRoMGN8vERmCYSPIeM52IjBEWjKA8pyazlviIcAv3VdKXXstJzWI89Lth9GVQTgJe+aHBo6Z9RixGwe9H65I4iEqE6r+cdWvSki3A5y7liT1a2+EuPgYBA==', 'title': 'San Diego, CA Weather Conditions | Weather Underground', 'type': 'web_search_result_location', 'url': 'https://www.wunderground.com/weather/us/ca/san-diego'}], 'text': 'cloudy conditions early with partial sunshine expected later', 'type': 'text'}, {'citations': None, 'text': '. ', 'type': 'text'}, {'citations': [{'cited_text': 'Winds SSW at 10 to 15 mph. ', 'encrypted_index': 'Eo8BCioIBBgCIiQ4ODk4YTFkYy0yMTNkLTRhNmYtOTljYi03ZTBlNTUzZDc0NWISDB45Fg4fI2lZagCjPRoM44KF0iEojWBopwrHIjBhn7dgVM1Ff/cqtJ/lTjfQ/jwVGUPTMJqvlWxrNi2vlcn6nHSZw+cUefs/Ruz/GNgqE6jMHyEpfOkI5cEy1xxL1qwAZvIYBA==', 'title': 'San Diego, CA Weather Conditions | Weather Underground', 'type': 'web_search_result_location', 'url': 'https://www.wunderground.com/weather/us/ca/san-diego'}], 'text': 'Winds are from the SSW at 10 to 15 mph', 'type': 'text'}, {'citations': None, 'text': '.\n\n', 'type': 'text'}, {'citations': [{'cited_text': 'Low 62F. Winds SSW at 10 to 15 mph. ', 'encrypted_index': 'EpEBCioIBBgCIiQ4ODk4YTFkYy0yMTNkLTRhNmYtOTljYi03ZTBlNTUzZDc0NWISDGs1z0BKFApU+3H2sxoMHemxpcDkrIGd4oSRIjAWWpByOKdjFHplptGY/sqWHuZVPAxLushiCw0j+aLQ3+bpwzSikTDw6Eb075la0fYqFeOQNDFP6pV830agKs390gtIQ9hn2RgE', 'title': 'San Diego, CA Weather Conditions | Weather Underground', 'type': 'web_search_result_location', 'url': 'https://www.wunderground.com/weather/us/ca/san-diego'}], 'text': "Tonight's low will be around 62°F with overcast conditions and SSW winds at 10 to 15 mph", 'type': 'text'}, {'citations': None, 'text': '.\n\n', 'type': 'text'}, {'citations': [{'cited_text': 'Cooler today with highs around 4-7 degrees below normal for most areas, still slightly above normal in the lower deserts. ', 'encrypted_index': 'Eo8BCioIBBgCIiQ4ODk4YTFkYy0yMTNkLTRhNmYtOTljYi03ZTBlNTUzZDc0NWISDKmS4xmv51SRhiupjBoM1jB2H6k2FU08pQ3GIjAV+DJ6rRuV2b6Q7ignq8PgwpnBySIrcI0FjJyUkxWXMUqYQYSPaTtiNLaSUJi1kh4qE+SXxbI2WryAsUjDE9uQS3F/91QYBA==', 'title': 'San Diego, CA', 'type': 'web_search_result_location', 'url': 'https://www.weather.gov/sgx/'}], 'text': 'Temperatures are running about 4-7 degrees below normal for most areas', 'type': 'text'}, {'citations': None, 'text': ', making it a cooler day than typical for this time of year in San Diego.\n\n', 'type': 'text'}, {'citations': [{'cited_text': 'The air has reached a high level of pollution and is unhealthy for sensitive groups. Reduce time spent outside if you are feeling symptoms such as dif...', 'encrypted_index': 'EpEBCioIBBgCIiQ4ODk4YTFkYy0yMTNkLTRhNmYtOTljYi03ZTBlNTUzZDc0NWISDK8D4vc8KfCrlx9emxoMMLnROCL/VkErH3i/IjA/9/wpz9prNlBSXXcsTY2S+xdsPRDTNhPl7sYwMQoZ1OAvK8zbv5m0QT4Z0rVOkO8qFX/4Kq1l4tkCVlYlPmm9TE6ED9r0ABgE', 'title': 'San Diego, CA Weather Forecast | AccuWeather', 'type': 'web_search_result_location', 'url': 'https://www.accuweather.com/en/us/san-diego/92101/weather-forecast/347628'}], 'text': 'Air quality is currently at an unhealthy level for sensitive groups, so those with breathing sensitivities should reduce outdoor time if experiencing symptoms', 'type': 'text'}, {'citations': None, 'text': '.', 'type': 'text'}] - model:
claude-sonnet-4-20250514 - role:
assistant - stop_reason:
end_turn - stop_sequence:
None - type:
message - usage:
{'cache_creation_input_tokens': 0, 'cache_read_input_tokens': 0, 'input_tokens': 7302, 'output_tokens': 325, 'server_tool_use': {'web_search_requests': 1}, 'service_tier': 'standard'}
Thesearch_conf()function creates the necessary configuration for the web search tool.You can customize it with several parameters:
search_conf(max_uses=None,# Maximum number of searches Claude can performallowed_domains=None,# List of domains to search within (e.g., ['wikipedia.org'])blocked_domains=None,# List of domains to exclude (e.g., ['twitter.com'])user_location=None# Location context for search)
When Claude uses the web search tool, the response includes citationslinking to the source information. Claudette automatically formats thesecitations and provides them as footnotes in the response.
Web search usage is tracked separately from normal token usage in theusage statistics:
chat.use
In: 7302; Out: 325; Cache create: 0; Cache read: 0; Total Tokens: 7627; Search: 1Web search requests have their own pricing. As of May 2024, web searchescost $10 per 1,000 requests.
Claudette provides support for Anthropic’s special Text Editor Tool,which allows Claude to view and modify files directly. Unlike regularfunction-calling tools, the text editor tool uses a predefined schemabuilt into Claude’s model.
Important notes about the text editor tool:
- It’s schema-less - you provide a configuration but not a schema
- It uses type identifiers like “text_editor_20250124” specific toClaude models
- You must implement a dispatcher function (in Claudette, it’s
str_replace_based_edit_tool) - Different commands route through this single dispatcher function
The text editor tool allows Claude to:
- View file or directory contents
- Create new files
- Insert text at specific line numbers
- Replace text within files
fromclaudette.text_editorimporttext_editor_conf,str_replace_based_edit_toolfromtoolslm.funccallimportmk_ns# Create a chat with the text editor toolchat=Chat(model,sp='Be concise in your responses.',tools=[text_editor_conf['sonnet']],ns=mk_ns(str_replace_based_edit_tool))# Now Claude can explore filesforoinchat.toolloop('Please explain concisely what my _quarto.yml does. Use your tools, and explain before each usage what you are doing.'):ifnotisinstance(o,dict):display(o)
I’ll examine your _quarto.yml file to explain what it does. Let mestart by looking at the current directory to locate the file.
- id:
msg_01S59jijaZGLN9jq525KoDRu - content:
[{'citations': None, 'text': "I'll examine your _quarto.yml file to explain what it does. Let me start by looking at the current directory to locate the file.", 'type': 'text'}, {'id': 'toolu_01NxKxWNHFroLYxTULzFnBAp', 'input': {'command': 'view', 'path': '.'}, 'name': 'str_replace_based_edit_tool', 'type': 'tool_use'}] - model:
claude-sonnet-4-20250514 - role:
assistant - stop_reason:
tool_use - stop_sequence:
None - type:
message - usage:
{'cache_creation_input_tokens': 0, 'cache_read_input_tokens': 0, 'input_tokens': 1120, 'output_tokens': 106, 'server_tool_use': None, 'service_tier': 'standard'}
Now I can see the _quarto.yml file exists. Let me examine its contentsto understand what it configures.
- id:
msg_015w8s5yw4RBs4dXgfLx2CDS - content:
[{'citations': None, 'text': 'Now I can see the _quarto.yml file exists. Let me examine its contents to understand what it configures.', 'type': 'text'}, {'id': 'toolu_01ToUv8CSQH69Kx2ahBSwcGf', 'input': {'command': 'view', 'path': '/_Users/jhoward/aai-ws/claudette/_quarto.yml'}, 'name': 'str_replace_based_edit_tool', 'type': 'tool_use'}] - model:
claude-sonnet-4-20250514 - role:
assistant - stop_reason:
tool_use - stop_sequence:
None - type:
message - usage:
{'cache_creation_input_tokens': 0, 'cache_read_input_tokens': 0, 'input_tokens': 2738, 'output_tokens': 120, 'server_tool_use': None, 'service_tier': 'standard'}
Let me use the correct path:
- id:
msg_01Baaa1otgra5CHimvP9Ja5s - content:
[{'citations': None, 'text': 'Let me use the correct path:', 'type': 'text'}, {'id': 'toolu_01FTCbeJLRdAyfqqnq3pAQFa', 'input': {'command': 'view', 'path': '/Users/jhoward/aai-ws/claudette/_quarto.yml'}, 'name': 'str_replace_based_edit_tool', 'type': 'tool_use'}] - model:
claude-sonnet-4-20250514 - role:
assistant - stop_reason:
tool_use - stop_sequence:
None - type:
message - usage:
{'cache_creation_input_tokens': 0, 'cache_read_input_tokens': 0, 'input_tokens': 2896, 'output_tokens': 102, 'server_tool_use': None, 'service_tier': 'standard'}
Your_quarto.yml file configures a Quarto website project with thefollowing key settings:
Project Configuration: - Sets up a website project type - Includesall.txt files as resources - Configures preview server on port 3000without auto-opening browser
HTML Formatting: - Uses the “cosmo” theme with custom CSS fromstyles.css - Enables table of contents, code tools, and syntaxhighlighting - Sets a custom layout with wider body (1800px) andnarrower sidebar (180px) - Uses “arrow” highlight style with custom codeblock styling - Keeps markdown files during rendering
Website Features: - Enables social media cards (Twitter and OpenGraph) - Adds a search-enabled navbar with primary background - Uses afloating sidebar style - Links to GitHub issues via repo-actions
Metadata Sources: - Pulls additional configuration fromnbdev.ymlandsidebar.yml files
This appears to be set up for a documentation website, likely for aPython package using nbdev (given the nbdev.yml reference), with a focuson displaying code and technical content with good readability andnavigation.
- id:
msg_01Ba23FNyw6xy7KdtTVnBdk6 - content:
[{'citations': None, 'text': 'Your_quarto.ymlfile configures a Quarto website project with the following key settings:\n\n**Project Configuration:**\n- Sets up a website project type\n- Includes all.txtfiles as resources\n- Configures preview server on port 3000 without auto-opening browser\n\n**HTML Formatting:**\n- Uses the "cosmo" theme with custom CSS fromstyles.css\n- Enables table of contents, code tools, and syntax highlighting\n- Sets a custom layout with wider body (1800px) and narrower sidebar (180px)\n- Uses "arrow" highlight style with custom code block styling\n- Keeps markdown files during rendering\n\n**Website Features:**\n- Enables social media cards (Twitter and Open Graph)\n- Adds a search-enabled navbar with primary background\n- Uses a floating sidebar style\n- Links to GitHub issues via repo-actions\n\n**Metadata Sources:**\n- Pulls additional configuration fromnbdev.ymlandsidebar.ymlfiles\n\nThis appears to be set up for a documentation website, likely for a Python package using nbdev (given the nbdev.yml reference), with a focus on displaying code and technical content with good readability and navigation.', 'type': 'text'}] - model:
claude-sonnet-4-20250514 - role:
assistant - stop_reason:
end_turn - stop_sequence:
None - type:
message - usage:
{'cache_creation_input_tokens': 0, 'cache_read_input_tokens': 0, 'input_tokens': 3235, 'output_tokens': 267, 'server_tool_use': None, 'service_tier': 'standard'}
chat.use
In: 9989; Out: 595; Cache create: 0; Cache read: 0; Total Tokens: 10584; Search: 0You can also use 3rd party providers of Anthropic models, as shown here.
These are the models available through Bedrock:
models_aws['anthropic.claude-sonnet-4-20250514-v1:0', 'claude-3-5-haiku-20241022', 'claude-3-7-sonnet-20250219', 'anthropic.claude-3-opus-20240229-v1:0', 'anthropic.claude-3-5-sonnet-20241022-v2:0']To use them, callAnthropicBedrock with your access details, and passthat toClient:
fromanthropicimportAnthropicBedrock
ab=AnthropicBedrock(aws_access_key=os.environ['AWS_ACCESS_KEY'],aws_secret_key=os.environ['AWS_SECRET_KEY'],)client=Client(models_aws[-1],ab)
Now create yourChatobject passing this client to thecli parameter – and from then on,everything is identical to the previous examples.
chat=Chat(cli=client)chat("I'm Jeremy")
These are the models available through Vertex:
models_googTo use them, callAnthropicVertex with your access details, and passthat toClient:
fromanthropicimportAnthropicVerteximportgoogle.auth
# project_id = google.auth.default()[1]# gv = AnthropicVertex(project_id=project_id, region="us-east5")# client = Client(models_goog[-1], gv)
chat=Chat(cli=client)chat("I'm Jeremy")
Footnotes
https://www.wunderground.com/weather/us/ca/san-diego “TomorrowSat06/21 High · 67 °F · 14% Precip.”↩
https://www.wunderground.com/weather/us/ca/san-diego “High 67F.”↩
https://www.wunderground.com/weather/us/ca/san-diego “/ 0.00 °inCloudy early with partial sunshine expected late.”↩
https://www.wunderground.com/weather/us/ca/san-diego “Winds SSW at10 to 15 mph.”↩
https://www.wunderground.com/weather/us/ca/san-diego “Low 62F.Winds SSW at 10 to 15 mph.”↩
https://www.weather.gov/sgx/ “Cooler today with highs around 4-7degrees below normal for most areas, still slightly above normal inthe lower deserts.”↩
https://www.accuweather.com/en/us/san-diego/92101/weather-forecast/347628“The air has reached a high level of pollution and is unhealthy forsensitive groups. Reduce time spent outside if you are feelingsymptoms such as dif…”↩
About
Claudette is Claude's friend
Resources
License
Uh oh!
There was an error while loading.Please reload this page.
Stars
Watchers
Forks
Uh oh!
There was an error while loading.Please reload this page.
