|
1 | 1 | package com.aiman.api.service; |
2 | 2 |
|
3 | | -// import org.springframework.ai.chat.client.ChatClient; |
| 3 | +import org.springframework.ai.chat.client.ChatClient; |
4 | 4 | import org.springframework.stereotype.Service; |
5 | 5 | import java.time.LocalDateTime; |
6 | 6 | import java.util.Map; |
7 | 7 | @Service |
8 | 8 | public class RiskAssessmentService { |
9 | 9 |
|
10 | | - // private final ChatClient chatClient; |
| 10 | + private final ChatClient chatClient; |
11 | 11 |
|
12 | | - // public RiskAssessmentService(ChatClient.Builder builder) { |
13 | | - // this.chatClient = builder.build(); |
14 | | - // } |
| 12 | + public RiskAssessmentService(ChatClient.Builder builder) { |
| 13 | + this.chatClient = builder.build(); |
| 14 | + } |
15 | 15 |
|
16 | 16 | public AssessmentResult analyze(String nationalId, String ip, String userAgent) { |
17 | | - // String userPromptTemplate = """ |
18 | | - // Evaluate the security risk of this Saudi Nafath login attempt: |
19 | | - // - National ID: {id} |
20 | | - // - Origin IP: {ip} |
21 | | - // - Device: {ua} |
22 | | - // - Time: {time} |
| 17 | + String userPromptTemplate = """ |
| 18 | + Evaluate the security risk of this Saudi Nafath login attempt: |
| 19 | + - National ID: {id} |
| 20 | + - Origin IP: {ip} |
| 21 | + - Device: {ua} |
| 22 | + - Time: {time} |
23 | 23 | |
24 | | - // Return JSON only: { "score": 0.0-1.0, "status": "SAFE|CAUTION|BLOCK", "reason": "string" } |
25 | | - // """; |
26 | | - |
27 | | - // return chatClient.prompt() |
28 | | - // .user(u -> u.text(userPromptTemplate) |
29 | | - // .params(Map.of( |
30 | | - // "id", nationalId, |
31 | | - // "ip", ip, |
32 | | - // "ua", userAgent, |
33 | | - // "time", LocalDateTime.now().toString() |
34 | | - // ))) |
35 | | - // .call() |
36 | | - // .entity(AssessmentResult.class); |
37 | | - |
38 | | - // Mock Assesment begin |
39 | | - double score = Math.random(); |
40 | | - String status = (score > 0.9) ? "BLOCK" : "SAFE"; |
41 | | - return new AssessmentResult(score, status, "Mocked AI Assessment for testing"); |
42 | | - // Mock Assesment end |
| 24 | + Return JSON only: { "score": 0.0-1.0, "status": "SAFE|CAUTION|BLOCK", "reason": "string" } |
| 25 | + """; |
| 26 | + |
| 27 | + return chatClient.prompt() |
| 28 | + .user(u -> u.text(userPromptTemplate) |
| 29 | + .params(Map.of( |
| 30 | + "id", nationalId, |
| 31 | + "ip", ip, |
| 32 | + "ua", userAgent, |
| 33 | + "time", LocalDateTime.now().toString() |
| 34 | + ))) |
| 35 | + .call() |
| 36 | + .entity(AssessmentResult.class); |
| 37 | + |
| 38 | + // // Mock Assesment begin |
| 39 | + // double score = Math.random(); |
| 40 | + // String status = (score > 0.9) ? "BLOCK" : "SAFE"; |
| 41 | + // return new AssessmentResult(score, status, "Mocked AI Assessment for testing"); |
| 42 | + // // Mock Assesment end |
43 | 43 |
|
44 | 44 | } |
45 | 45 |
|
|
0 commit comments