Membangun Definisi Tool OpenAI
Anda telah membuat fungsi convert_timezone() yang menggunakan OpenTimezone API untuk mengonversi tanggal-waktu antar zona waktu. Sekarang Anda perlu membuat definisi tool dalam format OpenAI agar LLM memahami cara menggunakan fungsi ini. Definisi tool berfungsi sebagai panduan untuk model, yang menjelaskan tujuan fungsi, parameter, dan persyaratannya.
Latihan ini merupakan bagian dari kursus
Bekerja dengan OpenAI Responses API
Instruksi latihan
- Definisikan tool bertipe
"function"bernama"convert_timezone". - Buat definisi untuk masing-masing dari tiga parameter fungsi:
"date_time","from_timezone", dan"to_timezone". - Pastikan ketiga parameter tersebut ditandai sebagai wajib oleh tool.
Latihan interaktif langsung praktik
Cobalah latihan ini dengan melengkapi kode contoh ini.
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
}
}
]