GeezerVison is showing github.com — feat(judge): wire verdict cache in gateway, relay, and demo · majorcontext/keep@51052eb
File treeExpand file treeCollapse file tree Open diff view settings Expand file treeCollapse file tree Open diff view settings Collapse file Copy file name to clipboardExpand all lines: cmd/keep-llm-gateway/main.go +5-2Lines changed: 5 additions & 2 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -16,6 +16,7 @@ import ( | 16 | 16 | "github.com/majorcontext/keep/internal/audit" | 17 | 17 | "github.com/majorcontext/keep/internal/gateway" | 18 | 18 | gwconfig "github.com/majorcontext/keep/internal/gateway/config" | | 19 | + "github.com/majorcontext/keep/judge" | 19 | 20 | anthropicjudge "github.com/majorcontext/keep/judge/anthropic" | 20 | 21 | openaijudge "github.com/majorcontext/keep/judge/openai" | 21 | 22 | ) | @@ -54,14 +55,16 @@ func main() { | 54 | 55 | jopts = append(jopts, anthropicjudge.WithBaseURL(cfg.Judge.BaseURL)) | 55 | 56 | } | 56 | 57 | p := anthropicjudge.New(apiKey, jopts...) | 57 | | - engineOpts = append(engineOpts, keep.WithJudge(p.Judge)) | | 58 | + cached := judge.NewCache(p) | | 59 | + engineOpts = append(engineOpts, keep.WithJudge(cached.Judge)) | 58 | 60 | case "openai": | 59 | 61 | var jopts []openaijudge.Option | 60 | 62 | if cfg.Judge.BaseURL != "" { | 61 | 63 | jopts = append(jopts, openaijudge.WithBaseURL(cfg.Judge.BaseURL)) | 62 | 64 | } | 63 | 65 | p := openaijudge.New(apiKey, jopts...) | 64 | | - engineOpts = append(engineOpts, keep.WithJudge(p.Judge)) | | 66 | + cached := judge.NewCache(p) | | 67 | + engineOpts = append(engineOpts, keep.WithJudge(cached.Judge)) | 65 | 68 | } | 66 | 69 | } | 67 | 70 | } | |
Collapse file Copy file name to clipboardExpand all lines: cmd/keep-mcp-relay/main.go +5-2Lines changed: 5 additions & 2 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -16,6 +16,7 @@ import ( | 16 | 16 | "github.com/majorcontext/keep/internal/relay" | 17 | 17 | relayconfig "github.com/majorcontext/keep/internal/relay/config" | 18 | 18 | "github.com/majorcontext/keep/internal/relay/mcp" | | 19 | + "github.com/majorcontext/keep/judge" | 19 | 20 | anthropicjudge "github.com/majorcontext/keep/judge/anthropic" | 20 | 21 | openaijudge "github.com/majorcontext/keep/judge/openai" | 21 | 22 | ) | @@ -54,14 +55,16 @@ func main() { | 54 | 55 | jopts = append(jopts, anthropicjudge.WithBaseURL(cfg.Judge.BaseURL)) | 55 | 56 | } | 56 | 57 | p := anthropicjudge.New(apiKey, jopts...) | 57 | | - engineOpts = append(engineOpts, keep.WithJudge(p.Judge)) | | 58 | + cached := judge.NewCache(p) | | 59 | + engineOpts = append(engineOpts, keep.WithJudge(cached.Judge)) | 58 | 60 | case "openai": | 59 | 61 | var jopts []openaijudge.Option | 60 | 62 | if cfg.Judge.BaseURL != "" { | 61 | 63 | jopts = append(jopts, openaijudge.WithBaseURL(cfg.Judge.BaseURL)) | 62 | 64 | } | 63 | 65 | p := openaijudge.New(apiKey, jopts...) | 64 | | - engineOpts = append(engineOpts, keep.WithJudge(p.Judge)) | | 66 | + cached := judge.NewCache(p) | | 67 | + engineOpts = append(engineOpts, keep.WithJudge(cached.Judge)) | 65 | 68 | } | 66 | 69 | } | 67 | 70 | } | |
Collapse file Copy file name to clipboardExpand all lines: examples/judge-demo/demo.sh +3-1Lines changed: 3 additions & 1 deletion | Original file line number | Diff line number | Diff line change |
|---|
@@ -86,10 +86,12 @@ for line in open('$1'): | 86 | 86 | verdict = j.get('verdict', '?') | 87 | 87 | reason = j.get('reason', '') | 88 | 88 | ms = j.get('latency_ms', 0) | | 89 | + cached = j.get('cached', False) | | 90 | + cache_tag = ' (cached)' if cached else '' | 89 | 91 | vc = '\033[32m' if verdict == 'allow' else '\033[31m' | 90 | 92 | if len(reason) > 100: | 91 | 93 | reason = reason[:100] + '...' | 92 | | - print(f' {magenta}\u2728 {model}{reset}: {vc}{verdict}{reset} ({ms}ms) \u2014 {dim}{reason}{reset}') | | 94 | + print(f' {magenta}\u2728 {model}{reset}: {vc}{verdict}{reset} ({ms}ms){cache_tag} \u2014 {dim}{reason}{reset}') | 93 | 95 | except: pass | 94 | 96 | " 2>/dev/null | 95 | 97 | } | |
|