
#  Categorizing companies

```
Exercise ID 1578134
```

##  Assignment 

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.

##  Pre exercise code 

```
import openai
```



##  Instructions 

- 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.



```
# Set your API key
openai.api_key = "____"

# Create a request to the Completion endpoint
response = openai.____.____(
  model="gpt-3.5-turbo-instruct",
  prompt=____,
  max_tokens=100,
  temperature=0.5
)

print(response['choices'][0]['text'])
```

##  Hints 

- In your first prompt, you'll need to instruct the model to categorize the companies and provide the company names.
- In your second prompt, adjust the wording so that you provide the model with the four categories it should use: `Tech`, `Energy`, `Luxury Goods`, or `Investment`.



##  Solution 

```
# Set your API key
openai.api_key = "<OPENAI_API_TOKEN>"

# Create a request to the Completion endpoint
response = openai.Completion.create(
 model="gpt-3.5-turbo-instruct",
 prompt="Categorize the following list of companies as either Tech, Energy, Luxury Goods, or Investment: Apple, Microsoft, Saudi Aramco, Alphabet, Amazon, Berkshire Hathaway, NVIDIA, Meta, Tesla, LVMH",
 max_tokens=100,
 temperature=0.5
)

print(response['choices'][0]['text'])
```


