from anthropic import AnthropicVertex
client = AnthropicVertex()
# Replace placeholders like {{AVAILABLE_FUNCTIONS}} with real values,
# because the SDK does not support variables.
message = client.messages.create(
model="claude-3-5-sonnet-v2@20241022",
max_tokens=1000,
temperature=0,
messages=[
{
"role": "user",
"content": [
{
"type": "text",
"text": "\n\n\nWhat is the weather in Las Vegas \n\n\nget_weather\n\n\nThe weather in Las Vegas is 30 grade celsius, dry, and sunny very low possibilities of rain.\n\n\n\n\n"
},
{
"type": "text",
"text": "You are an AI assistant designed to help users obtain information about time and stock prices. Your primary goal is to interpret the user's request and use the provided functions to retrieve the requested information.\n\nHere are the functions available to you:\n\n\n{{AVAILABLE_FUNCTIONS}}\n\n\nTo use these functions, output a function call in the format: function_name(argument1=\"value1\", argument2=\"value2\"). You will receive a in response, which you can use to answer the user's request.\n\nGuidelines for handling requests:\n1. For time-related requests:\n - Use the get_current_time function with the appropriate timezone.\n - If no timezone is specified, use \"UTC\" as the default.\n\n2. For stock price requests:\n - First use the get_ticker_symbol function to obtain the stock symbol.\n - Then use the get_current_stock_price function with the obtained symbol.\n\n3. If the user's request is unclear or lacks necessary information:\n - Ask for clarification before making any function calls.\n\n4. If the request cannot be fulfilled using the available functions:\n - Politely inform the user that you cannot provide the requested information.\n\nError handling:\n- If a function call results in an error, explain the issue to the user and suggest alternatives if possible.\n- For TickerNotFound errors, try alternative company name variations or ask the user for clarification.\n\nAlways provide your final response within tags. Include both the requested information and a brief explanation of how you obtained it.\n\nNow, please process the following user request:\n\n\n{{USER_REQUEST}}\n"
}
]
},
{
"role": "assistant",
"content": [
{
"type": "text",
"text": "I'll help you get the weather information for Panama. Let me use the get_weather function to check the current weather conditions."
},
{
"type": "tool_use",
"name": "get_weather",
"id": "toolu_01XcMqgP8U4GLxgAEyRGQoB4",
"input": {
"location": "Panama City, Panama"
}
}
]
},
{
"role": "user",
"content": [
{
"type": "tool_result",
"tool_use_id": "toolu_01XcMqgP8U4GLxgAEyRGQoB4",
"content": ""
}
]
},
{
"role": "assistant",
"content": [
{
"type": "text",
"text": "I've requested the weather information for Panama City, Panama. However, I notice that the function call didn't return any specific weather data. This could be due to technical limitations or connectivity issues with the weather service.\n\nTo get more accurate weather information, I would recommend:\n1. Specifying a particular city in Panama (e.g., \"Panama City\")\n2. Trying again in a few moments\n3. Using an alternative weather service\n\nWould you like to try again with a more specific location in Panama?"
}
]
},
{
"role": "user",
"content": [
{
"type": "text",
"text": "give me the weather in las vegas\n"
}
]
}
]
)
print(message.content)