Skip to content

Commit

Permalink
Merge pull request #64 from jkuznik/Task-51-Fix-RiskAssessement
Browse files Browse the repository at this point in the history
Task 51 fix risk assessement
  • Loading branch information
jkuznik authored Nov 30, 2024
2 parents 7911008 + fc90b41 commit 32cfcb5
Show file tree
Hide file tree
Showing 6 changed files with 31 additions and 24 deletions.
3 changes: 2 additions & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -44,5 +44,6 @@ jobs:
- name: Build and Run Tests
env:
OPENAI_API_KEY: ${{ secrets.OPENAI_API_KEY }}
OPENAI_API_KEY: ${{secrets.OPENAI_API_KEY}}
RISK_THRESHOLD: ${{secrets.RISK_THRESHOLD}}
run: mvn clean install
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
@Slf4j
class RiskAssessmentService {

public static final double RISK_THRESHOLD = 0.7;
public static final double RISK_THRESHOLD = Double.parseDouble(System.getenv("RISK_THRESHOLD"));
private final OpenAIClient openAIClient;

boolean assessRisk(DisasterAddDTO disasterAddDTO) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,18 +25,15 @@ public DisasterDTO createDisaster(DisasterAddDTO disasterAddDTO, String source)
Disaster disaster = mapper.mapDisasterAddDtoToDisaster(disasterAddDTO);
disaster.setSource(source);
//TODO: trzeba dopracować promt do czata bo przy obecnym trudno osiągnąć wynik pozwalający na uznanie zdarzenia za prawdziwe
// if (riskAssessment.assessRisk(disasterAddDTO)) {
// disaster.setStatus(DisasterStatus.ACTIVE);
// disasterRepository.save(disaster);
// generateAlert(disaster.getId());
// } else {
// disaster.setStatus(DisasterStatus.FAKE);
// disasterRepository.save(disaster);
// }

disaster.setStatus(DisasterStatus.ACTIVE);
disasterRepository.save(disaster);
generateAlert(disaster.getId());
// edit: tymczasowo można po prostu zmniejszyć wymagany wynik zwracany przez AI aby zdarzenie zakwalifikować jako ACTIVE
if (riskAssessment.assessRisk(disasterAddDTO)) {
disaster.setStatus(DisasterStatus.ACTIVE);
disasterRepository.save(disaster);
generateAlert(disaster.getId());
} else {
disaster.setStatus(DisasterStatus.FAKE);
disasterRepository.save(disaster);
}

return mapper.mapDisasterToDisasterDto(disaster);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,19 @@ public String createDisaster(Model model, @AuthenticationPrincipal AppUser userD
return "addDisaster";
}

disasterAlertFacade.createDisaster(disasterAddDTO, USER_AS_DISASTER_SOURCE);
redirectAttributes.addFlashAttribute("message", "Dodano zdarzenie");
DisasterDTO disasterDTO = disasterAlertFacade.createDisaster(disasterAddDTO, USER_AS_DISASTER_SOURCE);

if (DisasterStatus.FAKE.equals(disasterDTO.status())) {
String message = String.format("""
Zdarzenie zostało uznane za fałszywe.
Jeśli chcesz je aktywować skontatuj się z adminiastratorem i podaj id zgłoszenia %s.
""", disasterDTO.id());
redirectAttributes.addFlashAttribute("messageStatus", DisasterStatus.FAKE.toString());
redirectAttributes.addFlashAttribute("message", message);
} else {
redirectAttributes.addFlashAttribute("message", "Dodano zdarzenie");
}

return "redirect:/disasters/add";
}

Expand Down
4 changes: 2 additions & 2 deletions src/main/resources/application-prod.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,11 @@ spring:

ai:
openai:
api-key: "${{ secrets.OPENAI_API_KEY }}"
api-key: ${OPENAI_API_KEY}
chat:
options:
model: gpt-4o
temperature: 0.5
temperature: 1.0

server:
port: 8080
Expand Down
10 changes: 4 additions & 6 deletions src/main/resources/templates/fragments.html
Original file line number Diff line number Diff line change
Expand Up @@ -67,12 +67,10 @@

<div th:fragment="toast" class="toast rounded align-items-center border-0 position-fixed bottom-0 end-0 m-3 show"
role="alert" aria-live="assertive" aria-atomic="true" th:if="${message}">
<div class="toast-header">
<svg class="bd-placeholder-img rounded me-2" width="20" height="20" xmlns="http://www.w3.org/2000/svg"
aria-hidden="true" preserveAspectRatio="xMidYMid slice" focusable="false">
<rect width="100%" height="100%" fill="#007aff"/>
</svg>
<strong class="me-auto">Udało się!</strong>
<div class="toast-header"
th:classappend="${messageStatus != 'FAKE'} ? ' text-primary' : ' text-danger'">
<i th:class="${messageStatus != 'FAKE'} ? 'bi bi-balloon-heart-fill' : 'bi bi-exclamation-circle-fill'"></i>
<strong class="me-auto">Dodano zgłoszenie</strong>
<button type="button" class="btn-close" data-bs-dismiss="toast" aria-label="Close"></button>
</div>
<div class="d-flex text-secondary bg-light px-3 py-1 fw-light">
Expand Down

0 comments on commit 32cfcb5

Please sign in to comment.