lock gigachat api
This commit is contained in:
+4
-1
@@ -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(
|
||||
|
||||
Reference in New Issue
Block a user