1. build.gradle
// ChatGPT
implementation group: 'com.theokanning.openai-gpt3-java', name: 'service', version: '0.11.1'
implementation 'io.github.flashvayne:chatgpt-spring-boot-starter:1.0.0'
  1. application.yml
chatgpt:
  api-key: api-token-value
  1. chatgpt 연동하는 service class
import io.github.flashvayne.chatgpt.service.ChatgptService;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Service;

import java.util.Optional;

@Service
@RequiredArgsConstructor
@Slf4j
public class PaperSummaryService {

    private final ChatgptService chatgptService;

    @Async
    public String sendQuestion() {
        String prompt = "Summary in 2 lines \\n" + 요청내용;
        String responseAbstract = chatgptService.sendMessage(prompt);
        return responseAbstract;
    }
}

  1. 라이브러리에 포함되어있는 ChatgptProperties
package io.github.flashvayne.chatgpt.property;

import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.stereotype.Component;

@Component
@ConfigurationProperties(prefix = "chatgpt")
public class ChatgptProperties {

    //apiKey
    private String apiKey = "";

    private String model = "text-davinci-003";

    private Integer maxTokens = 300;

    private Double temperature = 0.0;

    private Double topP = 1.0;
    public String getApiKey() {
        return apiKey;
    }

    public void setApiKey(String apiKey) {
        this.apiKey = apiKey;
    }

    public String getModel() {
        return model;
    }

    public void setModel(String model) {
        this.model = model;
    }

    public Integer getMaxTokens() {
        return maxTokens;
    }

    public void setMaxTokens(Integer maxTokens) {
        this.maxTokens = maxTokens;
    }

    public Double getTemperature() {
        return temperature;
    }

    public void setTemperature(Double temperature) {
        this.temperature = temperature;
    }

    public Double getTopP() {
        return topP;
    }

    public void setTopP(Double topP) {
        this.topP = topP;
    }
}