ciyidogan commited on
Commit
add2298
Β·
verified Β·
1 Parent(s): 2678346

Update prompt_builder.py

Browse files
Files changed (1) hide show
  1. prompt_builder.py +59 -1
prompt_builder.py CHANGED
@@ -113,7 +113,65 @@ def build_intent_prompt(general_prompt: str,
113
  return prompt
114
 
115
  # ─────────────────────────────────────────────────────────────────────────────
116
- # PARAMETER PROMPT - Improved version
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
117
  # ─────────────────────────────────────────────────────────────────────────────
118
  _FMT = """#PARAMETERS:{"extracted":[{"name":"<param>","value":"<val>"},...],"missing":["<param>",...]}"""
119
 
 
113
  return prompt
114
 
115
  # ─────────────────────────────────────────────────────────────────────────────
116
+ # RESPONSE PROMPT
117
+ # ─────────────────────────────────────────────────────────────────────────────
118
+ def build_api_response_prompt(api_config, api_response: Dict) -> str:
119
+ """Build prompt for API response with mappings"""
120
+
121
+ response_prompt = api_config.response_prompt or "API yanΔ±tΔ±nΔ± kullanΔ±cΔ±ya aΓ§Δ±kla:"
122
+
123
+ # Response mappings varsa, mapping bilgilerini ekle
124
+ if api_config.response_mappings:
125
+ mapping_info = []
126
+
127
+ for mapping in api_config.response_mappings:
128
+ # JSON path'e gâre değeri bul
129
+ value = extract_value_from_json_path(api_response, mapping.json_path)
130
+ if value is not None:
131
+ # Type'a gΓΆre formatlama
132
+ if mapping.type == "date":
133
+ # ISO date'i TΓΌrkΓ§e formata Γ§evir
134
+ try:
135
+ dt = datetime.fromisoformat(value.replace('Z', '+00:00'))
136
+ value = dt.strftime("%d %B %Y %H:%M")
137
+ except:
138
+ pass
139
+ elif mapping.type == "float":
140
+ try:
141
+ value = f"{float(value):,.2f}"
142
+ except:
143
+ pass
144
+
145
+ mapping_info.append(f"{mapping.caption}: {value}")
146
+
147
+ if mapping_info:
148
+ # Response prompt'a mapping bilgilerini ekle
149
+ mapping_text = "\n\nΓ–nemli Bilgiler:\n" + "\n".join(f"β€’ {info}" for info in mapping_info)
150
+ response_prompt = response_prompt.replace("{{api_response}}", f"{{{{api_response}}}}{mapping_text}")
151
+
152
+ # API response'u JSON string olarak ekle
153
+ response_json = json.dumps(api_response, ensure_ascii=False, indent=2)
154
+ final_prompt = response_prompt.replace("{{api_response}}", response_json)
155
+
156
+ return final_prompt
157
+
158
+ def extract_value_from_json_path(data: Dict, path: str):
159
+ """Extract value from JSON using dot notation path"""
160
+ try:
161
+ parts = path.split('.')
162
+ value = data
163
+ for part in parts:
164
+ if isinstance(value, dict):
165
+ value = value.get(part)
166
+ elif isinstance(value, list) and part.isdigit():
167
+ value = value[int(part)]
168
+ else:
169
+ return None
170
+ return value
171
+ except:
172
+ return None
173
+ # ─────────────────────────────────────────────────────────────────────────────
174
+ # PARAMETER PROMPT
175
  # ─────────────────────────────────────────────────────────────────────────────
176
  _FMT = """#PARAMETERS:{"extracted":[{"name":"<param>","value":"<val>"},...],"missing":["<param>",...]}"""
177