package com.example.demo.service;

import com.theokanning.openai.completion.CompletionRequest;
import com.theokanning.openai.service.OpenAiService;

public class ConsultaChatGpt {
  public static String obterTraducao(String texto) {
    OpenAiService service = new OpenAiService(System.getenv("OPENAI_APIKEY"));

    CompletionRequest requisicao = CompletionRequest.builder()
        .model("text-davinci-003")
        .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
[((357, 555), 'com.theokanning.openai.completion.CompletionRequest.builder'), ((357, 537), 'com.theokanning.openai.completion.CompletionRequest.builder'), ((357, 510), 'com.theokanning.openai.completion.CompletionRequest.builder'), ((357, 484), 'com.theokanning.openai.completion.CompletionRequest.builder'), ((357, 420), 'com.theokanning.openai.completion.CompletionRequest.builder')]