feat(mode): Jev solo/conspiracy/split classification on nest requests (#22)
This commit is contained in:
1 parent
5b3701d6e2
commit
9205cece65
3 files changed
+131
-47
No files matched your search
@@ -155,6 +155,64 @@ func deref(f *float64) float64 {
|
||||
return *f
|
||||
}
|
||||
|
||||
// modeQuestions classifies how a request should be taken up (Epic C). The
|
||||
// escape option "other" keeps Jev from forcing a wrong class; mode is discrete,
|
||||
// so choice, not score (JEV_STRATEGIES.md strategy 3).
|
||||
var modeQuestions = map[string]any{
|
||||
"mode": map[string]any{
|
||||
"type": "choice",
|
||||
"instructions": "How should this chatroom request be taken up?",
|
||||
"criteria": map[string]string{
|
||||
"solo": "Simple: one crow answers it directly.",
|
||||
"conspiracy": "A judgment call worth several distinct readings: several crows take the same request from their different strengths.",
|
||||
"split": "Large with distinct parts: separate subtasks, one owner each.",
|
||||
"other": "None of these fits well.",
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
// ClassifyMode returns the mode when Jev is set and its choice is at or above
|
||||
// the band. "other" reads as unsure (not ok) so callers fall back to a header.
|
||||
func (j *JevClient) ClassifyMode(ctx context.Context, text string) (string, map[string]float64, bool) {
|
||||
if j == nil {
|
||||
return "", nil, false
|
||||
}
|
||||
answers, _, _, err := j.SystemOne(ctx, text, modeQuestions)
|
||||
if err != nil {
|
||||
return "", nil, false
|
||||
}
|
||||
a := answers["mode"]
|
||||
if a.Choice == "" || a.Choice == "other" || a.Confidence == nil || *a.Confidence < j.threshold {
|
||||
return "", nil, false
|
||||
}
|
||||
return a.Choice, a.Probabilities, true
|
||||
}
|
||||
|
||||
// ClassifyMode classifies a request under the same guardrails as any call:
|
||||
// flock cap, timeout and flight log, with the probabilities recorded. Returns
|
||||
// the mode and ok; below-band or absent Jev means not ok.
|
||||
func (f *Flock) ClassifyMode(ctx context.Context, text string, budgets ...*Budget) (string, bool) {
|
||||
if f.jev == nil {
|
||||
return "", false
|
||||
}
|
||||
for _, b := range budgets {
|
||||
if err := b.Check(); err != nil {
|
||||
return "", false
|
||||
}
|
||||
}
|
||||
f.sem <- struct{}{}
|
||||
defer func() { <-f.sem }()
|
||||
cctx, cancel := context.WithTimeout(ctx, f.g.CrowTimeout)
|
||||
defer cancel()
|
||||
start := time.Now()
|
||||
mode, probs, ok := f.jev.ClassifyMode(cctx, text)
|
||||
e := Event{Kind: "mode", Item: text, Crow: "Sentry", Model: f.jev.model, Ms: time.Since(start).Milliseconds(), Prob: probs, Mode: mode}
|
||||
if f.log != nil {
|
||||
f.log.Write(e)
|
||||
}
|
||||
return mode, ok
|
||||
}
|
||||
|
||||
func (c JevCall) confident(threshold float64) bool {
|
||||
return c.ModeConf >= threshold && c.TaskTypeConf >= threshold
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user