From 41703aea3a06df1cd1435368eabdc56ab16414f7 Mon Sep 17 00:00:00 2001 From: Cold <16419454+cold502@user.noreply.gitee.com> Date: Sun, 4 Jan 2026 13:54:14 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9common/redis/types.go=20-=20?= =?UTF-8?q?=E7=A7=BB=E9=99=A4config=E5=8C=85=E4=BE=9D=E8=B5=96=EF=BC=8C?= =?UTF-8?q?=E6=94=B9=E4=B8=BA=E4=BB=8Econfig.yml=E8=AF=BB=E5=8F=96?= =?UTF-8?q?=E9=85=8D=E7=BD=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- redis/types.go | 56 ++++++++++++++++++++++++++++---------------------- 1 file changed, 32 insertions(+), 24 deletions(-) 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轮对话 }