MulaiMulai sekarang secara gratis

Using the tools parameter

You are developing an AI application for a real estate agency and have been asked to extract some key data from listings: house type, location, price, number of bedrooms. Use the Chat Completions endpoint with function calling to extract the information.

The message_listing message, containing the real estate listing, and function_definition, containing the function to call defined as a tool to be passed to the model, have been preloaded.

Latihan ini adalah bagian dari kursus

Developing AI Systems with the OpenAI API

Lihat Kursus

Petunjuk latihan

  • Add the preloaded message, message_listing.
  • Add the function definition, function_definition.
  • Print the response.

Latihan interaktif praktis

Cobalah latihan ini dengan menyelesaikan kode contoh berikut.

client = OpenAI(api_key="")

response= client.chat.completions.create(
    model="gpt-4o-mini",
    # Add the message
    ____,
    # Add your function definition
    ____
)

# Print the response
print(____)
Edit dan Jalankan Kode