ciyidogan commited on
Commit
827c88f
Β·
verified Β·
1 Parent(s): 092c3de

Update prompy_engine.py

Browse files
Files changed (1) hide show
  1. prompy_engine.py +60 -61
prompy_engine.py CHANGED
@@ -1,61 +1,60 @@
1
- from log import log
2
-
3
-
4
- class PromptEngine:
5
- def __init__(self, service_config):
6
- self.service_config = service_config
7
-
8
- def build_intent_prompt(self, project_name):
9
- project = self.service_config.get_project(project_name)
10
- if not project:
11
- raise Exception(f"Project not found: {project_name}")
12
-
13
- system_prompt = self.service_config.system_prompt
14
- intent_examples = []
15
-
16
- for intent in project["intents"]:
17
- examples = intent.get("examples", [])
18
- intent_examples.append(f"Intent: {intent['name']}\nExamples:\n" + "\n".join(f"- {ex}" for ex in examples))
19
-
20
- full_prompt = f"{system_prompt}\n\nIntent Definitions:\n" + "\n\n".join(intent_examples)
21
- log("πŸ›  Built intent detection prompt.")
22
- return full_prompt
23
-
24
- def build_parameter_prompt(self, project_name, intent_name, missing_parameters):
25
- project = self.service_config.get_project(project_name)
26
- if not project:
27
- raise Exception(f"Project not found: {project_name}")
28
-
29
- intent = next((i for i in project["intents"] if i["name"] == intent_name), None)
30
- if not intent:
31
- raise Exception(f"Intent not found: {intent_name}")
32
-
33
- system_prompt = self.service_config.system_prompt
34
- prompts = []
35
-
36
- for param in intent.get("parameters", []):
37
- if param["name"] in missing_parameters:
38
- prompts.append(f"Extract the value for parameter '{param['name']}': {param['extraction_prompt']}")
39
-
40
- if not prompts:
41
- raise Exception("No extraction prompts found for missing parameters.")
42
-
43
- full_prompt = f"{system_prompt}\n\nParameter Extraction:\n" + "\n".join(prompts)
44
- log("πŸ›  Built parameter extraction prompt.")
45
- return full_prompt
46
-
47
- def build_humanization_prompt(self, project_name, intent_name):
48
- project = self.service_config.get_project(project_name)
49
- if not project:
50
- raise Exception(f"Project not found: {project_name}")
51
-
52
- intent = next((i for i in project["intents"] if i["name"] == intent_name), None)
53
- if not intent:
54
- raise Exception(f"Intent not found: {intent_name}")
55
-
56
- system_prompt = self.service_config.system_prompt
57
- humanization_instruction = intent.get("humanization_prompt", "")
58
-
59
- full_prompt = f"{system_prompt}\n\nHumanization Instruction:\n{humanization_instruction}"
60
- log("πŸ›  Built humanization prompt.")
61
- return full_prompt
 
1
+ from utils import log
2
+
3
+ class PromptEngine:
4
+ def __init__(self, service_config):
5
+ self.service_config = service_config
6
+
7
+ def build_intent_prompt(self, project_name):
8
+ project = self.service_config.get_project(project_name)
9
+ if not project:
10
+ raise Exception(f"Project not found: {project_name}")
11
+
12
+ system_prompt = self.service_config.system_prompt
13
+ intent_examples = []
14
+
15
+ for intent in project["intents"]:
16
+ examples = intent.get("examples", [])
17
+ intent_examples.append(f"Intent: {intent['name']}\nExamples:\n" + "\n".join(f"- {ex}" for ex in examples))
18
+
19
+ full_prompt = f"{system_prompt}\n\nIntent Definitions:\n" + "\n\n".join(intent_examples)
20
+ log("πŸ›  Built intent detection prompt.")
21
+ return full_prompt
22
+
23
+ def build_parameter_prompt(self, project_name, intent_name, missing_parameters):
24
+ project = self.service_config.get_project(project_name)
25
+ if not project:
26
+ raise Exception(f"Project not found: {project_name}")
27
+
28
+ intent = next((i for i in project["intents"] if i["name"] == intent_name), None)
29
+ if not intent:
30
+ raise Exception(f"Intent not found: {intent_name}")
31
+
32
+ system_prompt = self.service_config.system_prompt
33
+ prompts = []
34
+
35
+ for param in intent.get("parameters", []):
36
+ if param["name"] in missing_parameters:
37
+ prompts.append(f"Extract the value for parameter '{param['name']}': {param['extraction_prompt']}")
38
+
39
+ if not prompts:
40
+ raise Exception("No extraction prompts found for missing parameters.")
41
+
42
+ full_prompt = f"{system_prompt}\n\nParameter Extraction:\n" + "\n".join(prompts)
43
+ log("πŸ›  Built parameter extraction prompt.")
44
+ return full_prompt
45
+
46
+ def build_humanization_prompt(self, project_name, intent_name):
47
+ project = self.service_config.get_project(project_name)
48
+ if not project:
49
+ raise Exception(f"Project not found: {project_name}")
50
+
51
+ intent = next((i for i in project["intents"] if i["name"] == intent_name), None)
52
+ if not intent:
53
+ raise Exception(f"Intent not found: {intent_name}")
54
+
55
+ system_prompt = self.service_config.system_prompt
56
+ humanization_instruction = intent.get("humanization_prompt", "")
57
+
58
+ full_prompt = f"{system_prompt}\n\nHumanization Instruction:\n{humanization_instruction}"
59
+ log("πŸ›  Built humanization prompt.")
60
+ return full_prompt