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
+1 -1
View File
@@ -24,7 +24,7 @@ dependencies {
implementation(project(":feature:chat:chat-common"))
implementation(project(":feature:chat:chat-backend"))
implementation("org.jetbrains.kotlinx:kotlinx-coroutines-reactive:1.8.1")
implementation(libs.kotlinx.coroutines.reactive)
implementation(libs.lettuce.lettuce.core)
implementation(libs.ktor.server.core.jvm)
implementation(libs.ktor.server.host.common.jvm)
@@ -0,0 +1,9 @@
package ru.shadowsparky.vbox.backend.data
import org.koin.core.annotation.Factory
import ru.shadowsparky.chat.backend.domain.ChatService
@Factory
class ClientIdProviderImpl : ChatService.ClientIdProvider {
override suspend fun provide(userId: Long): String = "vbox-$userId"
}
@@ -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
+2
View File
@@ -1,5 +1,6 @@
[versions]
activity-compose = "1.13.0"
kotlinxCoroutinesReactive = "1.11.0"
lettuceCoreVersion = "7.7.0.RELEASE"
material3-compose = "1.11.0-alpha03"
adaptiveLayout = "1.3.0-beta02"
@@ -75,6 +76,7 @@ haze-materials = { module = "dev.chrisbanes.haze:haze-materials", version.ref =
java-jwt = { module = "com.auth0:java-jwt", version.ref = "java-jwt" }
jdbc-driver = { module = "app.cash.sqldelight:jdbc-driver", version.ref = "sqlite-driver" }
koin-annotations = { module = "io.insert-koin:koin-annotations", version.ref = "koin-core" }
kotlinx-coroutines-reactive = { module = "org.jetbrains.kotlinx:kotlinx-coroutines-reactive", version.ref = "kotlinxCoroutinesReactive" }
ktor-client-js = { module = "io.ktor:ktor-client-js", version.ref = "ktor-plugin" }
ktor-server-cors = { module = "io.ktor:ktor-server-cors" }
ktor-server-auth-jwt = { module = "io.ktor:ktor-server-auth-jwt" }