Zack Saadioui
8/22/2024
1
2
bash
pip install openai
1
chatgpt_example.py
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
import openai # Initialize your API key o = openai.Client(api_key='your-api-key') # Define a question or prompt prompt = "What is machine learning?" # Call the API response = o.Completion.create( engine='text-davinci-003', prompt=prompt, max_tokens=100 ) # Print the response txt = response.choices[0].text.strip() print(txt)
1
'your-api-key'
1
prompt
1
openai.Completion.create()
1
prompt
1
max_tokens
1
text-davinci-003
1
gpt-3.5-turbo
1
2
3
4
5
6
python
try:
# API call
don
except Exception as e:
print(f"An error occurred: {e}")
Copyright © Arsturn 2024