chore: prompt
Browse files
app.py
CHANGED
|
@@ -20,36 +20,44 @@ def get_device_type() -> str:
|
|
| 20 |
|
| 21 |
# # HuggingFaceTB/SmolLM2-135M-Instruct
|
| 22 |
# model_name="deepseek-ai/DeepSeek-R1-Distill-Qwen-7B" # 15G
|
|
|
|
|
|
|
| 23 |
model_name="meta-llama/Llama-3.2-3B-Instruct" # 6.5G
|
| 24 |
|
| 25 |
device = get_device_type()
|
| 26 |
tokenizer = AutoTokenizer.from_pretrained(model_name)
|
| 27 |
model = AutoModelForCausalLM.from_pretrained(model_name).to(device)
|
| 28 |
|
| 29 |
-
system_prompt =
|
| 30 |
-
|
| 31 |
-
|
| 32 |
-
|
| 33 |
-
|
| 34 |
-
|
| 35 |
-
|
| 36 |
-
|
| 37 |
-
|
| 38 |
-
|
| 39 |
-
|
| 40 |
-
|
| 41 |
-
|
| 42 |
-
|
| 43 |
-
|
| 44 |
-
|
| 45 |
-
|
| 46 |
-
|
| 47 |
-
|
| 48 |
-
|
| 49 |
-
|
| 50 |
-
|
| 51 |
-
|
| 52 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 53 |
|
| 54 |
examples = [
|
| 55 |
"My transaction payment-a1c1 failed",
|
|
@@ -65,7 +73,7 @@ def predict(message, history):
|
|
| 65 |
history = [{"role": "system", "content": sys_prompt}] + history
|
| 66 |
else:
|
| 67 |
history[0]["content"] = sys_prompt
|
| 68 |
-
|
| 69 |
history.append({"role": "user", "content": message})
|
| 70 |
|
| 71 |
# 1. Build prompt from history using chat template
|
|
|
|
| 20 |
|
| 21 |
# # HuggingFaceTB/SmolLM2-135M-Instruct
|
| 22 |
# model_name="deepseek-ai/DeepSeek-R1-Distill-Qwen-7B" # 15G
|
| 23 |
+
|
| 24 |
+
# "meta-llama/Llama-3.2-3B does not work
|
| 25 |
model_name="meta-llama/Llama-3.2-3B-Instruct" # 6.5G
|
| 26 |
|
| 27 |
device = get_device_type()
|
| 28 |
tokenizer = AutoTokenizer.from_pretrained(model_name)
|
| 29 |
model = AutoModelForCausalLM.from_pretrained(model_name).to(device)
|
| 30 |
|
| 31 |
+
system_prompt = """
|
| 32 |
+
You are a customer support officer. Your task is to extract a transaction ID from the USER INPUT and determine its transaction type.
|
| 33 |
+
|
| 34 |
+
To extract the transaction ID, follow these steps:
|
| 35 |
+
|
| 36 |
+
1.For each word in the USER INPUT, check if it starts with 'payout' or 'payment'. If yes, continue to Step 2; if not, go to Step 7.
|
| 37 |
+
2.Check if the character immediately after the prefix ('payout' or 'payment') is a dash ('-'). If yes, continue to Step 3; if not, go to Step 7.
|
| 38 |
+
3.Check if there is at least one digit or character after the dash. If yes, continue to Step 4; if not, go to Step 7.
|
| 39 |
+
4.Extract the transaction ID from the USER INPUT and continue to Step 5.
|
| 40 |
+
5.Verify that the extracted transaction ID appears exactly in the USER INPUT. If yes, continue to Step 6; if not, go to Step 7.
|
| 41 |
+
6.Mark the transaction ID as valid and set the flag found to true.
|
| 42 |
+
7.If no valid transaction ID is found, set the flag found to false.
|
| 43 |
+
|
| 44 |
+
To determine the transaction type:
|
| 45 |
+
|
| 46 |
+
1.If the transaction ID starts with 'payout', the type is payout.
|
| 47 |
+
2.If the transaction ID starts with 'payment', the type is payment.
|
| 48 |
+
|
| 49 |
+
===>USER INPUT BEGINS
|
| 50 |
+
{input}
|
| 51 |
+
<===USER INPUT ENDS
|
| 52 |
+
|
| 53 |
+
Respond in valid JSON with the following fields:
|
| 54 |
+
|
| 55 |
+
found: (boolean) Whether a valid transaction ID was found.
|
| 56 |
+
transaction_id: (string, if found) The extracted transaction ID.
|
| 57 |
+
transaction_type: (string, if found) The transaction type in lowercase.
|
| 58 |
+
justification: (string) An explanation of how the transaction ID and type were determined. If no valid transaction ID is found, do not fabricate an explanation.
|
| 59 |
+
Return only valid JSON and nothing else.
|
| 60 |
+
"""
|
| 61 |
|
| 62 |
examples = [
|
| 63 |
"My transaction payment-a1c1 failed",
|
|
|
|
| 73 |
history = [{"role": "system", "content": sys_prompt}] + history
|
| 74 |
else:
|
| 75 |
history[0]["content"] = sys_prompt
|
| 76 |
+
|
| 77 |
history.append({"role": "user", "content": message})
|
| 78 |
|
| 79 |
# 1. Build prompt from history using chat template
|