Spaces:
Running
Running
Update chat_handler_debug.py
Browse files- chat_handler_debug.py +4 -19
chat_handler_debug.py
CHANGED
@@ -28,12 +28,9 @@ async def handle_chat(msg: Message, request: Request, app, s_config):
|
|
28 |
if get_model() is None or get_tokenizer() is None:
|
29 |
return {"error": "Model yüklenmedi."}
|
30 |
|
31 |
-
|
32 |
-
|
33 |
-
|
34 |
-
detected_intent, intent_conf = await detect_intent(user_input)
|
35 |
-
if DEBUG:
|
36 |
-
log(f"🎯 Intent tespiti: {detected_intent}, Confidence: {intent_conf:.2f}")
|
37 |
|
38 |
current_intent = session.get("last_intent")
|
39 |
awaiting_variable = session.get("awaiting_variable")
|
@@ -42,7 +39,6 @@ async def handle_chat(msg: Message, request: Request, app, s_config):
|
|
42 |
log(f"📦 Session: {session}")
|
43 |
log(f"🧩 Awaiting: {awaiting_variable}, Last Intent: {current_intent}")
|
44 |
|
45 |
-
# === KONU DEĞİŞİKLİĞİ TESPİTİ ===
|
46 |
if (
|
47 |
awaiting_variable and
|
48 |
detected_intent and
|
@@ -55,7 +51,6 @@ async def handle_chat(msg: Message, request: Request, app, s_config):
|
|
55 |
session["last_intent"] = detected_intent
|
56 |
current_intent = detected_intent
|
57 |
|
58 |
-
# === INTENT GEÇERLİ Mİ? ===
|
59 |
intent_is_valid = (
|
60 |
detected_intent and
|
61 |
intent_conf > s_config.INTENT_CONFIDENCE_THRESHOLD and
|
@@ -71,7 +66,6 @@ async def handle_chat(msg: Message, request: Request, app, s_config):
|
|
71 |
data_formats = s_config.DATA_FORMATS
|
72 |
variable_format_map = definition.get("variable_formats", {})
|
73 |
|
74 |
-
# === AWAITING PARAMETRE TAMAMLANDI MI? ===
|
75 |
if awaiting_variable:
|
76 |
extracted = extract_parameters(pattern_list, user_input)
|
77 |
for p in extracted:
|
@@ -81,7 +75,6 @@ async def handle_chat(msg: Message, request: Request, app, s_config):
|
|
81 |
log(f"✅ Awaiting parametre tamamlandı: {awaiting_variable} = {p['value']}")
|
82 |
break
|
83 |
|
84 |
-
# === TÜM PARAMETRELERİ TOPLA ===
|
85 |
extracted = extract_parameters(pattern_list, user_input)
|
86 |
variables = {p["key"]: p["value"] for p in extracted}
|
87 |
session.setdefault("variables", {}).update(variables)
|
@@ -89,12 +82,7 @@ async def handle_chat(msg: Message, request: Request, app, s_config):
|
|
89 |
if DEBUG:
|
90 |
log(f"🧪 Tespit edilen parametreler: {variables}")
|
91 |
|
92 |
-
|
93 |
-
is_valid, validation_errors = validate_variable_formats(
|
94 |
-
session["variables"],
|
95 |
-
variable_format_map,
|
96 |
-
data_formats
|
97 |
-
)
|
98 |
if DEBUG:
|
99 |
log(f"📛 Validasyon hataları: {validation_errors}")
|
100 |
|
@@ -104,7 +92,6 @@ async def handle_chat(msg: Message, request: Request, app, s_config):
|
|
104 |
app.state.session_store = session_store
|
105 |
return {"response": list(validation_errors.values())[0]}
|
106 |
|
107 |
-
# === EKSİK VAR MI? ===
|
108 |
expected_vars = list(variable_format_map.keys())
|
109 |
missing_vars = [v for v in expected_vars if v not in session["variables"]]
|
110 |
if DEBUG:
|
@@ -116,7 +103,6 @@ async def handle_chat(msg: Message, request: Request, app, s_config):
|
|
116 |
app.state.session_store = session_store
|
117 |
return {"response": f"Lütfen {missing_vars[0]} bilgisini belirtir misiniz?"}
|
118 |
|
119 |
-
# === INTENT ÇALIŞTIR ===
|
120 |
log("🚀 execute_intent() çağrılıyor...")
|
121 |
result = execute_intent(
|
122 |
detected_intent,
|
@@ -136,7 +122,6 @@ async def handle_chat(msg: Message, request: Request, app, s_config):
|
|
136 |
else:
|
137 |
return {"response": random.choice(s_config.FALLBACK_ANSWERS)}
|
138 |
|
139 |
-
# === LLM FALLBACK ===
|
140 |
log("🤖 execute_intent çağrılmadı → LLM fallback devrede")
|
141 |
session["awaiting_variable"] = None
|
142 |
session["variables"] = {}
|
|
|
28 |
if get_model() is None or get_tokenizer() is None:
|
29 |
return {"error": "Model yüklenmedi."}
|
30 |
|
31 |
+
detected_intent, intent_conf = await detect_intent(user_input)
|
32 |
+
if DEBUG:
|
33 |
+
log(f"🎯 Intent tespiti: {detected_intent}, Confidence: {intent_conf:.2f}")
|
|
|
|
|
|
|
34 |
|
35 |
current_intent = session.get("last_intent")
|
36 |
awaiting_variable = session.get("awaiting_variable")
|
|
|
39 |
log(f"📦 Session: {session}")
|
40 |
log(f"🧩 Awaiting: {awaiting_variable}, Last Intent: {current_intent}")
|
41 |
|
|
|
42 |
if (
|
43 |
awaiting_variable and
|
44 |
detected_intent and
|
|
|
51 |
session["last_intent"] = detected_intent
|
52 |
current_intent = detected_intent
|
53 |
|
|
|
54 |
intent_is_valid = (
|
55 |
detected_intent and
|
56 |
intent_conf > s_config.INTENT_CONFIDENCE_THRESHOLD and
|
|
|
66 |
data_formats = s_config.DATA_FORMATS
|
67 |
variable_format_map = definition.get("variable_formats", {})
|
68 |
|
|
|
69 |
if awaiting_variable:
|
70 |
extracted = extract_parameters(pattern_list, user_input)
|
71 |
for p in extracted:
|
|
|
75 |
log(f"✅ Awaiting parametre tamamlandı: {awaiting_variable} = {p['value']}")
|
76 |
break
|
77 |
|
|
|
78 |
extracted = extract_parameters(pattern_list, user_input)
|
79 |
variables = {p["key"]: p["value"] for p in extracted}
|
80 |
session.setdefault("variables", {}).update(variables)
|
|
|
82 |
if DEBUG:
|
83 |
log(f"🧪 Tespit edilen parametreler: {variables}")
|
84 |
|
85 |
+
is_valid, validation_errors = validate_variable_formats(session["variables"], variable_format_map, data_formats)
|
|
|
|
|
|
|
|
|
|
|
86 |
if DEBUG:
|
87 |
log(f"📛 Validasyon hataları: {validation_errors}")
|
88 |
|
|
|
92 |
app.state.session_store = session_store
|
93 |
return {"response": list(validation_errors.values())[0]}
|
94 |
|
|
|
95 |
expected_vars = list(variable_format_map.keys())
|
96 |
missing_vars = [v for v in expected_vars if v not in session["variables"]]
|
97 |
if DEBUG:
|
|
|
103 |
app.state.session_store = session_store
|
104 |
return {"response": f"Lütfen {missing_vars[0]} bilgisini belirtir misiniz?"}
|
105 |
|
|
|
106 |
log("🚀 execute_intent() çağrılıyor...")
|
107 |
result = execute_intent(
|
108 |
detected_intent,
|
|
|
122 |
else:
|
123 |
return {"response": random.choice(s_config.FALLBACK_ANSWERS)}
|
124 |
|
|
|
125 |
log("🤖 execute_intent çağrılmadı → LLM fallback devrede")
|
126 |
session["awaiting_variable"] = None
|
127 |
session["variables"] = {}
|