-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAI TERMINAL.py
More file actions
31 lines (26 loc) · 970 Bytes
/
AI TERMINAL.py
File metadata and controls
31 lines (26 loc) · 970 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
import os
import openai
# Clear the console
if os.name == 'nt':
os.system('cls')
else:
os.system('clear')
# Get user input
message = "hello"
m2 = input("Please enter your name: ")
print(f"{message}, {m2}")
print("I am a Basic copilot and I am learning to code in Python")
m3 = input("So tell me what's on your mind 'Today'? ")
# Set up OpenAI API key from environment variable for security
openai.api_key = os.getenv("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")
# Optionally, use try/except for error handling
try:
# Using text-davinci-003 completion
response = openai.Completion.create(
engine="text-davinci-003",
prompt=m3,
max_tokens=150
)
print("ChatGPT response: ", response.choices[0].text.strip())
except Exception as e:
print("An error occurred:", e)