add send message

This commit is contained in:
2026-09-12 23:53:16 +03:00
parent b5788e14f1
commit 346abc24fe
6 changed files with 42 additions and 10 deletions
@@ -4,6 +4,7 @@ import org.koin.core.annotation.Factory
import ru.shadowsparky.backend.data.EnvFetcher
import ru.shadowsparky.chat.domain.ChatRoles
import ru.shadowsparky.chat.domain.Message
import ru.shadowsparky.http.domain.BadRequestException
@Factory
class ProcessUserMessageUseCase(
@@ -12,9 +13,12 @@ class ProcessUserMessageUseCase(
private val envFetcher: EnvFetcher
) {
suspend fun execute(
userMessage: Message,
userId: Long,
systemPrompt: String = envFetcher.get("CHAT_SYSTEM_PROMPT").trim('"')
): Message {
if (userMessage.role != ChatRoles.USER) throw BadRequestException("invalid role")
storage.insert(userId, userMessage)
val history = storage.query(userId, null, limit = 10).toList()
val sortedHistory = history.sortedBy { it.timestamp }
val systemMessage = Message(