package br.com.alura.desafioJPA.Service;
import com.theokanning.openai.completion.CompletionRequest; import com.theokanning.openai.service.OpenAiService;
public class ConsultaChatGPT { public static String obterInformacao(String texto) { OpenAiService service = new OpenAiService(System.getenv("OPENAI_APIKEY"));
CompletionRequest requisicao = CompletionRequest.builder()
.model(""gpt-3.5-turbo-instruct"")
.prompt("me fale sobre o artista:" + texto)
.maxTokens(1000)
.temperature(0.7)
.build();
var resposta = service.createCompletion(requisicao);
return resposta.getChoices().get(0).getText();
}
} java.lang.NullPointerException: OpenAI token required at java.base/java.util.Objects.requireNonNull(Objects.java:233) ~[na:na] at com.theokanning.openai.service.AuthenticationInterceptor.(AuthenticationInterceptor.java:18) ~[service-0.14.0.jar:na] at com.theokanning.openai.service.OpenAiService.defaultClient(OpenAiService.java:396) ~[service-0.14.0.jar:na] at com.theokanning.openai.service.OpenAiService.(OpenAiService.java:78) ~[service-0.14.0.jar:na] at com.theokanning.openai.service.OpenAiService.(OpenAiService.java:67) ~[service-0.14.0.jar:na] at br.com.alura.desafioJPA.Service.ConsultaChatGPT.obterInformacao(ConsultaChatGPT.java:8) ~[classes/:na] at br.com.alura.desafioJPA.Principal.Principal.pesquisarSobreUmArtista(Principal.java:146) ~[classes/:na] at br.com.alura.desafioJPA.Principal.Principal.exibeMenu(Principal.java:64) ~[classes/:na] at br.com.alura.desafioJPA.DesafioJpaApplication.run(DesafioJpaApplication.java:24) ~[classes/:na] at org.springframework.boot.SpringApplication.lambda$callRunner$5(SpringApplication.java:790) ~[spring-boot-3.2.3.jar:3.2.3] at org.springframework.util.function.ThrowingConsumer$1.acceptWithException(ThrowingConsumer.java:83) ~[spring-core-6.1.4.jar:6.1.4] at org.springframework.util.function.ThrowingConsumer.accept(ThrowingConsumer.java:60) ~[spring-core-6.1.4.jar:6.1.4] at org.springframework.util.function.ThrowingConsumer$1.accept(ThrowingConsumer.java:88) ~[spring-core-6.1.4.jar:6.1.4] at org.springframework.boot.SpringApplication.callRunner(SpringApplication.java:798) ~[spring-boot-3.2.3.jar:3.2.3] at org.springframework.boot.SpringApplication.callRunner(SpringApplication.java:789) ~[spring-boot-3.2.3.jar:3.2.3] at org.springframework.boot.SpringApplication.lambda$callRunners$3(SpringApplication.java:774) ~[spring-boot-3.2.3.jar:3.2.3] at java.base/java.util.stream.ForEachOps$ForEachOp$OfRef.accept(ForEachOps.java:183) ~[na:na] at java.base/java.util.stream.SortedOps$SizedRefSortingSink.end(SortedOps.java:357) ~[na:na] at java.base/java.util.stream.AbstractPipeline.copyInto(AbstractPipeline.java:510) ~[na:na] at java.base/java.util.stream.AbstractPipeline.wrapAndCopyInto(AbstractPipeline.java:499) ~[na:na] at java.base/java.util.stream.ForEachOps$ForEachOp.evaluateSequential(ForEachOps.java:150) ~[na:na] at java.base/java.util.stream.ForEachOps$ForEachOp$OfRef.evaluateSequential(ForEachOps.java:173) ~[na:na] at java.base/java.util.stream.AbstractPipeline.evaluate(AbstractPipeline.java:234) ~[na:na] at java.base/java.util.stream.ReferencePipeline.forEach(ReferencePipeline.java:596) ~[na:na] at org.springframework.boot.SpringApplication.callRunners(SpringApplication.java:774) ~[spring-boot-3.2.3.jar:3.2.3] at org.springframework.boot.SpringApplication.run(SpringApplication.java:341) ~[spring-boot-3.2.3.jar:3.2.3] at org.springframework.boot.SpringApplication.run(SpringApplication.java:1354) ~[spring-boot-3.2.3.jar:3.2.3] at org.springframework.boot.SpringApplication.run(SpringApplication.java:1343) ~[spring-boot-3.2.3.jar:3.2.3] at br.com.alura.desafioJPA.DesafioJpaApplication.main(DesafioJpaApplication.java:18) ~[classes/:na]``