openai-java
openai-java copied to clipboard
Class Not found okhttp3/Interceptor
"Caused by: java.lang.NoClassDefFoundError: okhttp3/Interceptor"
Whenever I try to call OpenAiService. I seem to have tried everything to ensure okhttp3 is properly on my system.
Is there a specific troubleshooting strategy I should follow. I have the gradle dependencies for okhttp3 & openai-gpt3 setup:
implementation 'com.squareup.okhttp3:okhttp:4.10.0'
implementation 'com.squareup.okhttp3:logging-interceptor:4.10.0'
implementation 'com.theokanning.openai-gpt3-java:api:0.11.1'
implementation 'com.theokanning.openai-gpt3-java:service:0.11.1'
implementation 'com.theokanning.openai-gpt3-java:client:0.11.1'
Here is my apiCaller class, however I doubt this is causing the issue because its a failure to find class error, and nothing to do with the outbound HTTP call. No HTTP request should be made at the point of the error.
class apiCaller {
static String token = ("REDACTED API KEY");
public static String generateCompletion(String prompt) {
OpenAiService service = new OpenAiService(token);
CompletionRequest completionRequest = CompletionRequest.builder()
.model("text-davinci-003")
.prompt(prompt)
.echo(false)
.n(1)
.maxTokens(200)
.build();
var response = service.createCompletion(completionRequest).getChoices().get(0).getText();
if (response != null) {
return response.toString();
} else {
return ("OpenAI function failed to provide a response to your message.");
}
}
I'm using IntelliJ to build my final jar file. Let me know if any of y'all may need any more info.
Suggestion as I'm not that familiar w/ okhttp3 and Interceptors, but do you have to @Override public response in your own class and then addInterceptor(class) to the service?
Hey! Facing this problem as well... were you able to find a solution?
It was a while ago, but it had something to do with how I had my dependencies set up in my final package.
Specifically, I was creating a Minecraft plugin that would build into a .jar file. I would use WinRAR to peak into my jar file to test to see how my dependencies and included code would be included.
I just kind of experimented until my theokanning packages were included properly.
On Tue, Oct 10, 2023 at 7:51 PM Amber Morris @.***> wrote:
Hey! Facing this problem as well... were you able to find a solution?
— Reply to this email directly, view it on GitHub https://github.com/TheoKanning/openai-java/issues/207#issuecomment-1756667943, or unsubscribe https://github.com/notifications/unsubscribe-auth/AHQI6FIGQJARUNQG3KJWEX3X6YCTXAVCNFSM6AAAAAAWGBGW4CVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMYTONJWGY3DOOJUGM . You are receiving this because you authored the thread.Message ID: @.***>