Update chatbot_new.py
Browse files- chatbot_new.py +14 -15
chatbot_new.py
CHANGED
|
@@ -17,8 +17,8 @@ META_PATH = "hbl_vector_store/hbl_metadata.pkl"
|
|
| 17 |
EMBED_MODEL = "./bge-m3"
|
| 18 |
OLLAMA_URL = "http://localhost:11434/api/chat"
|
| 19 |
LLM_MODEL = "qwen3.5:4b"
|
| 20 |
-
TOP_K =
|
| 21 |
-
MIN_SCORE = 0.
|
| 22 |
HISTORY_TURNS = 3 # number of past user/assistant exchanges kept for classifier context
|
| 23 |
|
| 24 |
|
|
@@ -105,7 +105,6 @@ HBL_TERMS = [
|
|
| 105 |
]
|
| 106 |
|
| 107 |
OTHER_BANK_TERMS = [
|
| 108 |
-
"haider bank",
|
| 109 |
"meezan bank",
|
| 110 |
"meezan",
|
| 111 |
"ubl",
|
|
@@ -139,14 +138,14 @@ def detect_bank_entity(query):
|
|
| 139 |
hbl_hit = any(_has_term(q, t) for t in HBL_TERMS)
|
| 140 |
other_hit = any(_has_term(q, t) for t in OTHER_BANK_TERMS)
|
| 141 |
|
| 142 |
-
if hbl_hit:
|
| 143 |
-
|
| 144 |
-
|
| 145 |
-
# docs, so retrieval keeps the answer scoped correctly regardless.
|
| 146 |
-
return "HBL"
|
| 147 |
-
|
| 148 |
if other_hit:
|
| 149 |
return "OTHER_BANK"
|
|
|
|
|
|
|
|
|
|
| 150 |
|
| 151 |
return "UNKNOWN"
|
| 152 |
|
|
@@ -272,14 +271,14 @@ def retrieve(query):
|
|
| 272 |
SYSTEM_PROMPT = """
|
| 273 |
You are Habib Bank Limited Assistant.
|
| 274 |
|
| 275 |
-
|
| 276 |
-
|
|
|
|
| 277 |
- Do not use outside knowledge.
|
| 278 |
-
- Do not guess.
|
| 279 |
-
- If
|
| 280 |
"I could not find this information in the available HBL documents."
|
| 281 |
-
|
| 282 |
-
Never answer questions outside HBL domain.
|
| 283 |
"""
|
| 284 |
|
| 285 |
|
|
|
|
| 17 |
EMBED_MODEL = "./bge-m3"
|
| 18 |
OLLAMA_URL = "http://localhost:11434/api/chat"
|
| 19 |
LLM_MODEL = "qwen3.5:4b"
|
| 20 |
+
TOP_K = 4
|
| 21 |
+
MIN_SCORE = 0.58 # re-validate against the new embeddings, this was tuned for the old ones
|
| 22 |
HISTORY_TURNS = 3 # number of past user/assistant exchanges kept for classifier context
|
| 23 |
|
| 24 |
|
|
|
|
| 105 |
]
|
| 106 |
|
| 107 |
OTHER_BANK_TERMS = [
|
|
|
|
| 108 |
"meezan bank",
|
| 109 |
"meezan",
|
| 110 |
"ubl",
|
|
|
|
| 138 |
hbl_hit = any(_has_term(q, t) for t in HBL_TERMS)
|
| 139 |
other_hit = any(_has_term(q, t) for t in OTHER_BANK_TERMS)
|
| 140 |
|
| 141 |
+
if hbl_hit and other_hit:
|
| 142 |
+
return "OTHER_BANK"
|
| 143 |
+
|
|
|
|
|
|
|
|
|
|
| 144 |
if other_hit:
|
| 145 |
return "OTHER_BANK"
|
| 146 |
+
|
| 147 |
+
if hbl_hit:
|
| 148 |
+
return "HBL"
|
| 149 |
|
| 150 |
return "UNKNOWN"
|
| 151 |
|
|
|
|
| 271 |
SYSTEM_PROMPT = """
|
| 272 |
You are Habib Bank Limited Assistant.
|
| 273 |
|
| 274 |
+
Answer only from the provided HBL documents.
|
| 275 |
+
|
| 276 |
+
Rules:
|
| 277 |
- Do not use outside knowledge.
|
| 278 |
+
- Do not guess or invent information.
|
| 279 |
+
- If the answer is not present in the documents, say:
|
| 280 |
"I could not find this information in the available HBL documents."
|
| 281 |
+
- Do not discuss topics unrelated to HBL.
|
|
|
|
| 282 |
"""
|
| 283 |
|
| 284 |
|