Anchor weather and other realtime questions on runner /v1/search results (or an explicit refuse constraint) so the model cannot invent dates or temperatures from training memory.
39 lines
1.1 KiB
Go
39 lines
1.1 KiB
Go
package coordinator
|
|
|
|
import (
|
|
"context"
|
|
"strings"
|
|
"unicode/utf8"
|
|
|
|
"chat-agent-system/internal/intent"
|
|
)
|
|
|
|
// RealtimeSearcher 对话路径的实时信息检索(天气/新闻等);由 app 注入 Pi Runner /v1/search。
|
|
type RealtimeSearcher interface {
|
|
Search(ctx context.Context, query string) (markdown string, err error)
|
|
}
|
|
|
|
var realtimeInfoMarkers = []string{
|
|
"天气", "气温", "温度", "下雨", "下雪", "降雨", "降雪", "台风", "雾霾",
|
|
"天气预报", "气象", "风力", "体感",
|
|
"新闻", "头条", "股价", "汇率", "实时", "今日新闻", "热点新闻",
|
|
}
|
|
|
|
// IsRealtimeInformationQuery 判定是否为需要实时检索的时效性问句。
|
|
// 含强业务词典时不触发(避免「型检温度」「项目进度」等误伤)。
|
|
func IsRealtimeInformationQuery(input string) bool {
|
|
trimmed := strings.TrimSpace(input)
|
|
if trimmed == "" || utf8.RuneCountInString(trimmed) < 2 {
|
|
return false
|
|
}
|
|
if intent.HasStrongBusinessLexicon(trimmed) {
|
|
return false
|
|
}
|
|
for _, m := range realtimeInfoMarkers {
|
|
if strings.Contains(trimmed, m) {
|
|
return true
|
|
}
|
|
}
|
|
return false
|
|
}
|