Get startedGet started for free

Avoiding inconsistent responses

The team you were working with on the previous project is enthusiastic about the reply generator and asks you if more reviews can be processed. However, some reviews have been mixed up with other documents, and you're being asked not to return responses if the text doesn't contain a review, or relevant information. For example, the review you're considering now doesn't contain a product name, and so there should be no product name being returned.

In this exercise, the get_response() function, and messages and function_definition variables have been preloaded. The messages already contain the user's review, and function_definition contains the two functions: one asking to extract structured data, and one asking to generate a reply.

This exercise is part of the course

Developing AI Systems with the OpenAI API

View Course

Exercise instructions

  • Modify the messages to ask the model not to assume any values for the responses.

Hands-on interactive exercise

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

client = OpenAI(api_key="")

# Modify the messages
____

response = get_response(messages, function_definition)

print(response)
Edit and Run Code