Perform calling permits Claude to work together with exterior features and instruments in a structured method. This information will stroll you thru implementing perform calling with Claude utilizing Python, full with examples and greatest practices.
Stipulations
To get began, you’ll want:
- Python 3.7+
- anthropic Python bundle
- A legitimate API key from Anthropic
Fundamental Setup
from anthropic import Anthropic
import json
# Initialize the consumer
anthropic = Anthropic(api_key='your-api-key')
Defining Capabilities
function_schema = {
"identify": "get_weather",
"description": "Get the present climate for a particular location",
"parameters": {
"sort": "object",
"properties": {
"location": {
"sort": "string",
"description": "Metropolis identify or coordinates"
},
"unit": {
"sort": "string",
"enum": ["celsius", "fahrenheit"],
"description": "Temperature unit"
}
},
"required": ["location"]
}
}
Making Perform Calls
def get_weather(location, unit="celsius"):
# It is a mock implementation however you possibly can all name your API
return {
"location": location,
"temperature": 22 if unit ==…