Spaces:
Building
Building
File size: 2,509 Bytes
827c88f |
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 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 |
from utils import log
class PromptEngine:
def __init__(self, service_config):
self.service_config = service_config
def build_intent_prompt(self, project_name):
project = self.service_config.get_project(project_name)
if not project:
raise Exception(f"Project not found: {project_name}")
system_prompt = self.service_config.system_prompt
intent_examples = []
for intent in project["intents"]:
examples = intent.get("examples", [])
intent_examples.append(f"Intent: {intent['name']}\nExamples:\n" + "\n".join(f"- {ex}" for ex in examples))
full_prompt = f"{system_prompt}\n\nIntent Definitions:\n" + "\n\n".join(intent_examples)
log("π Built intent detection prompt.")
return full_prompt
def build_parameter_prompt(self, project_name, intent_name, missing_parameters):
project = self.service_config.get_project(project_name)
if not project:
raise Exception(f"Project not found: {project_name}")
intent = next((i for i in project["intents"] if i["name"] == intent_name), None)
if not intent:
raise Exception(f"Intent not found: {intent_name}")
system_prompt = self.service_config.system_prompt
prompts = []
for param in intent.get("parameters", []):
if param["name"] in missing_parameters:
prompts.append(f"Extract the value for parameter '{param['name']}': {param['extraction_prompt']}")
if not prompts:
raise Exception("No extraction prompts found for missing parameters.")
full_prompt = f"{system_prompt}\n\nParameter Extraction:\n" + "\n".join(prompts)
log("π Built parameter extraction prompt.")
return full_prompt
def build_humanization_prompt(self, project_name, intent_name):
project = self.service_config.get_project(project_name)
if not project:
raise Exception(f"Project not found: {project_name}")
intent = next((i for i in project["intents"] if i["name"] == intent_name), None)
if not intent:
raise Exception(f"Intent not found: {intent_name}")
system_prompt = self.service_config.system_prompt
humanization_instruction = intent.get("humanization_prompt", "")
full_prompt = f"{system_prompt}\n\nHumanization Instruction:\n{humanization_instruction}"
log("π Built humanization prompt.")
return full_prompt
|