Remember to add your dotenv #1071
sigterm9kill
started this conversation in
Ideas
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Trivial, but creating a simple venv with py3.9, including the instructions for new users to import both os and dotenv may be helpful.
Updated example, please feel free to use (this assumes .env in same dir).
import os
from dotenv import load_dotenv
from openai import OpenAI
load_dotenv()
api_key = os.getenv('OPENAI_API_KEY')
client = OpenAI(api_key=api_key)
response = client.chat.completions.create(
model="gpt-3.5-turbo",
messages=[
{"role": "system", "content": "You are a helpful assistant."},
{"role": "user", "content": "Who won the world series in 2020?"},
{"role": "assistant", "content": "The Los Angeles Dodgers won the World Series in 2020."},
{"role": "user", "content": "Where was it played?"}
]
)
Excuse the bad indents on save.
My 2 cents... :)
Beta Was this translation helpful? Give feedback.
All reactions