修改common/redis/types.go - 移除config包依赖,改为从config.yml读取配置

This commit is contained in:
Cold
2026-01-04 13:54:14 +08:00
committed by 张斌
parent 27314840d1
commit 41703aea3a

View File

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