lock gigachat api

This commit is contained in:
2026-07-29 21:51:12 +03:00
parent 4d9a6aa4d6
commit 6a77e0c668
@@ -8,6 +8,8 @@ import io.ktor.client.request.post
import io.ktor.client.request.setBody
import io.ktor.http.ContentType
import io.ktor.http.contentType
import kotlinx.coroutines.sync.Mutex
import kotlinx.coroutines.sync.withLock
import kotlinx.serialization.SerialName
import kotlinx.serialization.Serializable
import org.koin.core.annotation.Single
@@ -21,6 +23,7 @@ class GigaChatService(
private val tokenManager: GigaChatTokenManager,
private val httpClientFactory: HttpClientFactory
) : ChatService {
private val mutex = Mutex()
private val httpClient by lazy {
httpClientFactory.create(
BearerAuthProvider(
@@ -36,7 +39,7 @@ class GigaChatService(
)
}
override suspend fun getCompletion(userId: Long, messages: List<Message>): String {
override suspend fun getCompletion(userId: Long, messages: List<Message>): String = mutex.withLock {
val clientId = "vbox-$userId"
val staticSessionId = UUID.nameUUIDFromBytes(clientId.toByteArray()).toString()
val requestBody = GigaChatRequest(