Spaces:
Building
Building
Update prompt_builder.py
Browse files- prompt_builder.py +13 -11
prompt_builder.py
CHANGED
@@ -8,7 +8,8 @@ from datetime import datetime
|
|
8 |
|
9 |
|
10 |
def log(msg: str) -> None:
|
11 |
-
|
|
|
12 |
|
13 |
|
14 |
# βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
|
@@ -17,17 +18,18 @@ def log(msg: str) -> None:
|
|
17 |
def build_intent_prompt(general_prompt: str,
|
18 |
conversation: List[Dict[str, str]],
|
19 |
user_input: str,
|
20 |
-
intents: List
|
21 |
# === INTENT INDEX ===
|
22 |
lines = ["### INTENT INDEX ###"]
|
23 |
for it in intents:
|
24 |
-
|
25 |
-
|
26 |
-
|
|
|
27 |
ex_part = f" β’ examples β {exs}" if exs else ""
|
28 |
|
29 |
newline_between = "\n" if det_part and ex_part else ""
|
30 |
-
lines.append(f"{it
|
31 |
|
32 |
intent_index = "\n".join(lines)
|
33 |
|
@@ -56,7 +58,7 @@ _FMT = (
|
|
56 |
"\"missing\":[\"<param>\",...]}"
|
57 |
)
|
58 |
|
59 |
-
def build_parameter_prompt(intent_cfg
|
60 |
missing_params: List[str],
|
61 |
user_input: str,
|
62 |
conversation: List[Dict[str, str]]) -> str:
|
@@ -65,9 +67,9 @@ def build_parameter_prompt(intent_cfg: Dict,
|
|
65 |
"If a parameter cannot be found OR fails validation, keep it in the "
|
66 |
"\"missing\" list. Never guess values."
|
67 |
]
|
68 |
-
for p in intent_cfg
|
69 |
-
if p
|
70 |
-
parts.append(f"* {p
|
71 |
parts.append(_FMT)
|
72 |
|
73 |
history_block = "\n".join(
|
@@ -80,4 +82,4 @@ def build_parameter_prompt(intent_cfg: Dict,
|
|
80 |
"\n\nUSER: " + user_input.strip()
|
81 |
)
|
82 |
log("β
Parameter prompt built")
|
83 |
-
return prompt
|
|
|
8 |
|
9 |
|
10 |
def log(msg: str) -> None:
|
11 |
+
timestamp = datetime.now().strftime("%H:%M:%S.%f")[:-3]
|
12 |
+
print(f"[{timestamp}] {msg}", flush=True)
|
13 |
|
14 |
|
15 |
# βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
|
|
|
18 |
def build_intent_prompt(general_prompt: str,
|
19 |
conversation: List[Dict[str, str]],
|
20 |
user_input: str,
|
21 |
+
intents: List) -> str:
|
22 |
# === INTENT INDEX ===
|
23 |
lines = ["### INTENT INDEX ###"]
|
24 |
for it in intents:
|
25 |
+
# IntentConfig object attribute access
|
26 |
+
det = it.detection_prompt.strip() if it.detection_prompt else ""
|
27 |
+
det_part = f" β’ detection_prompt β "{det}"" if det else ""
|
28 |
+
exs = " | ".join(it.examples) if it.examples else ""
|
29 |
ex_part = f" β’ examples β {exs}" if exs else ""
|
30 |
|
31 |
newline_between = "\n" if det_part and ex_part else ""
|
32 |
+
lines.append(f"{it.name}:{det_part}{newline_between}{ex_part}")
|
33 |
|
34 |
intent_index = "\n".join(lines)
|
35 |
|
|
|
58 |
"\"missing\":[\"<param>\",...]}"
|
59 |
)
|
60 |
|
61 |
+
def build_parameter_prompt(intent_cfg,
|
62 |
missing_params: List[str],
|
63 |
user_input: str,
|
64 |
conversation: List[Dict[str, str]]) -> str:
|
|
|
67 |
"If a parameter cannot be found OR fails validation, keep it in the "
|
68 |
"\"missing\" list. Never guess values."
|
69 |
]
|
70 |
+
for p in intent_cfg.parameters:
|
71 |
+
if p.name in missing_params:
|
72 |
+
parts.append(f"* {p.name}: {p.extraction_prompt}")
|
73 |
parts.append(_FMT)
|
74 |
|
75 |
history_block = "\n".join(
|
|
|
82 |
"\n\nUSER: " + user_input.strip()
|
83 |
)
|
84 |
log("β
Parameter prompt built")
|
85 |
+
return prompt
|