-
Notifications
You must be signed in to change notification settings - Fork 0
/
PromptBuilder.py
35 lines (24 loc) · 1.28 KB
/
PromptBuilder.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
functionDescriptionPlaceholder = "<functionDescription>"
inputParametersPlaceholder = "<inputParameters>"
outputParametersPlaceholder = "<outputParameters>"
languagePlaceholder = "<LANGUAGE>"
promptFileName = "prompt.txt"
class PromptBuilder:
def __init__(self,language,inputParameters,outputParameters,functionDescription = ""):
prompt = ""
with open(promptFileName,"r") as f:
prompt = f.read()
prompt = prompt.replace(languagePlaceholder,language)
prompt = prompt.replace(functionDescriptionPlaceholder,functionDescription)
prompt = prompt.replace(inputParametersPlaceholder ,inputParameters)
prompt = prompt.replace(outputParametersPlaceholder,outputParameters)
self.init_prompt = prompt
def get_initial_prompt(self):
return self.init_prompt
def get_debug_prompt(self,output):
# with open(filename, "r") as f:
# file_content = f.read()
debug_prompt = f"Code generated following output: ```{output}```\n"+\
"If output is result of bug, or unexpected exception, provide fixed code in new JSON.\n"+\
f"If output matches expected pattern: `{self.outputParameters}` then provide answer `CODE IS CORRECT`"
return debug_prompt