diff --git a/redis/types.go b/redis/types.go index 3e7b1e0..f76d97d 100644 --- a/redis/types.go +++ b/redis/types.go @@ -1,6 +1,10 @@ package redis -import "gitee.com/red-future---jilin-g/common/config" +import ( + "context" + + "github.com/gogf/gf/v2/frame/g" +) // HistoryMessage 历史消息结构(用于上下文注入) type HistoryMessage struct { @@ -61,32 +65,34 @@ const ( FollowUpType3 = 3 // 第三次追问 ) -// GetFollowUpContent 获取追问话术(从 config 包读取) +// GetFollowUpContent 获取追问话术(从 config.yml 读取) func GetFollowUpContent(followUpType int) string { - switch followUpType { - case FollowUpType1: - return config.FollowUpContent1 - case FollowUpType2: - return config.FollowUpContent2 - case FollowUpType3: - return config.FollowUpContent3 - default: + ctx := context.Background() + contents := g.Cfg().MustGet(ctx, "followUp.contents").Strings() + if len(contents) == 0 { return "" } + // followUpType: 1,2,3 对应数组索引 0,1,2 + index := followUpType - 1 + if index >= 0 && index < len(contents) { + return contents[index] + } + return "" } -// GetFollowUpDelay 获取追问延时(从 config 包读取) +// GetFollowUpDelay 获取追问延时(从 config.yml 读取) 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 + 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] + } + return 30 } // ArchiveMessage 会话归档消息结构(RabbitMQ 延时队列) @@ -97,12 +103,14 @@ type ArchiveMessage struct { Timestamp int64 `json:"timestamp"` // 发送时间戳 } -// GetArchiveDelay 获取归档延时(从 config 包读取) +// GetArchiveDelay 获取归档延时(从 config.yml 读取) func GetArchiveDelay() int { - return config.ArchiveDelay + ctx := context.Background() + return g.Cfg().MustGet(ctx, "archive.delay", 3600).Int() // 默认3600秒(1小时) } -// GetHistoryContextLimit 获取历史上下文轮数(从 config 包读取) +// GetHistoryContextLimit 获取历史上下文轮数(从 config.yml 读取) func GetHistoryContextLimit() int64 { - return config.HistoryContextLimit + ctx := context.Background() + return g.Cfg().MustGet(ctx, "history.contextLimit", 5).Int64() // 默认5轮对话 }