2025-12-06 10:13:38 +08:00
|
|
|
|
package redis
|
|
|
|
|
|
|
2025-12-09 09:20:44 +08:00
|
|
|
|
import "gitee.com/red-future---jilin-g/common/config"
|
|
|
|
|
|
|
|
|
|
|
|
// HistoryMessage 历史消息结构(用于上下文注入)
|
|
|
|
|
|
type HistoryMessage struct {
|
|
|
|
|
|
Question string `json:"question"` // 用户问题
|
|
|
|
|
|
Answer string `json:"answer"` // AI 回复
|
2025-12-06 10:13:38 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2025-12-09 09:20:44 +08:00
|
|
|
|
// SendStreamMessage 发送到 Redis Stream 的消息结构
|
|
|
|
|
|
type SendStreamMessage struct {
|
2026-01-04 10:42:49 +08:00
|
|
|
|
UserId string `json:"userId"` // 用户ID
|
|
|
|
|
|
Content string `json:"content"` // 消息内容
|
|
|
|
|
|
Timestamp int64 `json:"timestamp"` // 时间戳(秒)
|
|
|
|
|
|
MessageId string `json:"messageId"` // 消息唯一ID
|
|
|
|
|
|
Platform string `json:"platform,omitempty"` // 平台标识
|
|
|
|
|
|
AccountId string `json:"accountId,omitempty"` // 账号ID
|
|
|
|
|
|
TenantId string `json:"tenantId,omitempty"` // 租户ID(数据隔离)
|
|
|
|
|
|
AccountName string `json:"accountName,omitempty"` // 客服账号名称
|
|
|
|
|
|
ChatId string `json:"chatId,omitempty"` // RAGFlow Chat ID(从ragflow_config查询)
|
|
|
|
|
|
ReplyQueue string `json:"replyQueue,omitempty"` // 响应队列名称(支持多实例独立队列)
|
|
|
|
|
|
History []HistoryMessage `json:"history,omitempty"` // 历史对话(归档后恢复时携带)
|
2025-12-06 10:13:38 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// BatchStreamMessage 批量消息结构
|
|
|
|
|
|
type BatchStreamMessage struct {
|
2026-01-04 10:42:49 +08:00
|
|
|
|
UserId string `json:"userId"` // 用户ID
|
2025-12-06 10:13:38 +08:00
|
|
|
|
Content string `json:"content"` // 消息内容
|
|
|
|
|
|
Timestamp int64 `json:"timestamp"` // 时间戳(秒)
|
2026-01-04 10:42:49 +08:00
|
|
|
|
BatchId string `json:"batchId"` // 批次ID
|
2025-12-06 10:13:38 +08:00
|
|
|
|
Index int `json:"index"` // 批次内序号
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2025-12-09 09:20:44 +08:00
|
|
|
|
// ResponseStreamMessage RAGFlow 响应消息结构(MQ 消息)
|
2025-12-06 18:04:29 +08:00
|
|
|
|
type ResponseStreamMessage struct {
|
2026-01-04 10:42:49 +08:00
|
|
|
|
UserId string `json:"userId"` // 用户ID
|
|
|
|
|
|
Platform string `json:"platform"` // 平台标识
|
|
|
|
|
|
TenantId string `json:"tenantId"` // 租户ID
|
|
|
|
|
|
Question string `json:"question"` // 用户问题
|
|
|
|
|
|
Content string `json:"content"` // RAGFlow 回复内容
|
|
|
|
|
|
SessionId string `json:"sessionId"` // RAGFlow Session ID
|
|
|
|
|
|
Timestamp int64 `json:"timestamp"` // 时间戳(秒)
|
|
|
|
|
|
MessageId string `json:"messageId"` // 原始消息ID
|
2025-12-06 18:04:29 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// FollowUpMessage 追问消息结构(RabbitMQ 延时队列)
|
|
|
|
|
|
type FollowUpMessage struct {
|
2026-01-04 10:42:49 +08:00
|
|
|
|
TenantId string `json:"tenantId"` // 租户ID
|
|
|
|
|
|
UserId string `json:"userId"` // 用户ID
|
|
|
|
|
|
Platform string `json:"platform"` // 平台标识
|
|
|
|
|
|
Content string `json:"content"` // 追问内容
|
|
|
|
|
|
FollowUpType int `json:"followUpType"` // 追问类型:1=30s, 2=60s, 3=180s
|
|
|
|
|
|
Timestamp int64 `json:"timestamp"` // 发送时间戳
|
2025-12-06 18:04:29 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2025-12-09 09:20:44 +08:00
|
|
|
|
// 追问类型常量
|
2025-12-06 18:04:29 +08:00
|
|
|
|
const (
|
2025-12-09 09:20:44 +08:00
|
|
|
|
FollowUpType1 = 1 // 第一次追问
|
|
|
|
|
|
FollowUpType2 = 2 // 第二次追问
|
|
|
|
|
|
FollowUpType3 = 3 // 第三次追问
|
2025-12-06 18:04:29 +08:00
|
|
|
|
)
|
|
|
|
|
|
|
2025-12-09 09:20:44 +08:00
|
|
|
|
// GetFollowUpContent 获取追问话术(从 config 包读取)
|
|
|
|
|
|
func GetFollowUpContent(followUpType int) string {
|
|
|
|
|
|
switch followUpType {
|
|
|
|
|
|
case FollowUpType1:
|
|
|
|
|
|
return config.FollowUpContent1
|
|
|
|
|
|
case FollowUpType2:
|
|
|
|
|
|
return config.FollowUpContent2
|
|
|
|
|
|
case FollowUpType3:
|
|
|
|
|
|
return config.FollowUpContent3
|
|
|
|
|
|
default:
|
|
|
|
|
|
return ""
|
|
|
|
|
|
}
|
2025-12-06 18:04:29 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2025-12-09 09:20:44 +08:00
|
|
|
|
// GetFollowUpDelay 获取追问延时(从 config 包读取)
|
|
|
|
|
|
func GetFollowUpDelay(followUpType int) int {
|
|
|
|
|
|
switch followUpType {
|
|
|
|
|
|
case FollowUpType1:
|
|
|
|
|
|
return config.FollowUpDelay1
|
|
|
|
|
|
case FollowUpType2:
|
|
|
|
|
|
return config.FollowUpDelay2
|
|
|
|
|
|
case FollowUpType3:
|
|
|
|
|
|
return config.FollowUpDelay3
|
|
|
|
|
|
default:
|
|
|
|
|
|
return 0
|
|
|
|
|
|
}
|
2025-12-06 18:04:29 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// ArchiveMessage 会话归档消息结构(RabbitMQ 延时队列)
|
|
|
|
|
|
type ArchiveMessage struct {
|
2026-01-04 10:42:49 +08:00
|
|
|
|
UserId string `json:"userId"` // 用户ID
|
|
|
|
|
|
Platform string `json:"platform"` // 平台标识
|
|
|
|
|
|
SessionId string `json:"sessionId"` // RAGFlow Session ID
|
|
|
|
|
|
Timestamp int64 `json:"timestamp"` // 发送时间戳
|
2025-12-06 18:04:29 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2025-12-09 09:20:44 +08:00
|
|
|
|
// GetArchiveDelay 获取归档延时(从 config 包读取)
|
|
|
|
|
|
func GetArchiveDelay() int {
|
|
|
|
|
|
return config.ArchiveDelay
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// GetHistoryContextLimit 获取历史上下文轮数(从 config 包读取)
|
|
|
|
|
|
func GetHistoryContextLimit() int64 {
|
|
|
|
|
|
return config.HistoryContextLimit
|
|
|
|
|
|
}
|