AnthropicがFunctionCallingをBeta版として公開したので試してみた
https://docs.anthropic.com/claude/docs/tool-use
import anthropic
client = anthropic.Anthropic()
response = client.beta.tools.messages.create(
model="claude-3-opus-20240229",
max_tokens=1024,
tools=[
{
"name": "get_location",
"description": "Get the current user location based on their IP address. This tool has no parameters or arguments.",
"input_schema": {
"type": "object",
"properties": {}
}
},
{
"name": "get_weather",
"description": "Get the current weather in a given location",
"input_schema": {
"type": "object",
"properties": {
"location": {
"type": "string",
"description": "The city and state, e.g. San Francisco, CA"
},
"unit": {
"type": "string",
"enum": ["celsius", "fahrenheit"],
"description": "The unit of temperature, either 'celsius' or 'fahrenheit'"
}
},
"required": ["location"]
}
}
],
messages=[{
"role": "user",
"content": "What's the weather like where I am?"
}]
)
print(response)
API_KEYを環境変数に設定しておく(ご自身のKEYをおつかいください)
export ANTHROPIC_API_KEY=sk-ant-api03-XXXXXX
が、結果。。
anthropic.InternalServerError: Error code: 529 -
{'type': 'error', 'error': {'type': 'overloaded_error', 'message': 'Overloaded'}}
みんな使いまくっているの繋がらないー
繋がったら続きを書く。。