Documentation
¶
Index ¶
- Constants
- func ConfModAiIntentCheck(cfg *ConfModAiIntent, confRoot string) error
- func ExtractLastUserMessage(body []byte, protocol string) (string, error)
- type ConfModAiIntent
- type DecisionClient
- type IntentCache
- type IntentQuestion
- type IntentQuestions
- func (qs *IntentQuestions) OrderedQuestions() []*IntentQuestion
- func (qs *IntentQuestions) Question(name string) (*IntentQuestion, bool)
- func (qs *IntentQuestions) SystemOneQuestions() map[string]interface{}
- func (qs *IntentQuestions) Threshold(question string) float64
- func (qs *IntentQuestions) Version() string
- type ModuleAiIntent
- type ModuleAiIntentState
- type QuestionFile
- type QuestionLevel
- type QuestionsConf
- type QuestionsFile
Constants ¶
const ( DefaultTimeoutMs = 300 DefaultMaxStateChars = 2000 DefaultCacheSize = 10000 DefaultCacheTTLSeconds = 1800 DefaultExplicitIntentHeader = "X-AI-Intent" DefaultFailureThreshold = 5 DefaultProbeIntervalMs = 5000 )
default values for optional configuration items
const ( QuestionTypeChoice = bfe_basic.IntentQTypeChoice QuestionTypeScore = bfe_basic.IntentQTypeScore )
question types (kept in sync with bfe_basic.IntentQType*)
const (
DefaultMinConfidence = 0.6
)
const ModAiIntent = "mod_ai_intent"
Variables ¶
This section is empty.
Functions ¶
func ConfModAiIntentCheck ¶
func ConfModAiIntentCheck(cfg *ConfModAiIntent, confRoot string) error
Types ¶
type ConfModAiIntent ¶
type ConfModAiIntent struct {
Basic struct {
DecisionServiceAddr string // decision service address (System One protocol)
QuestionsPath string // path for intent questions data file
TimeoutMs int // per classification timeout (ms)
MaxStateChars int // rune truncation length of the classified text
CacheSize int // max entries of in-process LRU cache
CacheTTLSeconds int // TTL of cache entries (s)
ExplicitIntentHeader string // request header for explicit intent declaration
}
Breaker struct {
FailureThreshold int // consecutive failures before breaker opens
ProbeIntervalMs int // probe interval while breaker is open (ms)
}
Log struct {
OpenDebug bool
}
}
func (*ConfModAiIntent) Check ¶
func (cfg *ConfModAiIntent) Check(confRoot string) error
type DecisionClient ¶
type DecisionClient interface {
// Classify returns the answers by question name and the backend
// version string. Any error (timeout, 5xx, malformed response) is
// reported to the caller, which degrades to unknown answers.
Classify(ctx context.Context, state string, qs *IntentQuestions) (map[string]*bfe_basic.IntentAnswer, string, error)
}
DecisionClient classifies a state text against the configured questions via the System One protocol.
func NewDecisionClient ¶
func NewDecisionClient(addr string, timeoutMs int) DecisionClient
type IntentCache ¶
type IntentCache struct {
// contains filtered or unexported fields
}
IntentCache is a process-wide LRU cache with TTL for classification results. Self-implemented (map + list), no third-party dependency.
func NewIntentCache ¶
func NewIntentCache(capacity int, ttl time.Duration) *IntentCache
func (*IntentCache) Enabled ¶
func (c *IntentCache) Enabled() bool
Enabled reports whether the cache stores anything.
func (*IntentCache) Len ¶
func (c *IntentCache) Len() int
Len returns the current number of live entries (expired ones excluded).
type IntentQuestion ¶
type IntentQuestion struct {
Name string
Type string
Instructions string
Criteria map[string]string // choice: option name -> description
LevelNames []string // score: level names, ordered low to high
LevelDescs []string // score: level descriptions, ordered low to high
MinConfidence float64 // per-question gate, noConfidenceOverride to inherit
}
IntentQuestion is the runtime representation of a question.
func (*IntentQuestion) HasOption ¶
func (q *IntentQuestion) HasOption(option string) bool
HasOption reports whether option is a valid option/level name of the question.
type IntentQuestions ¶
type IntentQuestions struct {
// contains filtered or unexported fields
}
IntentQuestions is the runtime, immutable snapshot of the questions conf. It is swapped atomically on hot reload, so readers never see a partial conf.
func (*IntentQuestions) OrderedQuestions ¶
func (qs *IntentQuestions) OrderedQuestions() []*IntentQuestion
OrderedQuestions returns questions in file order (stable request assembly).
func (*IntentQuestions) Question ¶
func (qs *IntentQuestions) Question(name string) (*IntentQuestion, bool)
func (*IntentQuestions) SystemOneQuestions ¶
func (qs *IntentQuestions) SystemOneQuestions() map[string]interface{}
SystemOneQuestions assembles the questions field of the decision service request: choice questions carry a name->description criteria map; score questions carry the ordered level descriptions.
func (*IntentQuestions) Threshold ¶
func (qs *IntentQuestions) Threshold(question string) float64
Threshold returns the current effective confidence gate of a question: per-question override, then the global gate. Unconfigured questions get 0, i.e. only the presence of an answer is required.
func (*IntentQuestions) Version ¶
func (qs *IntentQuestions) Version() string
type ModuleAiIntent ¶
type ModuleAiIntent struct {
// contains filtered or unexported fields
}
func NewModuleAiIntent ¶
func NewModuleAiIntent() *ModuleAiIntent
func (*ModuleAiIntent) Init ¶
func (m *ModuleAiIntent) Init(cbs *bfe_module.BfeCallbacks, whs *web_monitor.WebHandlers, cr string) error
func (*ModuleAiIntent) Name ¶
func (m *ModuleAiIntent) Name() string
type ModuleAiIntentState ¶
type ModuleAiIntentState struct {
ReqTotal *metrics.Counter // total resolve triggered by intent conditions
ReqResolved *metrics.Counter // resolves with usable answers (header/cache/model)
ReqHeader *metrics.Counter // resolves using explicit intent header entries
ReqCacheHit *metrics.Counter // resolves served from in-process cache
ReqUnknown *metrics.Counter // resolves degraded to unknown (non-AI request, extract failure)
ReqErr *metrics.Counter // resolves failed on decision service (error / breaker open)
BreakerOpen *metrics.Counter // times the circuit breaker opened
QuestionsVersion *metrics.State // current version of the questions conf
}
type QuestionFile ¶
type QuestionFile struct {
Name string `json:"Name"`
Type string `json:"Type"`
Instructions string `json:"Instructions"`
Criteria map[string]string `json:"Criteria"` // choice options: name -> description
Levels []QuestionLevel `json:"Levels"` // score levels, ordered low to high
MinConfidence *float64 `json:"MinConfidence"`
}
QuestionFile is the JSON DTO of a single question in intent_questions.data.
type QuestionLevel ¶
QuestionLevel is one level of a score question, ordered low to high.
type QuestionsConf ¶
type QuestionsConf struct {
// contains filtered or unexported fields
}
QuestionsConf holds the current questions conf snapshot with atomic replacement, plus its source path for hot reload.
func NewQuestionsConf ¶
func NewQuestionsConf(path string) *QuestionsConf
func (*QuestionsConf) Current ¶
func (qc *QuestionsConf) Current() *IntentQuestions
func (*QuestionsConf) Load ¶
func (qc *QuestionsConf) Load(path ...string) error
Load reloads the questions conf from the file (or from path if given, which also becomes the new source path of the conf). The new conf is validated first; a hot reload with an unchanged Version is a no-op.
func (*QuestionsConf) Path ¶
func (qc *QuestionsConf) Path() string
func (*QuestionsConf) Threshold ¶
func (qc *QuestionsConf) Threshold(question string) float64
Threshold returns the current effective confidence gate of a question.
type QuestionsFile ¶
type QuestionsFile struct {
Version string `json:"Version"`
MinConfidence *float64 `json:"MinConfidence"`
Questions []QuestionFile `json:"Questions"`
}
QuestionsFile is the JSON DTO of intent_questions.data.