forked from Josh-XT/AGiXT
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCustomPrompt.py
45 lines (38 loc) · 1.62 KB
/
CustomPrompt.py
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
37
38
39
40
41
42
43
44
45
import os
class CustomPrompt:
def add_prompt(self, prompt_name, prompt):
# if prompts folder does not exist, create it
if not os.path.exists("prompts"):
os.mkdir("prompts")
# if prompt file does not exist, create it
if not os.path.exists(os.path.join("prompts", f"{prompt_name}.txt")):
with open(os.path.join("prompts", f"{prompt_name}.txt"), "w") as f:
f.write(prompt)
else:
raise Exception("Prompt already exists")
def get_prompt(self, prompt_name, model="default"):
try:
with open(f"model-prompts/{model}/{prompt_name}.txt", "r") as f:
return f.read()
except:
try:
with open(os.path.join("prompts", f"{prompt_name}.txt"), "r") as f:
prompt = f.read()
return prompt
except:
return ""
def get_prompts(self):
# Get all files in prompts folder that end in .txt and replace .txt with empty string
prompts = []
for file in os.listdir("prompts"):
if file.endswith(".txt"):
prompts.append(file.replace(".txt", ""))
return prompts
def delete_prompt(self, prompt_name):
os.remove(os.path.join("prompts", f"{prompt_name}.txt"))
def update_prompt(self, prompt_name, prompt):
with open(os.path.join("prompts", f"{prompt_name}.txt"), "w") as f:
f.write(prompt)
def get_model_prompt(self, prompt_name, model="default"):
with open(f"model-prompts/{model}/{prompt_name}.txt", "r") as f:
return f.read()