Olá Rodrigo, estou com esse erro:
Exception in thread "main" com.theokanning.openai.OpenAiHttpException: The model `gpt-4` does not exist or you do not have access to it. Learn more: https://help.openai.com/en/articles/7102672-how-can-i-access-gpt-4.
at com.theokanning.openai.service.OpenAiService.execute(OpenAiService.java:522)
at com.theokanning.openai.service.OpenAiService.createChatCompletion(OpenAiService.java:148)
at apilibrary.msapilibraryopenai.TestaIntegracao.main(TestaIntegracao.java:31)
Caused by: retrofit2.adapter.rxjava2.HttpException: HTTP 404 at retrofit2.adapter.rxjava2.BodyObservable$BodyObserver.onNext(BodyObservable.java:57) at retrofit2.adapter.rxjava2.BodyObservable$BodyObserver.onNext(BodyObservable.java:38) at retrofit2.adapter.rxjava2.CallExecuteObservable.subscribeActual(CallExecuteObservable.java:48) at io.reactivex.Observable.subscribe(Observable.java:10151) at retrofit2.adapter.rxjava2.BodyObservable.subscribeActual(BodyObservable.java:35) at io.reactivex.Observable.subscribe(Observable.java:10151) at io.reactivex.internal.operators.observable.ObservableSingleSingle.subscribeActual(ObservableSingleSingle.java:35) at io.reactivex.Single.subscribe(Single.java:2517) at io.reactivex.Single.blockingGet(Single.java:2001) at com.theokanning.openai.service.OpenAiService.execute(OpenAiService.java:513) ... 2 more
segue o código:
public static void main(String[] args) {
var user = "Gere 5 produtos";
var system = "Você é um gerador de produtos ficticios para um ecommerce e deve gerar apenas o nome dos produtos";
var chave = System.getenv("OPENAI_API_KEY");
var service = new OpenAiService(chave);
var completionRequest = ChatCompletionRequest
.builder()
.model("gpt-4")
.messages(Arrays.asList(
new ChatMessage(ChatMessageRole.USER.value(), user),
new ChatMessage(ChatMessageRole.SYSTEM.value(), system)
))
.build();
service
.createChatCompletion(completionRequest)
.getChoices()
.forEach(c -> System.out.println(c.getMessage().getContent()));
}