Get startedGet started for free

Building the OpenAI Tool Definition

You've created the convert_timezone() function that uses the OpenTimezone API to convert datetimes between timezones. Now you need to create a tool definition in OpenAI's format so the LLM can understand how to use this function. The tool definition acts as a manual for the model, describing the function's purpose, parameters, and requirements.

This exercise is part of the course

Working with the OpenAI Responses API

View Course

Exercise instructions

  • Define a "function" type tool called "convert_timezone".
  • Create definitions for each of the function's three parameters: "date_time", "from_timezone", and "to_timezone".
  • Ensure that all three of the parameters are marked as required by the tool.

Hands-on interactive exercise

Have a go at this exercise by completing this sample code.

tools = [
    {
        # Define a function tool called convert_timezone
        "type": "____",
        "name": "____",
        "description": "Convert a datetime from one timezone to another using the OpenTimezone API.",
        "parameters": {
            "type": "object",
            # Define the parameter names, types, and descriptions
            "properties": {
                "____": {
                    "type": "____",
                    "description": "The datetime string in ISO format (e.g., '2025-01-20T14:30:00')"
                },
                "____": {
                    "type": "____",
                    "description": "The source timezone (e.g., 'America/New_York', 'Asia/Tokyo')"
                },
                "____": {
                    "type": "____",
                    "description": "The target timezone (e.g., 'Europe/London', 'Australia/Sydney')"
                }
            },
            # Ensure that all three parameters are required
            "____": ["date_time", "from_timezone", "to_timezone"],
            "additionalProperties": False
        }
    }
]
Edit and Run Code