ciyidogan commited on
Commit
c31edec
Β·
verified Β·
1 Parent(s): 6506311

Update prompt_builder.py

Browse files
Files changed (1) hide show
  1. prompt_builder.py +16 -9
prompt_builder.py CHANGED
@@ -1,5 +1,5 @@
1
  """
2
- Flare – Prompt Builder (v4-fix Β· detection_prompt + examples)
3
  ==============================================================
4
  """
5
 
@@ -44,13 +44,9 @@ def build_intent_prompt(general_prompt: str,
44
 
45
 
46
  # ─────────────────────────────────────────────────────────────────────────────
47
- # PARAMETER PROMPT (değişmedi)
48
  # ─────────────────────────────────────────────────────────────────────────────
49
- _FMT = (
50
- "Return ONLY the JSON object in the EXACT format below with no extra text:\n"
51
- "{\"extracted\":[{\"name\":\"<param>\",\"value\":\"<val>\"},...],"
52
- "\"missing\":[\"<param>\",...]}"
53
- )
54
 
55
  def build_parameter_prompt(intent_cfg,
56
  missing_params: List[str],
@@ -58,17 +54,27 @@ def build_parameter_prompt(intent_cfg,
58
  conversation: List[Dict[str, str]]) -> str:
59
 
60
  parts: List[str] = [
61
- "Extract ONLY the parameters listed below from the user's message.",
 
 
62
  "If a parameter cannot be found, is invalid, or wasn't provided, keep it in the \"missing\" list.",
63
- "Never guess or make up values. Only extract values explicitly given by the user."
 
64
  ]
65
 
 
 
66
  for p in intent_cfg.parameters:
67
  if p.name in missing_params:
68
  parts.append(f"β€’ {p.name}: {p.extraction_prompt}")
69
 
 
 
 
 
70
  parts.append(_FMT)
71
 
 
72
  history_block = "\n".join(
73
  f"{m['role'].upper()}: {m['content']}" for m in conversation[-10:]
74
  )
@@ -79,4 +85,5 @@ def build_parameter_prompt(intent_cfg,
79
  "\n\nUSER: " + user_input.strip()
80
  )
81
 
 
82
  return prompt
 
1
  """
2
+ Flare – Prompt Builder (v5 Β· improved parameter prompt)
3
  ==============================================================
4
  """
5
 
 
44
 
45
 
46
  # ─────────────────────────────────────────────────────────────────────────────
47
+ # PARAMETER PROMPT - Improved version
48
  # ─────────────────────────────────────────────────────────────────────────────
49
+ _FMT = """#PARAMETERS:{"extracted":[{"name":"<param>","value":"<val>"},...],"missing":["<param>",...]}"""
 
 
 
 
50
 
51
  def build_parameter_prompt(intent_cfg,
52
  missing_params: List[str],
 
54
  conversation: List[Dict[str, str]]) -> str:
55
 
56
  parts: List[str] = [
57
+ "You are extracting parameters from user messages.",
58
+ "Extract ONLY the parameters listed below from the conversation.",
59
+ "Look at BOTH the current message AND previous messages to find parameter values.",
60
  "If a parameter cannot be found, is invalid, or wasn't provided, keep it in the \"missing\" list.",
61
+ "Never guess or make up values. Only extract values explicitly given by the user.",
62
+ ""
63
  ]
64
 
65
+ # Add parameter descriptions
66
+ parts.append("Parameters to extract:")
67
  for p in intent_cfg.parameters:
68
  if p.name in missing_params:
69
  parts.append(f"β€’ {p.name}: {p.extraction_prompt}")
70
 
71
+ # Add format instruction
72
+ parts.append("")
73
+ parts.append("IMPORTANT: Your response must start with '#PARAMETERS:' followed by the JSON.")
74
+ parts.append("Return ONLY this format with no extra text before or after:")
75
  parts.append(_FMT)
76
 
77
+ # Add conversation history
78
  history_block = "\n".join(
79
  f"{m['role'].upper()}: {m['content']}" for m in conversation[-10:]
80
  )
 
85
  "\n\nUSER: " + user_input.strip()
86
  )
87
 
88
+ log(f"πŸ“ Parameter prompt built for missing: {missing_params}")
89
  return prompt