package br.com.alura.roger.series.service;

import com.theokanning.openai.completion.CompletionRequest;
import com.theokanning.openai.service.OpenAiService;
import org.springframework.stereotype.Service;

@Service
public class ConsumerChatGPT {
    private static String token = System.getenv("OPEN_API_CHATGPT");

    public static String getTranslation(String text) {
        OpenAiService service = new OpenAiService(token);
        CompletionRequest request = CompletionRequest.builder()
                .model("gpt-3.5-turbo-instruct")
                .prompt("traduza para o português o texto: " + text)
                .maxTokens(1000)
                .temperature(0.7)
                .build();

        var response = service.createCompletion(request);
        return response.getChoices().get(0).getText();
    }
}

com.theokanning.openai.completion.CompletionRequest.builder
[((464, 702), 'com.theokanning.openai.completion.CompletionRequest.builder'), ((464, 677), 'com.theokanning.openai.completion.CompletionRequest.builder'), ((464, 643), 'com.theokanning.openai.completion.CompletionRequest.builder'), ((464, 610), 'com.theokanning.openai.completion.CompletionRequest.builder'), ((464, 540), 'com.theokanning.openai.completion.CompletionRequest.builder')]