add send message
This commit is contained in:
+4
@@ -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(
|
||||
|
||||
Reference in New Issue
Block a user