ciyidogan commited on
Commit
3bd94e0
Β·
verified Β·
1 Parent(s): b21aa21

Update prompt_builder.py

Browse files
Files changed (1) hide show
  1. prompt_builder.py +55 -3
prompt_builder.py CHANGED
@@ -1,12 +1,40 @@
1
  """
2
- Flare – Prompt Builder (v5 Β· improved parameter prompt)
3
  ==============================================================
4
  """
5
 
6
  from typing import List, Dict
 
7
  from utils import log
8
 
9
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
10
  # ─────────────────────────────────────────────────────────────────────────────
11
  # INTENT PROMPT
12
  # ─────────────────────────────────────────────────────────────────────────────
@@ -53,8 +81,11 @@ def build_parameter_prompt(intent_cfg,
53
  user_input: 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.",
@@ -66,7 +97,28 @@ def build_parameter_prompt(intent_cfg,
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("")
 
1
  """
2
+ Flare – Prompt Builder (v6 Β· date handling)
3
  ==============================================================
4
  """
5
 
6
  from typing import List, Dict
7
+ from datetime import datetime, timedelta
8
  from utils import log
9
 
10
 
11
+ # Date helper for Turkish date expressions
12
+ def _get_date_context() -> Dict[str, str]:
13
+ """Generate date context for Turkish date expressions"""
14
+ now = datetime.now()
15
+
16
+ # Weekday names in Turkish
17
+ weekdays_tr = ["Pazartesi", "SalΔ±", "Γ‡arşamba", "Perşembe", "Cuma", "Cumartesi", "Pazar"]
18
+ today_weekday = weekdays_tr[now.weekday()]
19
+
20
+ # Calculate various dates
21
+ dates = {
22
+ "today": now.strftime("%Y-%m-%d"),
23
+ "tomorrow": (now + timedelta(days=1)).strftime("%Y-%m-%d"),
24
+ "day_after_tomorrow": (now + timedelta(days=2)).strftime("%Y-%m-%d"),
25
+ "this_weekend_saturday": (now + timedelta(days=(5-now.weekday())%7)).strftime("%Y-%m-%d"),
26
+ "this_weekend_sunday": (now + timedelta(days=(6-now.weekday())%7)).strftime("%Y-%m-%d"),
27
+ "next_week_same_day": (now + timedelta(days=7)).strftime("%Y-%m-%d"),
28
+ "two_weeks_later": (now + timedelta(days=14)).strftime("%Y-%m-%d"),
29
+ "today_weekday": today_weekday,
30
+ "today_day": now.day,
31
+ "today_month": now.month,
32
+ "today_year": now.year
33
+ }
34
+
35
+ return dates
36
+
37
+
38
  # ─────────────────────────────────────────────────────────────────────────────
39
  # INTENT PROMPT
40
  # ─────────────────────────────────────────────────────────────────────────────
 
81
  user_input: str,
82
  conversation: List[Dict[str, str]]) -> str:
83
 
84
+ date_ctx = _get_date_context()
85
+
86
  parts: List[str] = [
87
+ "You are extracting parameters from user messages in TURKISH.",
88
+ f"Today is {date_ctx['today']} ({date_ctx['today_weekday']}). Tomorrow is {date_ctx['tomorrow']}.",
89
  "Extract ONLY the parameters listed below from the conversation.",
90
  "Look at BOTH the current message AND previous messages to find parameter values.",
91
  "If a parameter cannot be found, is invalid, or wasn't provided, keep it in the \"missing\" list.",
 
97
  parts.append("Parameters to extract:")
98
  for p in intent_cfg.parameters:
99
  if p.name in missing_params:
100
+ # Special handling for date type parameters
101
+ if p.type == "date":
102
+ date_prompt = (
103
+ f"β€’ {p.name}: {p.extraction_prompt}\n"
104
+ f" IMPORTANT DATE RULES:\n"
105
+ f" - 'bugΓΌn' = {date_ctx['today']}\n"
106
+ f" - 'yarΔ±n' = {date_ctx['tomorrow']}\n"
107
+ f" - 'ΓΆbΓΌr gΓΌn' = {date_ctx['day_after_tomorrow']}\n"
108
+ f" - 'bu hafta sonu' = {date_ctx['this_weekend_saturday']} or {date_ctx['this_weekend_sunday']}\n"
109
+ f" - 'bu cumartesi' = {date_ctx['this_weekend_saturday']}\n"
110
+ f" - 'bu pazar' = {date_ctx['this_weekend_sunday']}\n"
111
+ f" - 'haftaya' or 'gelecek hafta' = add 7 days to current date\n"
112
+ f" - 'haftaya bugΓΌn' = {date_ctx['next_week_same_day']}\n"
113
+ f" - 'iki hafta sonra' = {date_ctx['two_weeks_later']}\n"
114
+ f" - '15 gΓΌn sonra' = add 15 days to today\n"
115
+ f" - '10 Temmuz' = {date_ctx['today_year']}-07-10\n"
116
+ f" - Turkish months: Ocak=01, Şubat=02, Mart=03, Nisan=04, Mayıs=05, Haziran=06, "
117
+ f"Temmuz=07, Ağustos=08, Eylül=09, Ekim=10, Kasım=11, Aralık=12"
118
+ )
119
+ parts.append(date_prompt)
120
+ else:
121
+ parts.append(f"β€’ {p.name}: {p.extraction_prompt}")
122
 
123
  # Add format instruction
124
  parts.append("")