-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathopenAI.py
More file actions
20 lines (16 loc) · 690 Bytes
/
openAI.py
File metadata and controls
20 lines (16 loc) · 690 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
import openai
from sshhhh import OPENAI_API_KEY
openai.api_key = OPENAI_API_KEY
def chat_with_gpt(prompt, file=True):
response = openai.chat.completions.create(
model="gpt-3.5-turbo",
messages=[{'role': "user", "content": prompt}]
)
if file: return save_to_file(response.choices[0].message.content.strip(), prompt)
else: return response.choices[0].message.content.strip()
def save_to_file(r, prompt):
reply = f"OpenAI response for prompt: {prompt.capitalize()}\n" + "*" * 25 + "\n\n"
reply += r
with open(fr"assets\OpenAI\{prompt}.txt", mode='w') as file:
file.write(reply)
return fr"assets\OpenAI\{prompt}.txt"