ciyidogan commited on
Commit
9c2fd74
·
verified ·
1 Parent(s): 7d2683e

Update prompt_builder.py

Browse files
Files changed (1) hide show
  1. prompt_builder.py +8 -21
prompt_builder.py CHANGED
@@ -1,15 +1,14 @@
1
  """
2
- Flare – Prompt Builder (v2)
3
- ============================
4
  • build_intent_prompt
5
  • build_parameter_prompt
6
- Spark (LLM) çağrılarına gidecek ‘system’ prompt’ları üretir.
7
  """
8
 
9
  from typing import List, Dict
10
  from datetime import datetime
11
 
12
- # 🕒 zamanlı log
13
  def log(msg: str) -> None:
14
  print(f"[{datetime.now().strftime('%H:%M:%S')}] {msg}", flush=True)
15
 
@@ -20,9 +19,6 @@ def log(msg: str) -> None:
20
  def build_intent_prompt(general_prompt: str,
21
  conversation: List[Dict[str, str]],
22
  user_input: str) -> str:
23
- """
24
- Returns system-prompt string for LLM to detect intent.
25
- """
26
  history = "\n".join(
27
  f"{m['role'].upper()}: {m['content']}" for m in conversation[-10:]
28
  )
@@ -38,31 +34,23 @@ def build_intent_prompt(general_prompt: str,
38
  # ---------------------------------------------------------------------------
39
  # PARAMETER EXTRACTION PROMPT
40
  # ---------------------------------------------------------------------------
41
- _RESULT_SPEC = (
42
- "Return exactly ONE line in the format:\n"
43
- "#PARAMETERS:{\"extracted\":[{\"name\":\"<param>\",\"value\":\"<val>\"},...],"
44
- "\"missing\":[\"<param>\",...]}"
45
- )
46
 
47
  def build_parameter_prompt(intent_cfg: Dict,
48
  missing_params: List[str],
49
  user_input: str,
50
  conversation: List[Dict[str, str]]) -> str:
51
- """
52
- intent_cfg : intent section from service_config
53
- missing_params : list of param names still required
54
- """
55
  lines = [
56
  "You will extract ONLY the parameters listed below.",
57
  "If a parameter cannot be found OR fails validation, keep it in the "
58
  "\"missing\" list. Never guess values."
59
  ]
60
-
61
  for p in intent_cfg["parameters"]:
62
  if p["name"] in missing_params:
63
  lines.append(f"* {p['name']}: {p['extraction_prompt']}")
64
-
65
- lines.append(_RESULT_SPEC)
66
 
67
  history = "\n".join(
68
  f"{m['role'].upper()}: {m['content']}" for m in conversation[-10:]
@@ -73,6 +61,5 @@ def build_parameter_prompt(intent_cfg: Dict,
73
  "\n\nConversation so far:\n" + history +
74
  "\n\nUSER: " + user_input.strip()
75
  )
76
- log("✅ Parameter-prompt built")
77
  return prompt
78
-
 
1
  """
2
+ Flare – Prompt Builder (v2, değişmedi)
3
+ =======================================
4
  • build_intent_prompt
5
  • build_parameter_prompt
 
6
  """
7
 
8
  from typing import List, Dict
9
  from datetime import datetime
10
 
11
+
12
  def log(msg: str) -> None:
13
  print(f"[{datetime.now().strftime('%H:%M:%S')}] {msg}", flush=True)
14
 
 
19
  def build_intent_prompt(general_prompt: str,
20
  conversation: List[Dict[str, str]],
21
  user_input: str) -> str:
 
 
 
22
  history = "\n".join(
23
  f"{m['role'].upper()}: {m['content']}" for m in conversation[-10:]
24
  )
 
34
  # ---------------------------------------------------------------------------
35
  # PARAMETER EXTRACTION PROMPT
36
  # ---------------------------------------------------------------------------
37
+ _FMT = ("Return exactly ONE line in the format:\n"
38
+ "#PARAMETERS:{\"extracted\":[{\"name\":\"<param>\",\"value\":\"<val>\"},...],"
39
+ "\"missing\":[\"<param>\",...]}")
 
 
40
 
41
  def build_parameter_prompt(intent_cfg: Dict,
42
  missing_params: List[str],
43
  user_input: str,
44
  conversation: List[Dict[str, str]]) -> str:
 
 
 
 
45
  lines = [
46
  "You will extract ONLY the parameters listed below.",
47
  "If a parameter cannot be found OR fails validation, keep it in the "
48
  "\"missing\" list. Never guess values."
49
  ]
 
50
  for p in intent_cfg["parameters"]:
51
  if p["name"] in missing_params:
52
  lines.append(f"* {p['name']}: {p['extraction_prompt']}")
53
+ lines.append(_FMT)
 
54
 
55
  history = "\n".join(
56
  f"{m['role'].upper()}: {m['content']}" for m in conversation[-10:]
 
61
  "\n\nConversation so far:\n" + history +
62
  "\n\nUSER: " + user_input.strip()
63
  )
64
+ log("✅ Parameter prompt built")
65
  return prompt