spring-ai
spring-ai copied to clipboard
Timout calling MoonshotChatModel.call()
Bug description timeout when calling OpenAI/MoonShot API org.springframework.web.client.ResourceAccessException: I/O error on POST request for "https://api.moonshot.cn/v1/chat/completions": timeout at org.springframework.web.client.DefaultRestClient$DefaultRequestBodyUriSpec.createResourceAccessException(DefaultRestClient.java:578) at org.springframework.web.client.DefaultRestClient$DefaultRequestBodyUriSpec.exchangeInternal(DefaultRestClient.java:501) at org.springframework.web.client.DefaultRestClient$DefaultRequestBodyUriSpec.retrieve(DefaultRestClient.java:463) at org.springframework.ai.moonshot.api.MoonshotApi.chatCompletionEntity(MoonshotApi.java:584) at org.springframework.ai.moonshot.MoonshotChatModel.lambda$call$0(MoonshotChatModel.java:140) at org.springframework.retry.support.RetryTemplate.doExecute(RetryTemplate.java:344) at org.springframework.retry.support.RetryTemplate.execute(RetryTemplate.java:217) at org.springframework.ai.moonshot.MoonshotChatModel.call(MoonshotChatModel.java:140) at org.springframework.ai.chat.model.ChatModel.call(ChatModel.java:33) at com.fisher.common.ai.service.impl.MoonshotAiServiceImpl.chat(MoonshotAiServiceImpl.java:27) at com.fisher.news.api.FinanceNewsApi.parseArticleToEvent(FinanceNewsApi.java:130) at com.fisher.news.api.FinanceNewsApi.getFinNewsEventByArticle(FinanceNewsApi.java:57) at com.fisher.news.service.impl.NewsFinEventServiceImpl.crawlerLatestNewsFinEvent(NewsFinEventServiceImpl.java:36) at com.fisher.job.news.NewsFinEventCrawlerProcessor.process(NewsFinEventCrawlerProcessor.java:39) at tech.powerjob.worker.core.tracker.task.light.LightTaskTracker.processTask(LightTaskTracker.java:211) at java.base/java.util.concurrent.FutureTask.run$$$capture(FutureTask.java:264) at java.base/java.util.concurrent.FutureTask.run(FutureTask.java) at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1136) at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:635) at java.base/java.lang.Thread.run(Thread.java:840) Caused by: java.net.SocketTimeoutException: timeout at okhttp3.internal.http2.Http2Stream$StreamTimeout.newTimeoutException(Http2Stream.kt:675) at okhttp3.internal.http2.Http2Stream$StreamTimeout.exitAndThrowIfTimedOut(Http2Stream.kt:684) at okhttp3.internal.http2.Http2Stream.takeHeaders(Http2Stream.kt:143) at okhttp3.internal.http2.Http2ExchangeCodec.readResponseHeaders(Http2ExchangeCodec.kt:96) at okhttp3.internal.connection.Exchange.readResponseHeaders(Exchange.kt:106) at okhttp3.internal.http.CallServerInterceptor.intercept(CallServerInterceptor.kt:79) at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.kt:109) at okhttp3.internal.connection.ConnectInterceptor.intercept(ConnectInterceptor.kt:34) at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.kt:109) at okhttp3.internal.cache.CacheInterceptor.intercept(CacheInterceptor.kt:95) at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.kt:109) at okhttp3.internal.http.BridgeInterceptor.intercept(BridgeInterceptor.kt:83) at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.kt:109) at okhttp3.internal.http.RetryAndFollowUpInterceptor.intercept(RetryAndFollowUpInterceptor.kt:76) at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.kt:109) at okhttp3.internal.connection.RealCall.getResponseWithInterceptorChain$okhttp(RealCall.kt:201) at okhttp3.internal.connection.RealCall.execute(RealCall.kt:154) at org.springframework.http.client.OkHttp3ClientHttpRequest.executeInternal(OkHttp3ClientHttpRequest.java:95) at org.springframework.http.client.AbstractStreamingClientHttpRequest.executeInternal(AbstractStreamingClientHttpRequest.java:70) at org.springframework.http.client.AbstractClientHttpRequest.execute(AbstractClientHttpRequest.java:66) at org.springframework.web.client.DefaultRestClient$DefaultRequestBodyUriSpec.exchangeInternal(DefaultRestClient.java:495) ... 18 common frames omitted
Environment Spring AI version: 1.0.0-SNAPSHOT Java version: JDK17 No use Vector and others.
Steps to reproduce MoonshotChatModel.call() .
Expected behavior Get the right data from MoonShot AI interface.
Minimal Complete Reproducible example MoonshotChatModel
This seems to be the same problem described in https://github.com/spring-projects/spring-ai/issues/1016, and happening when okhttp3 is in the classpath (resulting in Spring Boot using it as the implementation of RestClient).
Timeout can happen for various reasons, maybe the server was just too slow to respond. You can provide a RestClient.Builder bean with custom timeout settings to increase the default timeout.
closing this and will track in #1016