-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #44 from tukcomCD2024/backend/feature/42-gpt-api-r…
…esponse-dto Backend/feature/42 gpt api response dto
- Loading branch information
Showing
12 changed files
with
164 additions
and
82 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
13 changes: 13 additions & 0 deletions
13
backend/src/main/java/com/isp/backend/domain/gpt/constant/ParsingConstants.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
package com.isp.backend.domain.gpt.constant; | ||
|
||
import java.util.List; | ||
|
||
public class ParsingConstants { | ||
public static final String DATE_REGEX = "(\\d{4}-\\d{2}-\\d{2})"; | ||
public static final String NEW_LINE_REGEX = "\n"; | ||
public static final String CURRENT_DATE = ""; | ||
public static final int BEGIN_INDEX = 3; | ||
public static final List<String> FILTER_STRINGS = List.of( | ||
"Message(role=assistant, content=", ")" | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
14 changes: 0 additions & 14 deletions
14
backend/src/main/java/com/isp/backend/domain/gpt/dto/QuestionRequestDTO.java
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
21 changes: 0 additions & 21 deletions
21
backend/src/main/java/com/isp/backend/domain/gpt/entity/GptScheduleDetail.java
This file was deleted.
Oops, something went wrong.
60 changes: 60 additions & 0 deletions
60
backend/src/main/java/com/isp/backend/domain/gpt/entity/GptScheduleParser.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
package com.isp.backend.domain.gpt.entity; | ||
|
||
import com.isp.backend.domain.gpt.constant.ParsingConstants; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.stereotype.Component; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
import java.util.regex.Matcher; | ||
import java.util.regex.Pattern; | ||
|
||
@RequiredArgsConstructor | ||
@Component | ||
public class GptScheduleParser { | ||
|
||
public List<GptSchedule> parseScheduleText(String scheduleText) { | ||
List<GptSchedule> schedules = new ArrayList<>(); | ||
Pattern pattern = Pattern.compile(ParsingConstants.DATE_REGEX); | ||
|
||
List<String> lines = List.of(scheduleText.split(ParsingConstants.NEW_LINE_REGEX)); | ||
List<String> currentScheduleDetail = new ArrayList<>(); | ||
String currentDate = ParsingConstants.CURRENT_DATE; | ||
|
||
for (String line : lines) { | ||
processLine(line, pattern, schedules, currentScheduleDetail, currentDate); | ||
} | ||
|
||
addScheduleIfNotEmpty(currentDate, schedules, currentScheduleDetail); | ||
|
||
return schedules; | ||
} | ||
|
||
private void processLine(String line, Pattern pattern, List<GptSchedule> schedules, List<String> currentScheduleDetail, String currentDate) { | ||
Matcher dateMatcher = pattern.matcher(line); | ||
|
||
if (dateMatcher.find()) { | ||
handleNewDate(currentDate, schedules, currentScheduleDetail, dateMatcher.group(1)); | ||
} else { | ||
handleNonDateLine(line, currentScheduleDetail); | ||
} | ||
} | ||
|
||
private void handleNewDate(String currentDate, List<GptSchedule> schedules, List<String> currentScheduleDetail, String newDate) { | ||
if (!currentDate.isEmpty()) { | ||
schedules.add(new GptSchedule(currentDate, currentScheduleDetail)); | ||
} | ||
} | ||
|
||
private void handleNonDateLine(String line, List<String> currentScheduleDetail) { | ||
if (!line.trim().isEmpty() && ParsingConstants.FILTER_STRINGS.stream().noneMatch(line::contains)) { | ||
currentScheduleDetail.add(line.trim().substring(ParsingConstants.BEGIN_INDEX)); // Remove leading index | ||
} | ||
} | ||
|
||
private void addScheduleIfNotEmpty(String currentDate, List<GptSchedule> schedules, List<String> currentScheduleDetail) { | ||
if (!currentDate.isEmpty()) { | ||
schedules.add(new GptSchedule(currentDate, currentScheduleDetail)); | ||
} | ||
} | ||
} |
10 changes: 0 additions & 10 deletions
10
backend/src/main/java/com/isp/backend/domain/gpt/mapper/GptMapper.java
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters