use ultra model

This commit is contained in:
2026-09-08 21:20:31 +03:00
parent 699c1cfe0b
commit ab54df2faf
6 changed files with 28 additions and 7 deletions
@@ -13,6 +13,7 @@ import kotlinx.coroutines.sync.withLock
import kotlinx.serialization.SerialName
import kotlinx.serialization.Serializable
import org.koin.core.annotation.Single
import ru.shadowsparky.backend.data.EnvFetcher
import ru.shadowsparky.chat.backend.domain.ChatService
import ru.shadowsparky.chat.domain.Message
import ru.shadowsparky.http.domain.HttpClientFactory
@@ -21,7 +22,9 @@ import java.util.UUID
@Single
class GigaChatService(
private val tokenManager: GigaChatTokenManager,
private val httpClientFactory: HttpClientFactory
private val httpClientFactory: HttpClientFactory,
private val clientIdProvider: ChatService.ClientIdProvider,
private val envFetcher: EnvFetcher
) : ChatService {
private val mutex = Mutex()
private val httpClient by lazy {
@@ -40,9 +43,10 @@ class GigaChatService(
}
override suspend fun getCompletion(userId: Long, messages: List<Message>): String = mutex.withLock {
val clientId = "vbox-$userId"
val clientId = clientIdProvider.provide(userId)
val staticSessionId = UUID.nameUUIDFromBytes(clientId.toByteArray()).toString()
val requestBody = GigaChatRequest(
model = envFetcher.get("GIGA_CHAT_MODEL", "GigaChat-3-Ultra"),
messages = messages.map { GigaChatMessageDto(role = it.role, content = it.content) }
)
val response: GigaChatResponse = httpClient.post("https://api.giga.chat/v1/chat/completions") {
@@ -58,7 +62,7 @@ class GigaChatService(
@Serializable
private data class GigaChatRequest(
val model: String = "GigaChat-2",
val model: String,
val stream: Boolean = false,
@SerialName("update_interval")
val updateInterval: Int = 0,
@@ -4,4 +4,8 @@ import ru.shadowsparky.chat.domain.Message
interface ChatService {
suspend fun getCompletion(userId: Long, messages: List<Message>): String
interface ClientIdProvider {
suspend fun provide(userId: Long): String
}
}
@@ -11,13 +11,15 @@ class ProcessUserMessageUseCase(
private val chatService: ChatService,
private val envFetcher: EnvFetcher
) {
suspend fun execute(userId: Long): Message {
suspend fun execute(
userId: Long,
systemPrompt: String = envFetcher.get("CHAT_SYSTEM_PROMPT").trim('"')
): Message {
val history = storage.query(userId, null, limit = 10).toList()
val sortedHistory = history.sortedBy { it.timestamp }
val systemMessage = Message(
role = ChatRoles.SYSTEM,
content = envFetcher.get("CHAT_SYSTEM_PROMPT").trim('"')
.ifEmpty { error("System prompt not set") },
content = systemPrompt.ifEmpty { error("System prompt not set") },
timestamp = System.currentTimeMillis()
)
val fullContext = listOf(systemMessage) + sortedHistory