""" Flare – Prompt Builder (v2, değişmedi) ======================================= • build_intent_prompt • build_parameter_prompt """ from typing import List, Dict from datetime import datetime def log(msg: str) -> None: print(f"[{datetime.now().strftime('%H:%M:%S')}] {msg}", flush=True) # --------------------------------------------------------------------------- # INTENT DETECTION PROMPT # --------------------------------------------------------------------------- def build_intent_prompt(general_prompt: str, conversation: List[Dict[str, str]], user_input: str) -> str: history = "\n".join( f"{m['role'].upper()}: {m['content']}" for m in conversation[-10:] ) prompt = ( f"{general_prompt}\n\n" f"Conversation so far:\n{history}\n\n" f"USER: {user_input.strip()}" ) log("✅ Intent prompt built") return prompt # --------------------------------------------------------------------------- # PARAMETER EXTRACTION PROMPT # --------------------------------------------------------------------------- _FMT = ("Return exactly ONE line in the format:\n" "#PARAMETERS:{\"extracted\":[{\"name\":\"\",\"value\":\"\"},...]," "\"missing\":[\"\",...]}") def build_parameter_prompt(intent_cfg: Dict, missing_params: List[str], user_input: str, conversation: List[Dict[str, str]]) -> str: lines = [ "You will extract ONLY the parameters listed below.", "If a parameter cannot be found OR fails validation, keep it in the " "\"missing\" list. Never guess values." ] for p in intent_cfg["parameters"]: if p["name"] in missing_params: lines.append(f"* {p['name']}: {p['extraction_prompt']}") lines.append(_FMT) history = "\n".join( f"{m['role'].upper()}: {m['content']}" for m in conversation[-10:] ) prompt = ( "\n".join(lines) + "\n\nConversation so far:\n" + history + "\n\nUSER: " + user_input.strip() ) log("✅ Parameter prompt built") return prompt