Spaces:
Sleeping
Sleeping
debug01
Browse files
app.py
CHANGED
|
@@ -76,13 +76,13 @@ def add_docs(user_id: str, docs: list[str]) -> int:
|
|
| 76 |
# ----- Qwen-chat prompt helper ---------------------------------------------
|
| 77 |
def build_qwen_prompt(context: str, user_question: str) -> str:
|
| 78 |
"""Return a string that follows Qwen-Chat’s template."""
|
|
|
|
| 79 |
conversation = [
|
| 80 |
{"role": "system",
|
| 81 |
"content": "You are an email assistant. Use ONLY the context provided."},
|
| 82 |
{"role": "user",
|
| 83 |
"content": f"Context:\n{context}\n\n{user_question}"}
|
| 84 |
]
|
| 85 |
-
# add_generation_prompt=True appends the assistant tag
|
| 86 |
return tokenizer.apply_chat_template(
|
| 87 |
conversation, tokenize=False, add_generation_prompt=True
|
| 88 |
)
|
|
@@ -122,7 +122,8 @@ def rag(req:QueryReq):
|
|
| 122 |
load_chat()
|
| 123 |
inputs = tokenizer(prompt, return_tensors="pt").to(chat_model.device)
|
| 124 |
out = chat_model.generate(**inputs, max_new_tokens=512)
|
| 125 |
-
|
|
|
|
| 126 |
return {"answer": ans}
|
| 127 |
|
| 128 |
# ---------- 4. Gradio playground (same UI as before) --------------------------
|
|
|
|
| 76 |
# ----- Qwen-chat prompt helper ---------------------------------------------
|
| 77 |
def build_qwen_prompt(context: str, user_question: str) -> str:
|
| 78 |
"""Return a string that follows Qwen-Chat’s template."""
|
| 79 |
+
load_chat() # ← make sure tokenizer is ready
|
| 80 |
conversation = [
|
| 81 |
{"role": "system",
|
| 82 |
"content": "You are an email assistant. Use ONLY the context provided."},
|
| 83 |
{"role": "user",
|
| 84 |
"content": f"Context:\n{context}\n\n{user_question}"}
|
| 85 |
]
|
|
|
|
| 86 |
return tokenizer.apply_chat_template(
|
| 87 |
conversation, tokenize=False, add_generation_prompt=True
|
| 88 |
)
|
|
|
|
| 122 |
load_chat()
|
| 123 |
inputs = tokenizer(prompt, return_tensors="pt").to(chat_model.device)
|
| 124 |
out = chat_model.generate(**inputs, max_new_tokens=512)
|
| 125 |
+
full = tokenizer.decode(out[0], skip_special_tokens=True)
|
| 126 |
+
ans = full.split("<|im_start|>assistant")[-1].strip()
|
| 127 |
return {"answer": ans}
|
| 128 |
|
| 129 |
# ---------- 4. Gradio playground (same UI as before) --------------------------
|