Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUG] WebClient GPT API 호출 시, 예외 발생 #37

Open
1 of 3 tasks
PgmJun opened this issue Nov 10, 2023 · 3 comments
Open
1 of 3 tasks

[BUG] WebClient GPT API 호출 시, 예외 발생 #37

PgmJun opened this issue Nov 10, 2023 · 3 comments
Assignees
Labels
🐞 Bug 버그 발생

Comments

@PgmJun
Copy link
Member

PgmJun commented Nov 10, 2023

Description 📝

GPT API KEY가 존재하는데, Key가 존재하지 않는다는 오류가 발생함

To-Do ☑️

  • GPT API 정상적으로 호출하도록 문제 해결
  • 자세한 원인 분석해서 근본적인 문제 해결
    • WebClient 사용하지 않고 openai-gpt3-java:client 라이브러리 사용

버그 로그 🧾

스크린샷 2023-11-10 오후 11 32 30

스크린샷 📸

스크린샷 2023-11-10 오후 11 33 07

스크린샷 2023-11-10 오후 11 32 07
@PgmJun PgmJun added the 🐞 Bug 버그 발생 label Nov 10, 2023
@PgmJun PgmJun self-assigned this Nov 10, 2023
@PgmJun
Copy link
Member Author

PgmJun commented Nov 10, 2023

문제 해결 로그1.

즐겨찾기 기능을 위해 구현한 favorite 패키지를 삭제했더니 정상적으로 작동한다.
왜지? 연결된 로직이 없는데..

@PgmJun
Copy link
Member Author

PgmJun commented Nov 10, 2023

문제 해결 로그2.

@Table(name = "FAVORITE")
@Entity
@NoArgsConstructor(access = AccessLevel.PROTECTED)
@AllArgsConstructor(access = AccessLevel.PRIVATE)
@Builder(access = AccessLevel.PRIVATE)
@Getter
public class Favorite extends BaseEntity {

// ..생략
    @Enumerated(EnumType.STRING)
    @Column(name = "FUNCTION_TYPE", nullable = false, length = 30)
    private GptFunction functionType;

// ..생략

Favorite 객체가 존재하면 위와 같은 문제가 발생한다.
원인은 Favorite 객체에 있는 GptFunction 때문이었다.

이 객체가 왜 문제를 발생시키는 지 알아봐야겠다.

@PgmJun
Copy link
Member Author

PgmJun commented Nov 10, 2023

문제 해결 로그3.

문제 해결을 완료했다.

package com.dongyang.core.domain.gpt.constant;

import static com.dongyang.core.global.config.gpt.GptConfig.GPT_ADD_COMMENT_MODEL;
import static com.dongyang.core.global.config.gpt.GptConfig.GPT_DEFAULT_MODEL;
import static com.dongyang.core.global.config.gpt.GptConfig.GPT_RECOMMEND_VARIABLE_NAME_MODEL;
import static com.dongyang.core.global.config.gpt.GptConfig.GPT_REFACTOR_CODE_MODEL;

import lombok.AccessLevel;
import lombok.AllArgsConstructor;
import lombok.Getter;

@Getter
@AllArgsConstructor(access = AccessLevel.PRIVATE)
public enum GptFunction {
    RECOMMEND_VARIABLE_NAME(
            "당신은 %s 언어 변수명 추천 전문가이다. 단어를 입력받으면 그 단어의 영어 변수명을 10개 생성하여 출력해라. 만약 %s 라는 언어가 존재하지 않는다면 X를 출력해라",
            GPT_RECOMMEND_VARIABLE_NAME_MODEL, 0.2, 100),
    ADD_COMMENT(
            "당신은 %s 언어로 작성된 코드를 받으면 이를 분석하여 설명 주석을 달아주는 코드 전문가이다. 만약 받은 코드가 %s 언어의 문법이 아니면 X를 출력하고, 받은 코드가 %s 언어로 작성된 것이 맞다면 각 코드 라인의 윗줄에 코드 기능 설명을 언어 형식에 맞는 주석으로 달아라.",
            GPT_ADD_COMMENT_MODEL, 0.4, 2000),
// .. 생략
@AllArgsConstructor(access = AccessLevel.PRIVATE)
@Getter
public class GptRequest {

    @Schema(description = "요청 기능 선택", examples = {"ADD_COMMENT", "RECOMMEND_VARIABLE_NAME", "REFACTOR_CODE"})
    @NotNull(message = "{gpt.function.notNull}")
    private GptFunction function;
// .. 생략

문제의 중심인 GptFunction Enum객체는 원래 DTO인 GptRequest을 통해 유저 요청의 입력값으로 받아졌다.

그러던 중 JPA Entity 객체에서 GptFunction 클래스를 @Column으로 설정해서 사용하자, 전혀 관련없는 위의 오류가 발생하기 시작했다.

결국은 @entity@column으로 설정된 Enum 객체 GptFunction을 DTO에서 사용 시, 오류가 발생된 것으로 추정되는 문제인데,
진짜 무슨 이유때문에 발생한 문제인지 아직도 이해할 수 없다..


해결법

public enum FunctionType {
    RECOMMEND_VARIABLE_NAME,
    ADD_COMMENT,
    REFACTOR_CODE,
    SOLVE_ALGORITHM

}

우선은 GptFunction 대신 FunctionType이라는 객체를
Entity 객체 Favorite에서 @Column으로 두어 사용하도록 했다.
사실상 기능 이름만 필요하기 때문이다.

근데 이렇게 되면 Function이 추가되면, FunctionType과 GptFunction 두 개를 수정해야하기 때문에 이렇게 구현하면 안 될 것 같아 해결책을 더 찾아볼 생각이다.

PgmJun added a commit that referenced this issue Nov 10, 2023
PgmJun added a commit that referenced this issue Nov 10, 2023
PgmJun added a commit that referenced this issue Nov 11, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🐞 Bug 버그 발생
Projects
None yet
Development

No branches or pull requests

1 participant