syedkhizarrayaz/BM-AI-Analysis-And-Alert-Prioritization-Agent
0
1uvicorn app:app --host 0.0.0.0 --port 8000 --reload2 3 4 5 6Local Dev Env Testing:7 8eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiJhZG1pbiIsImV4cCI6MTczMjA4MzIwNX0.KIXR5y5GH-fwA2acdXBAOEvgF9l58ZpRYUxvh5y6eWQ9 10token curl request:11curl -X 'POST' 'http://localhost:8000/api/ai-service/token' -H 'Content-Type: application/x-www-form-urlencoded' -d 'username=admin&password=admin'12 13 14email json api curl request:15curl -X POST "http://127.0.0.1:8000/api/ai-service/sendalertsemailjson" -H "Authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiJhZG1pbiIsImV4cCI6MTczMjAxMDg3Mn0.YyvlrZPrO7Oq7sIHwvk3ob31bqhycdxpahlxLtsWyJc" -H "Content-Type: application/json" -d '16{17 "to_emails": ["khizar.rayaz98@gmail.com"],18 "alert_details": {19 "AlertID": 1234,20 "FocusColumnValue": "457567",21 "STRCount": 5,22 "RevertedCount": 7,23 "TotalCount": 75,24 "CustomerName": "Jhon",25 "AccountNumber": "01212454788464",26 "TransactionID": 4578,27 "TransactionDate": "14/01/2025"28 }29}'30 31 32model prediction json api curl request:33curl -L -X 'POST' \34 'http://localhost:8000/api/ai-service/predicttransactionsjson' \35 -H 'Content-Type: application/json' \36 -H 'Authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiJhZG1pbiIsImV4cCI6MzUzMjA4NzYwNn0.oPjT4TjprsL9iJ4l8FJ_-sYz4QUlW4HqXSvaiBhRnvo' \37 -d '{38 "AlertID": 41680,39 "FocusColumnValue": "23410",40 "AlertScore": 90,41 "CreateDate": "6/10/2016",42 "KYCRiskCategoryValue": "High",43 "MatchDetails": "ID: 0023410|ID: 0023410|NO. OF DEPOSITS: 3|VALUE OF DEPOSITS: 3,150,000",44 "MatchInfoXML": " <ALERTMATCH><TRXNNO>025CHDP200160504</TRXNNO><DATE>16 Jan 2020</DATE><TIME>1:14PM</TIME><ACCOUNTNO>0251030023410038</ACCOUNTNO><TRXNTYPE>CASH DEPOSIT</TRXNTYPE><AMOUNT>1,000,000</AMOUNT><DRCR>Credit</DRCR><NARRATION>Cash Deposit</NARRATION><TRNXBRANCH>MULTAN BRANCH </TRNXBRANCH></ALERTMATCH><ALERTMATCH><TRXNNO>025CHDP200160008</TRXNNO><DATE>16 Jan 2020</DATE><TIME>5:17PM</TIME><ACCOUNTNO>0251030023410016</ACCOUNTNO><TRXNTYPE>CASH DEPOSIT</TRXNTYPE><AMOUNT>1,150,000</AMOUNT><DRCR>Credit</DRCR><NARRATION>Cash Deposit</NARRATION><TRNXBRANCH>MULTAN BRANCH </TRNXBRANCH></ALERTMATCH><ALERTMATCH><TRXNNO>025CHDP200160016</TRXNNO><DATE>16 Jan 2020</DATE><TIME>6:57PM</TIME><ACCOUNTNO>0251030023410016</ACCOUNTNO><TRXNTYPE>CASH DEPOSIT</TRXNTYPE><AMOUNT>1,000,000</AMOUNT><DRCR>Credit</DRCR><NARRATION>Cash Deposit</NARRATION><TRNXBRANCH>MULTAN BRANCH </TRNXBRANCH></ALERTMATCH>",45 "ScenarioName": "Structuring - Deposits",46 "title": "Selected for Reporting"47 }'48 49 analysis json api curl request:50 curl -L -X 'POST' 'http://localhost:8000/api/ai-service/generateanalysisjson' \51-H 'Content-Type: application/json' \52-H 'Authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiJhZG1pbiIsImV4cCI6MzUzMjUyMTE5NH0.notNUa2z6gT4a3pga4J7tKzzdSzTw5u3Q9ZIb7YETMY' \53-d '{54 "AlertID": 101,55 "FocusColumnValue": "valueA",56 "KYCMonthlyIncome": "4500",57 "KYCNoOfCredits": "10",58 "KYCNoOfDebits": "5",59 "KYCRiskCategoryValue": "High",60 "KYCValueOfCredits": "15000",61 "KYCValueOfDebits": "12000",62 "OccupationValue": "Engineer",63 "FilteredTransactions": "[{\"TransactionID\": 1, \"Amount\": 1000}, {\"TransactionID\": 2, \"Amount\": 1500}]",64 "ScenarioName": "SomeScenario",65 "STRCount": 2,66 "STRScenarioHistory": "[\"Scenario1\", \"Scenario2\"]"67}'68 69Docker Env Testing:70Run docker:71docker run -d -p 8000:8000 tms-acl-aml-aimodel:latest72 73eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiJhZG1pbiIsImV4cCI6MzUzMjUyMTE5NH0.notNUa2z6gT4a3pga4J7tKzzdSzTw5u3Q9ZIb7YETMY74 75 76token curl request:77curl -X 'POST' 'http://localhost:8000/api/ai-service/token' -H 'Content-Type: application/x-www-form-urlencoded' -d 'username=admin&password=admin'78 79model prediction json api curl request:80curl -L -X 'POST' \81 'http://localhost:8000/api/ai-service/predicttransactionsjson' \82 -H 'Content-Type: application/json' \83 -H 'Authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiJhZG1pbiIsImV4cCI6MzUzMjUyMTE5NH0.notNUa2z6gT4a3pga4J7tKzzdSzTw5u3Q9ZIb7YETMY' \84 -d '{85 "AlertID": 41680,86 "FocusColumnValue": "23410",87 "AlertScore": 90,88 "CreateDate": "6/10/2016",89 "KYCRiskCategoryValue": "High",90 "MatchDetails": "ID: 0023410|ID: 0023410|NO. OF DEPOSITS: 3|VALUE OF DEPOSITS: 3,150,000",91 "MatchInfoXML": " <ALERTMATCH><TRXNNO>025CHDP200160504</TRXNNO><DATE>16 Jan 2020</DATE><TIME>1:14PM</TIME><ACCOUNTNO>0251030023410038</ACCOUNTNO><TRXNTYPE>CASH DEPOSIT</TRXNTYPE><AMOUNT>1,000,000</AMOUNT><DRCR>Credit</DRCR><NARRATION>Cash Deposit</NARRATION><TRNXBRANCH>MULTAN BRANCH </TRNXBRANCH></ALERTMATCH><ALERTMATCH><TRXNNO>025CHDP200160008</TRXNNO><DATE>16 Jan 2020</DATE><TIME>5:17PM</TIME><ACCOUNTNO>0251030023410016</ACCOUNTNO><TRXNTYPE>CASH DEPOSIT</TRXNTYPE><AMOUNT>1,150,000</AMOUNT><DRCR>Credit</DRCR><NARRATION>Cash Deposit</NARRATION><TRNXBRANCH>MULTAN BRANCH </TRNXBRANCH></ALERTMATCH><ALERTMATCH><TRXNNO>025CHDP200160016</TRXNNO><DATE>16 Jan 2020</DATE><TIME>6:57PM</TIME><ACCOUNTNO>0251030023410016</ACCOUNTNO><TRXNTYPE>CASH DEPOSIT</TRXNTYPE><AMOUNT>1,000,000</AMOUNT><DRCR>Credit</DRCR><NARRATION>Cash Deposit</NARRATION><TRNXBRANCH>MULTAN BRANCH </TRNXBRANCH></ALERTMATCH>",92 "ScenarioName": "Structuring - Deposits",93 "title": "Selected for Reporting"94 }'95 96analysis json api curl request:97curl -L -X 'POST' 'http://localhost:8000/api/ai-service/generateanalysisjson' \98-H 'Content-Type: application/json' \99-d '{100 "AlertID": 101,101 "FocusColumnValue": "valueA",102 "KYCMonthlyIncome": "4500",103 "KYCNoOfCredits": "10",104 "KYCNoOfDebits": "5",105 "KYCRiskCategoryValue": "High",106 "KYCValueOfCredits": "15000",107 "KYCValueOfDebits": "12000",108 "OccupationValue": "Engineer",109 "FilteredTransactions": "[{\"TransactionID\": 1, \"Amount\": 1000}, {\"TransactionID\": 2, \"Amount\": 1500}]",110 "ScenarioName": "SomeScenario",111 "STRCount": 2,112 "STRScenarioHistory": "[\"Scenario1\", \"Scenario2\"]"113}'114 115email json api curl request:116curl -X POST "http://127.0.0.1:8000/api/ai-service/sendalertsemailjson" -H "Authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiJhZG1pbiIsImV4cCI6MzUzMjUyMTE5NH0.notNUa2z6gT4a3pga4J7tKzzdSzTw5u3Q9ZIb7YETMY" -H "Content-Type: application/json" -d '117{118 "to_emails": ["khizar.rayaz98@gmail.com"],119 "alert_details": {120 "AlertID": 1234,121 "FocusColumnValue": "457567",122 "STRCount": 5,123 "RevertedCount": 7,124 "TotalCount": 75,125 "CustomerName": "Jhon",126 "AccountNumber": "01212454788464",127 "TransactionID": 4578,128 "TransactionDate": "14/01/2025"129 }130}'131 132 133API Testing:134Passed:135 136Stress:137 138for i in {1..1000}139do140 curl -L -X 'POST' \141 'http://localhost:8000/api/ai-service/predicttransactionsjson' \142 -H 'Content-Type: application/json' \143 -H 'Authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiJhZG1pbiIsImV4cCI6MzUzMjUyMTE5NH0.notNUa2z6gT4a3pga4J7tKzzdSzTw5u3Q9ZIb7YETMY' \144 -d '{145 "AlertID": 41680,146 "FocusColumnValue": "23410",147 "AlertScore": 90,148 "CreateDate": "6/10/2016",149 "KYCRiskCategoryValue": "High",150 "MatchDetails": "ID: 0023410|ID: 0023410|NO. OF DEPOSITS: 3|VALUE OF DEPOSITS: 3,150,000",151 "MatchInfoXML": " <ALERTMATCH><TRXNNO>025CHDP200160504</TRXNNO><DATE>16 Jan 2020</DATE><TIME>1:14PM</TIME><ACCOUNTNO>0251030023410038</ACCOUNTNO><TRXNTYPE>CASH DEPOSIT</TRXNTYPE><AMOUNT>1,000,000</AMOUNT><DRCR>Credit</DRCR><NARRATION>Cash Deposit</NARRATION><TRNXBRANCH>MULTAN BRANCH </TRNXBRANCH></ALERTMATCH><ALERTMATCH><TRXNNO>025CHDP200160008</TRXNNO><DATE>16 Jan 2020</DATE><TIME>5:17PM</TIME><ACCOUNTNO>0251030023410016</ACCOUNTNO><TRXNTYPE>CASH DEPOSIT</TRXNTYPE><AMOUNT>1,150,000</AMOUNT><DRCR>Credit</DRCR><NARRATION>Cash Deposit</NARRATION><TRNXBRANCH>MULTAN BRANCH </TRNXBRANCH></ALERTMATCH><ALERTMATCH><TRXNNO>025CHDP200160016</TRXNNO><DATE>16 Jan 2020</DATE><TIME>6:57PM</TIME><ACCOUNTNO>0251030023410016</ACCOUNTNO><TRXNTYPE>CASH DEPOSIT</TRXNTYPE><AMOUNT>1,000,000</AMOUNT><DRCR>Credit</DRCR><NARRATION>Cash Deposit</NARRATION><TRNXBRANCH>MULTAN BRANCH </TRNXBRANCH></ALERTMATCH>",152 "ScenarioName": "Structuring - Deposits",153 "title": "Selected for Reporting"154 }'155done156 157Security invalid token test:158 159curl -L -X 'POST' \160 'http://localhost:8000/api/ai-service/predicttransactionsjson' \161 -H 'Content-Type: application/json' \162 -H 'Authorization: Bearer invalid_token' \163 -d '{164 "AlertID": 41680,165 "FocusColumnValue": "23410",166 "AlertScore": 90,167 "CreateDate": "6/10/2016",168 "KYCRiskCategoryValue": "High",169 "MatchDetails": "ID: 0023410|ID: 0023410|NO. OF DEPOSITS: 3|VALUE OF DEPOSITS: 3,150,000",170 "MatchInfoXML": " <ALERTMATCH><TRXNNO>025CHDP200160504</TRXNNO><DATE>16 Jan 2020</DATE><TIME>1:14PM</TIME><ACCOUNTNO>0251030023410038</ACCOUNTNO><TRXNTYPE>CASH DEPOSIT</TRXNTYPE><AMOUNT>1,000,000</AMOUNT><DRCR>Credit</DRCR><NARRATION>Cash Deposit</NARRATION><TRNXBRANCH>MULTAN BRANCH </TRNXBRANCH></ALERTMATCH><ALERTMATCH><TRXNNO>025CHDP200160008</TRXNNO><DATE>16 Jan 2020</DATE><TIME>5:17PM</TIME><ACCOUNTNO>0251030023410016</ACCOUNTNO><TRXNTYPE>CASH DEPOSIT</TRXNTYPE><AMOUNT>1,150,000</AMOUNT><DRCR>Credit</DRCR><NARRATION>Cash Deposit</NARRATION><TRNXBRANCH>MULTAN BRANCH </TRNXBRANCH></ALERTMATCH><ALERTMATCH><TRXNNO>025CHDP200160016</TRXNNO><DATE>16 Jan 2020</DATE><TIME>6:57PM</TIME><ACCOUNTNO>0251030023410016</ACCOUNTNO><TRXNTYPE>CASH DEPOSIT</TRXNTYPE><AMOUNT>1,000,000</AMOUNT><DRCR>Credit</DRCR><NARRATION>Cash Deposit</NARRATION><TRNXBRANCH>MULTAN BRANCH </TRNXBRANCH></ALERTMATCH>",171 "ScenarioName": "Structuring - Deposits",172 "title": "Selected for Reporting"173 }'174 175Security Missing token:176 177curl -L -X 'POST' \178 'http://localhost:8000/api/ai-service/predicttransactionsjson' \179 -H 'Content-Type: application/json' \180 -d '{181 "AlertID": 41680,182 "FocusColumnValue": "23410",183 "AlertScore": 90,184 "CreateDate": "6/10/2016",185 "KYCRiskCategoryValue": "High",186 "MatchDetails": "ID: 0023410|ID: 0023410|NO. OF DEPOSITS: 3|VALUE OF DEPOSITS: 3,150,000",187 "MatchInfoXML": " <ALERTMATCH><TRXNNO>025CHDP200160504</TRXNNO><DATE>16 Jan 2020</DATE><TIME>1:14PM</TIME><ACCOUNTNO>0251030023410038</ACCOUNTNO><TRXNTYPE>CASH DEPOSIT</TRXNTYPE><AMOUNT>1,000,000</AMOUNT><DRCR>Credit</DRCR><NARRATION>Cash Deposit</NARRATION><TRNXBRANCH>MULTAN BRANCH </TRNXBRANCH></ALERTMATCH><ALERTMATCH><TRXNNO>025CHDP200160008</TRXNNO><DATE>16 Jan 2020</DATE><TIME>5:17PM</TIME><ACCOUNTNO>0251030023410016</ACCOUNTNO><TRXNTYPE>CASH DEPOSIT</TRXNTYPE><AMOUNT>1,150,000</AMOUNT><DRCR>Credit</DRCR><NARRATION>Cash Deposit</NARRATION><TRNXBRANCH>MULTAN BRANCH </TRNXBRANCH></ALERTMATCH><ALERTMATCH><TRXNNO>025CHDP200160016</TRXNNO><DATE>16 Jan 2020</DATE><TIME>6:57PM</TIME><ACCOUNTNO>0251030023410016</ACCOUNTNO><TRXNTYPE>CASH DEPOSIT</TRXNTYPE><AMOUNT>1,000,000</AMOUNT><DRCR>Credit</DRCR><NARRATION>Cash Deposit</NARRATION><TRNXBRANCH>MULTAN BRANCH </TRNXBRANCH></ALERTMATCH>",188 "ScenarioName": "Structuring - Deposits",189 "title": "Selected for Reporting"190 }'191 192 193artillery run test.yml --record --key a9_7or5Eye3HRyWF2XYe5cbUA3gQRbwDO-N194 195 196Documentation Version 1.1197changed JSON Alert api request:198 199curl -L -X 'POST' \200 'http://localhost:8000/api/ai-service/predicttransactionsjson' \201 -H 'Content-Type: application/json' \202 -d '{203 "AlertID": 313268,204 "FocusColumnValue": "TC-2112025-3",205 "AlertScore": 90,206 "CreateDate": "2025-02-14T10:31:08",207 "riskLevel": "High",208 "MatchDetails": "{\"id\": 8, \"scenario\": \"AML06 - High velocity transaction-Tabby Card\", \"score\": 90, \"riskLevel\": \"High\"}",209 "MatchInfoJson": "[{\"ID\": \"TC-2112025-1\", \"ANNUAL INCOME\": 6000, \"AMOUNT\": 6500}]",210 "ScenarioName": "High velocity transaction-Tabby Card",211 "workflow": "Unassigned"212 }'213 214 215 Local LLM endpoint:216 http://localhost:8000/api/ai-service/generateanalysisjsonhybridtemplatellm217 218 {219 "AlertID": 22,220 "FilteredTransactions": "[{\"CUSTOMERID\": \"1234567\", \"IDENTITYNUMBERS\": \"A123456789\", \"LOANID\": \"LN12348675\", \"ACCOUNTID\": \"AC9876\", \"CREATEDDATE\": \"2025-08-25 00:00:00\", \"DISBURSEDAMOUNT\": 950000.0, \"ADDITIONALFIELD12\": 0.0, \"EXCESSAMOUNT\": 950000.0}]",221 "FocusColumnValue": "1234567",222 "KYCMonthlyIncome": "121",223 "KYCNoOfCredits": "Legal Info",224 "KYCNoOfDebits": "Business Purpose",225 "KYCRiskCategoryValue": "Additional Info",226 "KYCValueOfCredits": "Extra Info 1",227 "KYCValueOfDebits": "Extra Info 2",228 "OccupationValue": "Sole Proprietorship",229 "STRCount": 0,230 "STRScenarioHistory": "",231 "ScenarioName": "Unusually large installment"232}233 234Response:235{236 "status": 200,237 "message": "Success",238 "data": [239 {240 "AlertID": 22,241 "FocusColumnValue": "1234567",242 "analysis": "Initial Risk\n- Alerted Scenario / Rule ID: Unusually large installment\n\nTransaction Review\n- Transaction Data:\n[{\"CUSTOMERID\": \"1234567\", \"IDENTITYNUMBERS\": \"A123456789\", \"LOANID\": \"LN12348675\", \"ACCOUNTID\": \"AC9876\", \"CREATEDDATE\": \"2025-08-25 00:00:00\", \"DISBURSEDAMOUNT\": 950000.0, \"ADDITIONALFIELD12\": 0.0, \"EXCESSAMOUNT\": 950000.0}]\n\nResearch on Focus\n- KYC Profile:\nMonthly Income: 121\nOccupation: Sole Proprietorship\nRisk Category: Additional Info\nExpected Credits: Legal Info\nExpected Debits: Business Purpose\nCredit Value: Extra Info 1\nDebit Value: Extra Info 2\n\nHistory Related Cases\n- Alerts raised Previously: Alert ID: 22\n- STR raised Scenarios: \n\nAI Analysis:\nConclusion: Escalate the alert as it indicates an unusually large installment, which could be a red flag for potential suspicious activity or fraudulent behavior. Further investigation into the nature of this transaction and its context is necessary to determine if further action is required.\n\nRISK: HIGH\nReason: The unusual size of the installment suggests that there may be significant financial risk involved. This could indicate fraudulent activities such as money laundering, tax evasion, or other illicit means of obtaining funds. It is essential to investigate the nature of this transaction and its potential implications for both the individual and the organization.\n\nRecommendation: Further investigation into the nature of the transaction and its context is necessary to determine if further action is required. This may include reviewing additional documentation, conducting a thorough review of the customer's financial records, or consulting with legal experts to understand the potential risks associated with this transaction.",243 "response_time_ms": 0.0,244 "method": "hybrid_template_llm_cached",245 "model": "granite4:350m"246 }247 ]248}249 