From 478abe6f2d24f968f1f66438fb949b38ded4ac47 Mon Sep 17 00:00:00 2001 From: Kim Jiyoon Date: Wed, 19 Jun 2024 23:59:29 +0900 Subject: [PATCH 1/2] =?UTF-8?q?hotfix:=20webclient=20=ED=83=80=EC=9E=84?= =?UTF-8?q?=EC=95=84=EC=9B=83=20=EC=97=B0=EC=9E=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/isp/backend/domain/gpt/config/WebClientConfig.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/backend/src/main/java/com/isp/backend/domain/gpt/config/WebClientConfig.java b/backend/src/main/java/com/isp/backend/domain/gpt/config/WebClientConfig.java index b78c3b53..72b4a361 100644 --- a/backend/src/main/java/com/isp/backend/domain/gpt/config/WebClientConfig.java +++ b/backend/src/main/java/com/isp/backend/domain/gpt/config/WebClientConfig.java @@ -17,8 +17,8 @@ public WebClient webClient() { HttpClient httpClient = HttpClient.create() .option(ChannelOption.CONNECT_TIMEOUT_MILLIS, 30000) .doOnConnected(conn -> conn - .addHandlerLast(new ReadTimeoutHandler(30)) - .addHandlerLast(new WriteTimeoutHandler(30))); + .addHandlerLast(new ReadTimeoutHandler(50)) + .addHandlerLast(new WriteTimeoutHandler(50))); return WebClient.builder() .clientConnector(new ReactorClientHttpConnector(httpClient)) .build(); From faa672242d1b47a1130b499167100aed36940dd0 Mon Sep 17 00:00:00 2001 From: Kim Jiyoon Date: Wed, 19 Jun 2024 23:59:42 +0900 Subject: [PATCH 2/2] =?UTF-8?q?hotfix:=20=ED=8C=8C=EC=8B=B1=20=EA=B3=BC?= =?UTF-8?q?=EC=A0=95=EC=97=90=EC=84=9C=20=EC=A2=8C=ED=91=9C=EA=B0=92?= =?UTF-8?q?=EA=B3=BC=20=EB=82=A0=EC=A7=9C=EB=A5=BC=20=EA=B5=AC=EB=B6=84?= =?UTF-8?q?=ED=95=98=EC=A7=80=20=EB=AA=BB=ED=95=98=EB=8A=94=20=EB=AC=B8?= =?UTF-8?q?=EC=A0=9C=20=ED=95=B4=EA=B2=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../backend/domain/gpt/config/GptConfig.java | 65 ++++++++------- .../domain/gpt/constant/ParsingConstants.java | 6 +- .../domain/gpt/entity/GptScheduleParser.java | 80 ++++++------------- 3 files changed, 62 insertions(+), 89 deletions(-) diff --git a/backend/src/main/java/com/isp/backend/domain/gpt/config/GptConfig.java b/backend/src/main/java/com/isp/backend/domain/gpt/config/GptConfig.java index f249989f..ecea151b 100644 --- a/backend/src/main/java/com/isp/backend/domain/gpt/config/GptConfig.java +++ b/backend/src/main/java/com/isp/backend/domain/gpt/config/GptConfig.java @@ -23,36 +23,36 @@ public class GptConfig { Please write the itinerary without using any special characters, only in plain text. I would like the format to be as follows: - For example - --- - 2024-02-06 - 1. Go to location 26.69549000, 127.87642000 - 2. See the place 26.69549000, 127.87642000 - 3. Eat the Lunch 26.69549000, 127.87642000 - 4. Go to location 26.69549000, 127.87642000 - 5. See the place 26.69549000, 127.87642000 - 6. Eat the dinner 26.69549000, 127.87642000 - 7. shopping 26.69549000, 127.87642000 + 아래는 예시니까 참고만 해줘. + + 2024.02.06 + - Go to location 26.69549000, 127.87642000 + - See the place 26.69549000, 127.87642000 + - Eat the Lunch 26.69549000, 127.87642000 + - Go to location 26.69549000, 127.87642000 + - See the place 26.69549000, 127.87642000 + - Eat the dinner 26.69549000, 127.87642000 + - shopping 26.69549000, 127.87642000 2024-02-07 - 1. Go to location 26.69549000, 127.87642000 - 2. See the place 26.69549000, 127.87642000 - 3. Eat the Lunch 26.69549000, 127.87642000 - 4. Go to location 26.69549000, 127.87642000 - 5. See the place 26.69549000, 127.87642000 - 6. Eat the dinner 26.69549000, 127.87642000 - 7. shopping 26.69549000, 127.87642000 + - Go to location 26.69549000, 127.87642000 + - See the place 26.69549000, 127.87642000 + - Eat the Lunch 26.69549000, 127.87642000 + - Go to location 26.69549000, 127.87642000 + - See the place 26.69549000, 127.87642000 + - Eat the dinner 26.69549000, 127.87642000 + - shopping 26.69549000, 127.87642000 2024-02-08 - 1. Go to location 26.69549000, 127.87642000 - 2. See the place 26.69549000, 127.87642000 - 3. Eat the Lunch 26.69549000, 127.87642000 - 4. Go to location 26.69549000, 127.87642000 - 5. See the place 26.69549000, 127.87642000 - 6. Eat the dinner 26.69549000, 127.87642000 - 7. shopping 26.69549000, 127.87642000 - --- + - Go to location 26.69549000, 127.87642000 + - See the place 26.69549000, 127.87642000 + - Eat the Lunch 26.69549000, 127.87642000 + - Go to location 26.69549000, 127.87642000 + - See the place 26.69549000, 127.87642000 + - Eat the dinner 26.69549000, 127.87642000 + - shopping 26.69549000, 127.87642000 + 너가 여행 일정을 만들 때 필요한 정보는 아래와 같아. 여행지: %s 이번 여행의 목적: %s 여행에서 꼭 하고 싶은 활동: %s @@ -61,11 +61,14 @@ public class GptConfig { 한국에 귀국하는 날짜: %s No need to say anything else, just plan your schedule right away. - Please create the result in Korean. + 날짜 형식은 반드시 0000.00.00 을 지켜줘 And only include schedule-related content in the schedule you're creating. - Do not add any information I haven't provided to you. - Under no circumstances should you include any activities other than traveling. Absolutely not. - 우리는 매일 점심과 저녁은 항상 식당에 가서 먹을거야. 반드시 실제로 존재하는 맛있고 유명한 식당으로 추천해줘 - 금액 정보는 알려주지마. 대신 다양한 경험을 할 수 있게 일정을 만들어줘. - 그리고 일정 옆에 장소의 위도 경도 좌표값 소수점 여덟자리까지 함께 작성해줘."""; + We will have lunch and dinner at restaurants every day. + Be sure to recommend real, delicious, and famous restaurants. + Instead, create an itinerary that allows for a variety of experiences. + Include the latitude and longitude coordinates of each place with eight decimal places next to the itinerary item. + 위에 예시로 적어둔 영어 문구는 "절대" 포함하지마. + 시간은 안적어줘도돼. + Please create the result in Korean."""; + } \ No newline at end of file diff --git a/backend/src/main/java/com/isp/backend/domain/gpt/constant/ParsingConstants.java b/backend/src/main/java/com/isp/backend/domain/gpt/constant/ParsingConstants.java index eb8746c2..dd27dcbc 100644 --- a/backend/src/main/java/com/isp/backend/domain/gpt/constant/ParsingConstants.java +++ b/backend/src/main/java/com/isp/backend/domain/gpt/constant/ParsingConstants.java @@ -3,13 +3,11 @@ import java.util.List; public class ParsingConstants { - public static final String DATE_REGEX = "(\\d{4}-\\d{2}-\\d{2})"; + 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 String COMMA = ", "; - public static final int BEGIN_INDEX = 3; public static final List FILTER_STRINGS = List.of( "Message(role=assistant, content=", ")" ); - public static final int GROUP_MATCH = 1; -} +} \ No newline at end of file diff --git a/backend/src/main/java/com/isp/backend/domain/gpt/entity/GptScheduleParser.java b/backend/src/main/java/com/isp/backend/domain/gpt/entity/GptScheduleParser.java index 64a06dc0..12248b16 100644 --- a/backend/src/main/java/com/isp/backend/domain/gpt/entity/GptScheduleParser.java +++ b/backend/src/main/java/com/isp/backend/domain/gpt/entity/GptScheduleParser.java @@ -14,71 +14,43 @@ public class GptScheduleParser { public List parseScheduleText(String scheduleText) { + System.out.println(scheduleText); List schedules = new ArrayList<>(); + Pattern datePattern = Pattern.compile(ParsingConstants.DATE_REGEX); + Pattern detailPattern = Pattern.compile("^-\\s*(.*?)(\\d+\\.\\d{1,8}),\\s*(\\d+\\.\\d{1,8})$"); + List lines = List.of(scheduleText.split(ParsingConstants.NEW_LINE_REGEX)); List currentScheduleDetail = new ArrayList<>(); - String currentDate = ParsingConstants.CURRENT_DATE; + String currentDate = ""; for (String line : lines) { - currentDate = processLine(line, currentDate, currentScheduleDetail, schedules); - } - - if (!currentDate.isEmpty()) { - addSchedule(schedules, currentDate, currentScheduleDetail); - } - - return schedules; - } - - private String processLine(String line, String currentDate, List currentScheduleDetail, List schedules) { - if (isDateLine(line)) { - if (!currentDate.isEmpty()) { - addSchedule(schedules, currentDate, currentScheduleDetail); - currentScheduleDetail.clear(); + Matcher dateMatcher = datePattern.matcher(line); + if (dateMatcher.find()) { + if (!currentDate.isEmpty() && !currentScheduleDetail.isEmpty()) { + schedules.add(new GptSchedule(currentDate, currentScheduleDetail)); + currentScheduleDetail = new ArrayList<>(); + } + currentDate = dateMatcher.group(0); + } else if (!line.trim().isEmpty()) { + Matcher detailMatcher = detailPattern.matcher(line.trim()); + if (detailMatcher.find()) { + String detail = detailMatcher.group(1).trim(); + Double latitude = formatCoordinate(Double.valueOf(detailMatcher.group(2))); + Double longitude = formatCoordinate(Double.valueOf(detailMatcher.group(3))); + Coordinate coordinate = new Coordinate(latitude, longitude); + currentScheduleDetail.add(new GptScheduleDetail(detail, coordinate)); + } } - return extractDate(line); - } else if (shouldProcessLine(line)) { - addDetail(line, currentScheduleDetail); } - return currentDate; - } - private boolean isDateLine(String line) { - Pattern datePattern = Pattern.compile(ParsingConstants.DATE_REGEX); - Matcher dateMatcher = datePattern.matcher(line); - return dateMatcher.find(); - } - - private String extractDate(String line) { - Pattern datePattern = Pattern.compile(ParsingConstants.DATE_REGEX); - Matcher dateMatcher = datePattern.matcher(line); - if (dateMatcher.find()) { - return dateMatcher.group(ParsingConstants.GROUP_MATCH); + if (!currentDate.isEmpty() && !currentScheduleDetail.isEmpty()) { + schedules.add(new GptSchedule(currentDate, currentScheduleDetail)); } - return ParsingConstants.CURRENT_DATE; - } - - private boolean shouldProcessLine(String line) { - return !line.trim().isEmpty() && ParsingConstants.FILTER_STRINGS.stream().noneMatch(line::contains); - } - - private void addDetail(String line, List currentScheduleDetail) { - Pattern detailPattern = Pattern.compile("^(?:\\d+\\.\\s*)?(.*?)(\\d+\\.\\d{1,8}),\\s*(\\d+\\.\\d{1,8})$"); - Matcher detailMatcher = detailPattern.matcher(line.trim()); - if (detailMatcher.find()) { - String detail = detailMatcher.group(1).trim(); - Double latitude = Double.valueOf(detailMatcher.group(2)); - Double longitude = Double.valueOf(detailMatcher.group(3)); - - String formattedLatitude = String.format("%.8f", latitude); - String formattedLongitude = String.format("%.8f", longitude); - Coordinate coordinate = new Coordinate(Double.parseDouble(formattedLatitude), Double.parseDouble(formattedLongitude)); - currentScheduleDetail.add(new GptScheduleDetail(detail, coordinate)); - } + return schedules; } - private void addSchedule(List schedules, String date, List details) { - schedules.add(new GptSchedule(date, details)); + private Double formatCoordinate(Double coordinate) { + return Double.valueOf(String.format("%.8f", coordinate)); } } \ No newline at end of file