You signed in with another tab or window.
Reload
to refresh your session.
You signed out in another tab or window.
Reload
to refresh your session.
You switched accounts on another tab or window.
Reload
to refresh your session.
By clicking “Sign up for GitHub”, you agree to our
terms of service
and
privacy statement
. We’ll occasionally send you account related emails.
Already on GitHub?
Sign in
to your account
使用流式客户端时报错: Exception in thread "OkHttp Dispatcher" java.lang.NoSuchFieldError: instance
使用流式客户端时报错: Exception in thread "OkHttp Dispatcher" java.lang.NoSuchFieldError: instance
retroxz
opened this issue
Apr 19, 2024
· 0 comments
使用流式客户端时报错: Exception in thread "OkHttp Dispatcher" java.lang.NoSuchFieldError: instance
猜测原因可能是OkHttp的依赖版本问题 请问应该使用哪个版本的OkHttp
maven依赖
<!-- openai-java -->
<dependency>
<groupId>com.unfbx</groupId>
<artifactId>chatgpt-java</artifactId>
<version>1.1.5</version>
</dependency>
<!-- okhttp -->
<dependency>
<groupId>com.squareup.okhttp3</groupId>
<artifactId>okhttp</artifactId>
<version>4.5.0</version>
</dependency>
<dependency>
<groupId>com.squareup.okio</groupId>
<artifactId>okio</artifactId>
<version>3.9.0</version>
</dependency>
//国内访问需要做代理,国外服务器不需要
Proxy proxy = new Proxy(Proxy.Type.HTTP, new InetSocketAddress("127.0.0.1", 10809));//代理ip,端口
OkHttpClient okHttpClient = new OkHttpClient
.Builder()
//自定义代理
.proxy(proxy)
.connectTimeout(30, TimeUnit.SECONDS)//自定义超时时间
.writeTimeout(30, TimeUnit.SECONDS)//自定义超时时间
.readTimeout(30, TimeUnit.SECONDS)//自定义超时时间
.build();
OpenAiStreamClient openAiClient = OpenAiStreamClient.builder()
.apiKey(Arrays.asList(OPEN_AI_KEY))
.okHttpClient(okHttpClient)
.build();
ContentKeywordsPrompt prompt = new ContentKeywordsPrompt();
prompt.setContent("你好");
log.info("本次提示词: \n {}", prompt.build());
//聊天模型:gpt-3.5
Message message = Message.builder().role(Message.Role.USER).content(prompt.build()).build();
ChatCompletion chatCompletion = ChatCompletion.builder().messages(Arrays.asList(message)).build();
ConsoleEventSourceListener eventSourceListener = new ConsoleEventSourceListener();
openAiClient.streamChatCompletion(chatCompletion, eventSourceListener);
CountDownLatch countDownLatch = new CountDownLatch(1);
try {
countDownLatch.await();
} catch (InterruptedException e) {
e.printStackTrace();
Exception in thread "OkHttp Dispatcher" java.lang.NoSuchFieldError: instance
at okhttp3.internal.sse.RealEventSource.processResponse(RealEventSource.java:77)
at okhttp3.internal.sse.RealEventSource.onResponse(RealEventSource.java:56)
at okhttp3.internal.connection.RealCall$AsyncCall.run(RealCall.kt:504)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
at java.lang.Thread.run(Thread.java:748)