Skip to content

Commit 1f27115

Browse files
committed
Make handleNonStreamingCall suspend and use chatAsync
Refactored `handleNonStreamingCall` to be a suspend function, enabling asynchronous operations. Replaced `chat` with `chatAsync` for non-blocking processing of chat requests, improving performance and scalability.
1 parent 43bf263 commit 1f27115

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

langchain4j-kotlin/src/main/kotlin/me/kpavlov/langchain4j/kotlin/service/AiServiceOrchestrator.kt

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ import dev.langchain4j.service.output.ServiceOutputParser
3131
import dev.langchain4j.service.tool.ToolServiceContext
3232
import dev.langchain4j.spi.services.TokenStreamAdapter
3333
import me.kpavlov.langchain4j.kotlin.ChatMemoryId
34+
import me.kpavlov.langchain4j.kotlin.model.chat.chatAsync
3435
import me.kpavlov.langchain4j.kotlin.service.ReflectionHelper.validateParameters
3536
import me.kpavlov.langchain4j.kotlin.service.ReflectionVariableResolver.asString
3637
import me.kpavlov.langchain4j.kotlin.service.ReflectionVariableResolver.findMemoryId
@@ -199,7 +200,7 @@ internal class AiServiceOrchestrator<T : Any>(
199200
}
200201

201202
@Suppress("LongParameterList")
202-
private fun handleNonStreamingCall(
203+
private suspend fun handleNonStreamingCall(
203204
returnType: Type,
204205
messages: MutableList<ChatMessage?>,
205206
toolServiceContext: ToolServiceContext,
@@ -235,7 +236,7 @@ internal class AiServiceOrchestrator<T : Any>(
235236
.parameters(parameters)
236237
.build()
237238

238-
var chatResponse = context.chatModel.chat(chatRequest)
239+
var chatResponse = context.chatModel.chatAsync(chatRequest)
239240

240241
AiServices.verifyModerationIfNeeded(moderationFuture)
241242

0 commit comments

Comments
 (0)