Skip to content

Commit 42c8026

Browse files
committed
fix: fix server timeout issue
1 parent 8c8c6b9 commit 42c8026

File tree

3 files changed

+10
-2
lines changed

3 files changed

+10
-2
lines changed

llm-modules/openai/src/main/kotlin/cc/unitmesh/openai/OpenAiProvider.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ class OpenAiProvider(var apiKey: String, var apiHost: String? = null) : LlmProvi
5656
var result = ""
5757
openai.streamChatCompletion(request)
5858
.blockingForEach { response ->
59-
val completion = response.choices[0].message
59+
val completion = response.choices?.get(0)?.message
6060
if (completion != null && completion.content != null) {
6161
result += completion.content
6262
}

server/src/main/kotlin/cc/unitmesh/cf/presentation/ChatController.kt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,12 @@ import org.springframework.http.ResponseEntity
2121
import org.springframework.stereotype.Controller
2222
import org.springframework.web.bind.annotation.PostMapping
2323
import org.springframework.web.bind.annotation.RequestBody
24+
import org.springframework.web.bind.annotation.RestController
2425
import org.springframework.web.servlet.mvc.method.annotation.StreamingResponseBody
2526
import java.io.IOException
2627

2728

28-
@Controller
29+
@RestController
2930
class ChatController(
3031
val feFlow: FEWorkflow,
3132
val codeFlow: CodeInterpreterWorkflow,
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,24 @@
11
package cc.unitmesh.cf.presentation.config
22

33
import org.springframework.context.annotation.Configuration
4+
import org.springframework.scheduling.annotation.EnableAsync
5+
import org.springframework.web.servlet.config.annotation.AsyncSupportConfigurer
46
import org.springframework.web.servlet.config.annotation.CorsRegistry
57
import org.springframework.web.servlet.config.annotation.EnableWebMvc
68
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer
79

810
@Configuration
911
@EnableWebMvc
12+
@EnableAsync
1013
class WebConfig : WebMvcConfigurer {
1114
override fun addCorsMappings(registry: CorsRegistry) {
1215
registry.addMapping("/**")
1316
.allowedMethods("*")
1417
.allowedOrigins("*")
1518
.allowedHeaders("*")
1619
}
20+
21+
override fun configureAsyncSupport(configurer: AsyncSupportConfigurer) {
22+
configurer.setDefaultTimeout(-1)
23+
}
1724
}

0 commit comments

Comments
 (0)