Update handler.py
Browse files- handler.py +7 -3
handler.py
CHANGED
|
@@ -7,7 +7,7 @@ from huggingface_hub import snapshot_download
|
|
| 7 |
BASE_MODEL = "deepseek-ai/DeepSeek-R1-Distill-Qwen-1.5B"
|
| 8 |
ADAPTER_PATH = "GilbertAkham/deepseek-R1-multitask-lora"
|
| 9 |
|
| 10 |
-
# === System message
|
| 11 |
SYSTEM_PROMPT = (
|
| 12 |
"You are Chat-Bot, a helpful and logical assistant trained for reasoning, "
|
| 13 |
"email, chatting, summarization, story continuation, and report writing.\n\n"
|
|
@@ -37,8 +37,8 @@ class EndpointHandler:
|
|
| 37 |
|
| 38 |
def __call__(self, data):
|
| 39 |
# === Combine system + user prompt ===
|
| 40 |
-
|
| 41 |
-
full_prompt = SYSTEM_PROMPT +
|
| 42 |
|
| 43 |
params = data.get("parameters", {})
|
| 44 |
max_new_tokens = params.get("max_new_tokens", 512)
|
|
@@ -58,5 +58,9 @@ class EndpointHandler:
|
|
| 58 |
eos_token_id=self.tokenizer.eos_token_id,
|
| 59 |
)
|
| 60 |
|
|
|
|
| 61 |
text = self.tokenizer.decode(outputs[0], skip_special_tokens=True)
|
|
|
|
|
|
|
|
|
|
| 62 |
return {"generated_text": text}
|
|
|
|
| 7 |
BASE_MODEL = "deepseek-ai/DeepSeek-R1-Distill-Qwen-1.5B"
|
| 8 |
ADAPTER_PATH = "GilbertAkham/deepseek-R1-multitask-lora"
|
| 9 |
|
| 10 |
+
# === System message ===
|
| 11 |
SYSTEM_PROMPT = (
|
| 12 |
"You are Chat-Bot, a helpful and logical assistant trained for reasoning, "
|
| 13 |
"email, chatting, summarization, story continuation, and report writing.\n\n"
|
|
|
|
| 37 |
|
| 38 |
def __call__(self, data):
|
| 39 |
# === Combine system + user prompt ===
|
| 40 |
+
user_prompt = data.get("inputs", "")
|
| 41 |
+
full_prompt = SYSTEM_PROMPT + user_prompt
|
| 42 |
|
| 43 |
params = data.get("parameters", {})
|
| 44 |
max_new_tokens = params.get("max_new_tokens", 512)
|
|
|
|
| 58 |
eos_token_id=self.tokenizer.eos_token_id,
|
| 59 |
)
|
| 60 |
|
| 61 |
+
# === Decode and strip system message ===
|
| 62 |
text = self.tokenizer.decode(outputs[0], skip_special_tokens=True)
|
| 63 |
+
if text.startswith(SYSTEM_PROMPT):
|
| 64 |
+
text = text[len(SYSTEM_PROMPT):].strip()
|
| 65 |
+
|
| 66 |
return {"generated_text": text}
|