MCPcopy Create free account
hub / github.com/SalesforceAIResearch/perfcodegen / Prompt

Class Prompt

src/prompt.py:5–491  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

3
4
5class Prompt(object):
6 def __init__(self, chat = False):
7 self.templates = {}
8 if chat:
9 self.template_file_path = "src/templates_chat.json"
10 else:
11 self.template_file_path = "src/templates.json"
12 self.example_file_path = "src/fixed_examples.json"
13
14
15 def build_templates(self, template):
16 pass
17
18 def load_templates(self, file_path = None):
19 if file_path:
20 self.template_file_path = file_path
21 self.templates = json.load(open(self.template_file_path, "r"))
22
23 def load_examples(self, file_path = None):
24 if not file_path:
25 self.example_file_path = "src/fixed_examples.json"
26 else:
27 self.example_file_path = file_path
28 self.examples = json.load(open(self.example_file_path, "r"))
29
30 def save_templates(self):
31 with open(self.template_file_path, "w", encoding = "utf-8") as f:
32 f.write(json.dumps(self.templates, sort_keys=True, indent=4, separators=(',', ': ')))
33
34 def print_templates(self):
35 for name in self.templates:
36 print(f"=============================Template Name: {name}============================")
37 for i, r in enumerate(self.templates[name]):
38 print(f"===========Round: {i}==========")
39 print("demo:")
40 print(r["demo"])
41 print("instruction:")
42 print(r["instruction"])
43
44 def round_exist(self, rd, name):
45 if name == "base":
46 return True
47 for t in self.templates[name]:
48 if t["rd"] == rd:
49 return True
50
51 if self.templates[name][-1]["repeat"] and rd > self.templates[name][-1]["rd"]:
52 return True
53
54 return False
55
56 def gen_code(self, rd, name):
57 if name == "base":
58 if rd % 2 == 0:
59 return True
60 else:
61 return False
62 for t in self.templates[name]:

Callers 3

__init__Method · 0.90
evaluate_pass_rateMethod · 0.90

Calls

no outgoing calls

Tested by

no test coverage detected