-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbox.py
More file actions
36 lines (29 loc) · 1.01 KB
/
Copy pathbox.py
File metadata and controls
36 lines (29 loc) · 1.01 KB
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
32
33
34
35
36
from openai import OpenAI
SEPARATOR = "\n--- RESPONSE ---\n"
# Read the contents of the playground
with open("playground.txt", "r", encoding="utf-8") as f:
contents = f.read()
# Only use the text before the separator as the user's prompt
prompt = contents.split(SEPARATOR)[0].strip()
# If the file is empty, notify the user
if not prompt:
print("Please write something in the playground.")
else:
client = OpenAI()
completion = client.chat.completions.create(
model="gpt-5-mini",
messages=[
{
"role": "system",
"content": "You are a helpful assistant. Respond clearly and concisely."
},
{
"role": "user",
"content": prompt
}
]
)
response_text = completion.choices[0].message.content.strip()
# Rewrite the file with the prompt and response separated
with open("playground.txt", "w", encoding="utf-8") as f:
f.write(prompt + SEPARATOR + response_text)