package br.com.alura.screenmatch.service;

import br.com.alura.screenmatch.config.OpenAiConfig;
import com.theokanning.openai.completion.CompletionRequest;
import com.theokanning.openai.service.OpenAiService;

public class ConsultaChatGPT {

    public static String obterTraducao(String texto) {
        String apiKey = OpenAiConfig.getApiKey();
        OpenAiService service = new OpenAiService(apiKey);

        CompletionRequest requisicao = CompletionRequest.builder()
                .model("gpt-3.5-turbo-instruct")
                .prompt("traduza para o português o texto: " + texto)
                .maxTokens(1000)
                .temperature(0.7)
                .build();

        var resposta = service.createCompletion(requisicao);
        return resposta.getChoices().get(0).getText();
    }
}

com.theokanning.openai.completion.CompletionRequest.builder
[((446, 685), 'com.theokanning.openai.completion.CompletionRequest.builder'), ((446, 660), 'com.theokanning.openai.completion.CompletionRequest.builder'), ((446, 626), 'com.theokanning.openai.completion.CompletionRequest.builder'), ((446, 593), 'com.theokanning.openai.completion.CompletionRequest.builder'), ((446, 522), 'com.theokanning.openai.completion.CompletionRequest.builder')]