MulaiMulai sekarang secara gratis

Parallel function calling

After extracting the data from customers' reviews for the marketing team, the company you're working for asks you if there's a way to generate a response to the customer that they can post on their review platform. You decide to use parallel function calling to apply both functions and generate data as well as the responses. You use a function named reply_to_review and ask to return the review reply as a reply property.

In this exercise, the get_response() function, messages and function_definition variable have been preloaded. The messages already contain the user's review, and function_definition contains the function asking to extract structured data.

Latihan ini adalah bagian dari kursus

Developing AI Systems with the OpenAI API

Lihat Kursus

Petunjuk latihan

  • Append to the function definition to return the additional message responding to the customer review: the function should have name, description and parameters specified, and the parameters should be type and properties.
  • Print the response.

Latihan interaktif praktis

Cobalah latihan ini dengan menyelesaikan kode contoh berikut.

client = OpenAI(api_key="")

# Append the second function
function_definition.append({'type': 'function', 'function':{'name': ____, ____, ____: {'type': ____, 'properties': {'reply': {____}}}}})

response = get_response(messages, function_definition)

# Print the response
____
Edit dan Jalankan Kode