ivxivx commited on
Commit
f3c5d0a
·
unverified ·
1 Parent(s): 7987ce3

chore: prompt

Browse files
Files changed (1) hide show
  1. app.py +33 -25
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
- "You are a customer officer that helps extract transaction id from the USER INPUT and determine the transaction type based on the transaction id. "
31
- "To find transaction id, follow all the steps below: "
32
- "Step 1. **Look for prefix**: for each word in the USER INPUT, check if it starts with 'payout' or 'payment', if so, you should go to Step 2, otherwise go to Step 7. "
33
- "Step 2. **Find a single dash**: check the character immediately after the prefix 'payout' or 'payment', if it is a dash, you should go to Step 3, otherwise go to Step 7.. "
34
- "Step 3. **Find digits and characters**: check if there is at least one digit or one character after the dash, if so, you should go to Step 4, otherwise go to Step 7.. "
35
- "Step 4. **Extract transaction id**: extract transaction id from the USER INPUT, then go to Step 5. "
36
- "Step 5. **Verify transaction id**: verify the extracted transaction id by checking if the USER INPUT contains exact the same text, if so, you should go to Step 6, otherwise go to Step 7. "
37
- "Step 6. It is a valid transaction id, when constructing the response, return the flag found as true. "
38
- "Step 7. It is not a valid transaction id, when constructing the response, return the flag found as false. "
39
- "To determine the transaction type, follow the rule below: "
40
- "There are two types of transactions: "
41
- "a. A transaction id starting with 'payout' indicates a payout transaction. "
42
- "b. A transaction id starting with 'payment' indicates a payment transaction. "
43
- "===>USER INPUT BEGINS"
44
- "{input}"
45
- "<===USER INPUT ENDS"
46
- "Respond with the following 4 parameters in JSON format: "
47
- "1. a mandatory flag named found, which indicates if a valid transaction id is found "
48
- "2. the transaction id named transaction_id if found "
49
- "3. the transaction type (in lower case) named transaction_type if found "
50
- "4. a mandatory explanation named justification which explains how you deduce transaction id and transaction type, don't make up explanation if no exact text appears in the USER INPUT. "
51
- "You must give answer in valid JSON format without any extra content"
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