Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update README #1

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 12 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -133,21 +133,23 @@ Now open up the `ai.py` file and paste in the following code:

```python
import os
import openai
from openai import OpenAI
from dotenv import load_dotenv, find_dotenv

_ = load_dotenv(find_dotenv())

openai.api_key = os.environ["OPENAI_API_KEY"]
client = OpenAI(
api_key=os.environ['OPENAI_API_KEY']
)

messages = [{"role": "user", "content": "What is the capital of New York?"}]

try:
response = openai.ChatCompletion.create(
response = client.chat.completions.create(
model="gpt-3.5-turbo",
messages=messages,
temperature=0,
)

print(response.choices[0].message["content"])
except Exception as e:
print(e)
Expand All @@ -163,12 +165,16 @@ pipenv shell
python ai.py
```

This should give the following output:
There is no longer free tier access to the OpenAI API so you will receive the following message:

```bash
The capital of New York is Albany.
Error code: 429 - {'error': {'message': 'You exceeded your current quota, please check your plan and billing details. For more information on this error, read the docs: https://platform.openai.com/docs/guides/error-codes/api-errors.', 'type': 'insufficient_quota', 'param': None, 'code': 'insufficient_quota'}}
```
If your account had sufficient tokens for this request, this would give the following output:

```bash
The capital of New York is Albany.
```
Now you have a working environment for using the OpenAI API! We will explore how
to use this API in the next lesson.

Expand All @@ -189,9 +195,6 @@ with the 4k context shows the following pricing:
[This video on tokenization](https://youtu.be/sXbDXE_uD2s) will help you
understand how language models parse text.

Your free trial should give you enough token allowance to explore the API and
make a few hundred requests.

If you decide to add your credit card for a usage based account, make sure to
**also set up usage limits to avoid racking up unforeseen charges**. Visit the
[Usage Limits page](https://platform.openai.com/account/billing/limits) and add
Expand Down