1. Learn
  2. /
  3. Courses
  4. /
  5. Working with the OpenAI API

Exercise

Categorizing companies

In this exercise, you'll use a Completions model to categorize different companies. At first, you won't specify the categories to see how the model categorizes them. Then, you'll specify the categories in the prompt to ensure they are categorized in a desirable and predictable way.

The openai package has been pre-loaded for you.

Instructions

100 XP
  • Assign your API key to openai.api_key.
  • Create a request to the Completion endpoint to categorize the following companies: Apple, Microsoft, Saudi Aramco, Alphabet, Amazon, Berkshire Hathaway, NVIDIA, Meta, Tesla, and LVMH; run the code to see the response.
  • Alter the prompt to specify the four categories that the companies should be classified into, Tech, Energy, Luxury Goods, or Investment, and re-run the code.