Hi and welcome to dev forum @manigault71
The step 3 is simply asking to create a new file in a code editor, paste the code that’s provided, I cannot find any mention of file = open(‘openai-test.py’, ‘w’)
there.
Step 3: Sending your first API request
After you have Python configured and an API key setup, the final step is to send a request to the OpenAI API using the Python library. To do this, create a file named
openai-test.py
using th terminal or an IDE.Inside the file, copy and paste one of the examples below:
ChatCompletions
from openai import OpenAI client = OpenAI() completion = client.chat.completions.create( model="gpt-3.5-turbo", messages=[ {"role": "system", "content": "You are a poetic assistant, skilled in explaining complex programming concepts with creative flair."}, {"role": "user", "content": "Compose a poem that explains the concept of recursion in programming."} ] ) print(completion.choices[0].message)
To run the code, enter
python openai-test.py
into the terminal / command line.The Chat Completions example highlights just one area of strength for our models: creative ability. Explaining recursion (the programming topic) in a well formatted poem is something both the best developers and best poets would struggle with. In this case,
gpt-3.5-turbo
does it effortlessly.