连接池,redis,和配置文件
This commit is contained in:
110
redis/types.go
110
redis/types.go
@@ -1,21 +1,23 @@
|
||||
package redis
|
||||
|
||||
import "gitee.com/red-future---jilin-g/common/config"
|
||||
|
||||
// HistoryMessage 历史消息结构(用于上下文注入)
|
||||
type HistoryMessage struct {
|
||||
Question string `json:"question"` // 用户问题
|
||||
Answer string `json:"answer"` // AI 回复
|
||||
}
|
||||
|
||||
// SendStreamMessage 发送到 Redis Stream 的消息结构
|
||||
type SendStreamMessage struct {
|
||||
UserId string `json:"user_id"` // 用户ID
|
||||
Content string `json:"content"` // 消息内容
|
||||
Timestamp int64 `json:"timestamp"` // 时间戳(秒)
|
||||
MessageId string `json:"message_id"` // 消息唯一ID
|
||||
}
|
||||
|
||||
// ToMap 转换为 map[string]interface{} 用于 Stream 存储
|
||||
func (m *SendStreamMessage) ToMap() map[string]interface{} {
|
||||
return map[string]interface{}{
|
||||
"user_id": m.UserId,
|
||||
"content": m.Content,
|
||||
"timestamp": m.Timestamp,
|
||||
"message_id": m.MessageId,
|
||||
}
|
||||
UserId string `json:"user_id"` // 用户ID
|
||||
Content string `json:"content"` // 消息内容
|
||||
Timestamp int64 `json:"timestamp"` // 时间戳(秒)
|
||||
MessageId string `json:"message_id"` // 消息唯一ID
|
||||
Platform string `json:"platform,omitempty"` // 平台标识
|
||||
AccountId string `json:"account_id,omitempty"` // 账号ID
|
||||
TenantId string `json:"tenant_id,omitempty"` // 租户ID(数据隔离)
|
||||
History []HistoryMessage `json:"history,omitempty"` // 历史对话(归档后恢复时携带)
|
||||
}
|
||||
|
||||
// BatchStreamMessage 批量消息结构
|
||||
@@ -27,21 +29,11 @@ type BatchStreamMessage struct {
|
||||
Index int `json:"index"` // 批次内序号
|
||||
}
|
||||
|
||||
// ToMap 转换为 map[string]interface{} 用于 Stream 存储
|
||||
func (m *BatchStreamMessage) ToMap() map[string]interface{} {
|
||||
return map[string]interface{}{
|
||||
"user_id": m.UserId,
|
||||
"content": m.Content,
|
||||
"timestamp": m.Timestamp,
|
||||
"batch_id": m.BatchId,
|
||||
"index": m.Index,
|
||||
}
|
||||
}
|
||||
|
||||
// ResponseStreamMessage RAGFlow 响应消息结构(写入结果 Stream)
|
||||
// ResponseStreamMessage RAGFlow 响应消息结构(MQ 消息)
|
||||
type ResponseStreamMessage struct {
|
||||
UserId string `json:"user_id"` // 用户ID
|
||||
Platform string `json:"platform"` // 平台标识
|
||||
TenantId string `json:"tenant_id"` // 租户ID
|
||||
Question string `json:"question"` // 用户问题
|
||||
Content string `json:"content"` // RAGFlow 回复内容
|
||||
SessionId string `json:"session_id"` // RAGFlow Session ID
|
||||
@@ -49,19 +41,6 @@ type ResponseStreamMessage struct {
|
||||
MessageId string `json:"message_id"` // 原始消息ID
|
||||
}
|
||||
|
||||
// ToMap 转换为 map[string]interface{} 用于 Stream 存储
|
||||
func (m *ResponseStreamMessage) ToMap() map[string]interface{} {
|
||||
return map[string]interface{}{
|
||||
"user_id": m.UserId,
|
||||
"platform": m.Platform,
|
||||
"question": m.Question,
|
||||
"content": m.Content,
|
||||
"session_id": m.SessionId,
|
||||
"timestamp": m.Timestamp,
|
||||
"message_id": m.MessageId,
|
||||
}
|
||||
}
|
||||
|
||||
// FollowUpMessage 追问消息结构(RabbitMQ 延时队列)
|
||||
type FollowUpMessage struct {
|
||||
UserId string `json:"user_id"` // 用户ID
|
||||
@@ -71,25 +50,39 @@ type FollowUpMessage struct {
|
||||
Timestamp int64 `json:"timestamp"` // 发送时间戳
|
||||
}
|
||||
|
||||
// 追问话术常量
|
||||
// 追问类型常量
|
||||
const (
|
||||
FollowUpType1 = 1 // 30秒追问
|
||||
FollowUpType2 = 2 // 60秒追问
|
||||
FollowUpType3 = 3 // 180秒追问
|
||||
FollowUpType1 = 1 // 第一次追问
|
||||
FollowUpType2 = 2 // 第二次追问
|
||||
FollowUpType3 = 3 // 第三次追问
|
||||
)
|
||||
|
||||
// 追问话术内容
|
||||
var FollowUpContents = map[int]string{
|
||||
FollowUpType1: "还有其他问题吗?",
|
||||
FollowUpType2: "如果需要帮助,随时告诉我~",
|
||||
FollowUpType3: "我一直在线,有问题随时找我~",
|
||||
// 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 ""
|
||||
}
|
||||
}
|
||||
|
||||
// 追问延时时间(秒)
|
||||
var FollowUpDelays = map[int]int{
|
||||
FollowUpType1: 30,
|
||||
FollowUpType2: 60,
|
||||
FollowUpType3: 180,
|
||||
// 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
|
||||
}
|
||||
}
|
||||
|
||||
// ArchiveMessage 会话归档消息结构(RabbitMQ 延时队列)
|
||||
@@ -100,5 +93,12 @@ type ArchiveMessage struct {
|
||||
Timestamp int64 `json:"timestamp"` // 发送时间戳
|
||||
}
|
||||
|
||||
// 归档延时时间(秒)
|
||||
const ArchiveDelaySeconds = 3600 // 60分钟
|
||||
// GetArchiveDelay 获取归档延时(从 config 包读取)
|
||||
func GetArchiveDelay() int {
|
||||
return config.ArchiveDelay
|
||||
}
|
||||
|
||||
// GetHistoryContextLimit 获取历史上下文轮数(从 config 包读取)
|
||||
func GetHistoryContextLimit() int64 {
|
||||
return config.HistoryContextLimit
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user