Anthropic Claude#
In this notebook we will prompt the LLM Claude from anthropic.
import anthropic
def prompt_claude(message:str, model="claude-3-5-sonnet-20240620"):
"""
A prompt helper function that sends a message to anthropic
and returns only the text response.
Example models: claude-3-5-sonnet-20240620 or claude-3-opus-20240229
"""
from anthropic import Anthropic
# convert message in the right format if necessary
if isinstance(message, str):
message = [{"role": "user", "content": message}]
# setup connection to the LLM
client = Anthropic()
message = client.messages.create(
max_tokens=4096,
messages=message,
model=model,
)
# extract answer
return message.content[0].text
prompt_claude("What is the capital of France?")
'The capital of France is Paris.'
Listing available models#
client = anthropic.Anthropic()
models = client.models.list().data
for m in models:
print(m.id)
claude-3-7-sonnet-20250219
claude-3-5-sonnet-20241022
claude-3-5-haiku-20241022
claude-3-5-sonnet-20240620
claude-3-haiku-20240307
claude-3-opus-20240229
claude-3-sonnet-20240229
claude-2.1
claude-2.0