Last active
May 29, 2025 20:53
-
-
Save eLafo/daf0e2791b55c8eae11e76f03bdeb570 to your computer and use it in GitHub Desktop.
Function calling examples
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"model": "claude-sonnet-4-20250514", | |
"max_tokens": 1024, | |
"tools": [ | |
{ | |
"name": "get_weather", | |
"description": "Obtiene información meteorológica actual de una ciudad", | |
"input_schema": { | |
"type": "object", | |
"properties": { | |
"location": { | |
"type": "string", | |
"description": "La ciudad para consultar el clima, ej: Madrid, España" | |
}, | |
"unit": { | |
"type": "string", | |
"enum": [ | |
"celsius", | |
"fahrenheit" | |
], | |
"description": "Unidad de temperatura", | |
"default": "celsius" | |
} | |
}, | |
"required": [ | |
"location" | |
] | |
} | |
} | |
], | |
"messages": [ | |
{ | |
"role": "system", | |
"content": "Eres un asistente útil que puede acceder a información meteorológica actualizada. Usa las herramientas disponibles para proporcionar información precisa y actual." | |
}, | |
{ | |
"role": "user", | |
"content": "¿Cuál es el tiempo actual en Madrid?" | |
} | |
] | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"id": "msg_01Aq9w938a90dw8q", | |
"type": "message", | |
"role": "assistant", | |
"model": "claude-sonnet-4-20250514", | |
"content": [ | |
{ | |
"type": "text", | |
"text": "Te ayudo a consultar el tiempo actual en Madrid. Voy a usar la función meteorológica para obtener información actualizada." | |
}, | |
{ | |
"type": "tool_use", | |
"id": "toolu_01A09q90qw90lq917835lq9", | |
"name": "get_weather", | |
"input": { | |
"location": "Madrid, España", | |
"unit": "celsius" | |
} | |
} | |
], | |
"stop_reason": "tool_use", | |
"stop_sequence": null, | |
"usage": { | |
"input_tokens": 385, | |
"output_tokens": 78 | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
POST /weather {"location": "Madrid", "unit": "celsius"} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"location": "Madrid, España", | |
"temperature": 22, | |
"condition": "sunny", | |
"humidity": 65, | |
"wind_speed": 12, | |
"wind_direction": "NW", | |
"timestamp": "2025-05-29T14:30:00Z", | |
"description": "Cielo despejado con sol brillante", | |
"feels_like": 24, | |
"pressure": 1013, | |
"visibility": 10, | |
"uv_index": 6 | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"tools": [ | |
{ | |
"name": "get_weather", | |
"description": "Obtiene información meteorológica actual de una ciudad", | |
"input_schema": { | |
"type": "object", | |
"properties": { | |
"location": { | |
"type": "string", | |
"description": "La ciudad para consultar el clima, ej: Madrid, España" | |
}, | |
"unit": { | |
"type": "string", | |
"enum": ["celsius", "fahrenheit"], | |
"description": "Unidad de temperatura", | |
"default": "celsius" | |
} | |
}, | |
"required": ["location"] | |
} | |
} | |
], | |
"messages": [ | |
{ | |
"role": "system", | |
"content": "Eres un asistente útil que puede acceder a información meteorológica actualizada. Usa las herramientas disponibles para proporcionar información precisa y actual." | |
}, | |
{ | |
"role": "user", | |
"content": "¿Cuál es el tiempo actual en Madrid?" | |
}, | |
{ | |
"role": "assistant", | |
"content": [ | |
{ | |
"type": "text", | |
"text": "Te ayudo a consultar el tiempo actual en Madrid. Voy a usar la función meteorológica para obtener información actualizada." | |
}, | |
{ | |
"type": "tool_use", | |
"id": "toolu_01A09q90qw90lq917835lq9", | |
"name": "get_weather", | |
"input": { | |
"location": "Madrid, España", | |
"unit": "celsius" | |
} | |
} | |
] | |
}, | |
{ | |
"role": "user", | |
"content": [ | |
{ | |
"type": "tool_result", | |
"tool_use_id": "toolu_01A09q90qw90lq917835lq9", | |
"content": "{\"location\": \"Madrid, España\", \"temperature\": 22, \"condition\": \"sunny\", \"humidity\": 65, \"wind_speed\": 12, \"wind_direction\": \"NW\", \"timestamp\": \"2025-05-29T14:30:00Z\", \"description\": \"Cielo despejado con sol brillante\"}" | |
} | |
] | |
} | |
] | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"id": "msg_02Bq8x847b81ex9r", | |
"type": "message", | |
"role": "assistant", | |
"model": "claude-sonnet-4-20250514", | |
"content": [ | |
{ | |
"type": "text", | |
"text": "En Madrid hace actualmente 22°C con cielo despejado y sol brillante. Las condiciones son excelentes con una humedad del 65% y viento del noroeste a 12 km/h. ¡Un día perfecto para salir y disfrutar del buen tiempo!" | |
} | |
], | |
"stop_reason": "end_turn", | |
"stop_sequence": null, | |
"usage": { | |
"input_tokens": 542, | |
"output_tokens": 48 | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment