Files
common/redis/types.go

130 lines
5.1 KiB
Go
Raw Normal View History

package redis
import (
"context"
"github.com/gogf/gf/v2/frame/g"
)
2025-12-09 09:20:44 +08:00
// HistoryMessage 历史消息结构(用于上下文注入)
type HistoryMessage struct {
Question string `json:"question"` // 用户问题
Answer string `json:"answer"` // AI 回复
}
2025-12-09 09:20:44 +08:00
// SendStreamMessage 发送到 Redis Stream 的消息结构
type SendStreamMessage struct {
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"` // 历史对话(归档后恢复时携带)
}
// BatchStreamMessage 批量消息结构
type BatchStreamMessage struct {
UserId string `json:"userId"` // 用户ID
Content string `json:"content"` // 消息内容
Timestamp int64 `json:"timestamp"` // 时间戳(秒)
BatchId string `json:"batchId"` // 批次ID
Index int `json:"index"` // 批次内序号
}
2025-12-09 09:20:44 +08:00
// ResponseStreamMessage RAGFlow 响应消息结构MQ 消息)
type ResponseStreamMessage struct {
2026-01-09 17:57:14 +08:00
UserId string `json:"userId"` // 用户ID
Platform string `json:"platform"` // 平台标识
TenantId string `json:"tenantId"` // 租户ID
AccountId string `json:"accountId,omitempty"` // 账号ID
AccountName string `json:"accountName,omitempty"` // 客服账号名称
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
}
// FollowUpMessage 追问消息结构RabbitMQ 延时队列)
type FollowUpMessage struct {
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-09 09:20:44 +08:00
// 追问类型常量
const (
2025-12-09 09:20:44 +08:00
FollowUpType1 = 1 // 第一次追问
FollowUpType2 = 2 // 第二次追问
FollowUpType3 = 3 // 第三次追问
)
// GetFollowUpContent 获取追问话术(从 config.yml 读取)
2025-12-09 09:20:44 +08:00
func GetFollowUpContent(followUpType int) string {
ctx := context.Background()
contents := g.Cfg().MustGet(ctx, "followUp.contents").Strings()
if len(contents) == 0 {
2025-12-09 09:20:44 +08:00
return ""
}
// followUpType: 1,2,3 对应数组索引 0,1,2
index := followUpType - 1
if index >= 0 && index < len(contents) {
return contents[index]
}
return ""
}
// GetFollowUpDelay 获取追问延时(从 config.yml 读取)
2025-12-09 09:20:44 +08:00
func GetFollowUpDelay(followUpType int) int {
ctx := context.Background()
delays := g.Cfg().MustGet(ctx, "followUp.delays").Ints()
if len(delays) == 0 {
return 30 // 默认30秒
}
// followUpType: 1,2,3 对应数组索引 0,1,2
index := followUpType - 1
if index >= 0 && index < len(delays) {
return delays[index]
2025-12-09 09:20:44 +08:00
}
return 30
}
// ArchiveMessage 会话归档消息结构RabbitMQ 延时队列)
type ArchiveMessage struct {
UserId string `json:"userId"` // 用户ID
Platform string `json:"platform"` // 平台标识
SessionId string `json:"sessionId"` // RAGFlow Session ID
2026-01-17 17:58:13 +08:00
TenantId string `json:"tenantId"` // 租户ID
Timestamp int64 `json:"timestamp"` // 发送时间戳
}
// GetArchiveDelay 获取归档延时(从 config.yml 读取)
2025-12-09 09:20:44 +08:00
func GetArchiveDelay() int {
ctx := context.Background()
return g.Cfg().MustGet(ctx, "archive.delay", 3600).Int() // 默认3600秒1小时
2025-12-09 09:20:44 +08:00
}
// GetHistoryContextLimit 获取历史上下文轮数(从 config.yml 读取)
2025-12-09 09:20:44 +08:00
func GetHistoryContextLimit() int64 {
ctx := context.Background()
return g.Cfg().MustGet(ctx, "history.contextLimit", 5).Int64() // 默认5轮对话
2025-12-09 09:20:44 +08:00
}
2026-01-16 13:42:15 +08:00
// DocSyncMessage 文档同步消息结构RAGFlow与MongoDB同步
type DocSyncMessage struct {
DocId string `json:"docId"` // MongoDB文档ID
RagflowDocId string `json:"ragflowDocId"` // RAGFlow文档ID
TenantId string `json:"tenantId"` // 租户ID
DocType string `json:"docType"` // 文档类型speechcraft/product
Action string `json:"action"` // 操作类型sync_ragflow_id
Timestamp int64 `json:"timestamp"` // 时间戳
}