GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — feat(gateway,relay): add judge provider config · majorcontext/keep@775e76d

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
  • cmd
    • keep-llm-gateway
      • main.go
    • keep-mcp-relay
      • main.go
  • internal
    • gateway/config
      • config.go
      • config_test.go
    • relay/config
      • config.go
      • config_test.go
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎cmd/keep-llm-gateway/main.go‎

Copy file name to clipboardExpand all lines: cmd/keep-llm-gateway/main.go
+23Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ import (
1616
"github.com/majorcontext/keep/internal/audit"
1717
"github.com/majorcontext/keep/internal/gateway"
1818
gwconfig "github.com/majorcontext/keep/internal/gateway/config"
19+
anthropicjudge "github.com/majorcontext/keep/judge/anthropic"
20+
openaijudge "github.com/majorcontext/keep/judge/openai"
1921
)
2022

2123
func main() {
@@ -42,6 +44,27 @@ func main() {
4244
if cfg.PacksDir != "" {
4345
engineOpts = append(engineOpts, keep.WithPacksDir(cfg.PacksDir))
4446
}
47+
if cfg.Judge != nil {
48+
apiKey := os.Getenv(cfg.Judge.APIKeyEnv)
49+
if apiKey != "" {
50+
switch cfg.Judge.Provider {
51+
case "anthropic":
52+
var jopts []anthropicjudge.Option
53+
if cfg.Judge.BaseURL != "" {
54+
jopts = append(jopts, anthropicjudge.WithBaseURL(cfg.Judge.BaseURL))
55+
}
56+
p := anthropicjudge.New(apiKey, jopts...)
57+
engineOpts = append(engineOpts, keep.WithJudge(p.Judge))
58+
case "openai":
59+
var jopts []openaijudge.Option
60+
if cfg.Judge.BaseURL != "" {
61+
jopts = append(jopts, openaijudge.WithBaseURL(cfg.Judge.BaseURL))
62+
}
63+
p := openaijudge.New(apiKey, jopts...)
64+
engineOpts = append(engineOpts, keep.WithJudge(p.Judge))
65+
}
66+
}
67+
}
4568
engine, err := keep.Load(cfg.RulesDir, engineOpts...)
4669
if err != nil {
4770
fmt.Fprintf(os.Stderr, "error loading rules: %v\n", err)
Collapse file

‎cmd/keep-mcp-relay/main.go‎

Copy file name to clipboardExpand all lines: cmd/keep-mcp-relay/main.go
+23Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ import (
1616
"github.com/majorcontext/keep/internal/relay"
1717
relayconfig "github.com/majorcontext/keep/internal/relay/config"
1818
"github.com/majorcontext/keep/internal/relay/mcp"
19+
anthropicjudge "github.com/majorcontext/keep/judge/anthropic"
20+
openaijudge "github.com/majorcontext/keep/judge/openai"
1921
)
2022

2123
func main() {
@@ -42,6 +44,27 @@ func main() {
4244
if cfg.PacksDir != "" {
4345
engineOpts = append(engineOpts, keep.WithPacksDir(cfg.PacksDir))
4446
}
47+
if cfg.Judge != nil {
48+
apiKey := os.Getenv(cfg.Judge.APIKeyEnv)
49+
if apiKey != "" {
50+
switch cfg.Judge.Provider {
51+
case "anthropic":
52+
var jopts []anthropicjudge.Option
53+
if cfg.Judge.BaseURL != "" {
54+
jopts = append(jopts, anthropicjudge.WithBaseURL(cfg.Judge.BaseURL))
55+
}
56+
p := anthropicjudge.New(apiKey, jopts...)
57+
engineOpts = append(engineOpts, keep.WithJudge(p.Judge))
58+
case "openai":
59+
var jopts []openaijudge.Option
60+
if cfg.Judge.BaseURL != "" {
61+
jopts = append(jopts, openaijudge.WithBaseURL(cfg.Judge.BaseURL))
62+
}
63+
p := openaijudge.New(apiKey, jopts...)
64+
engineOpts = append(engineOpts, keep.WithJudge(p.Judge))
65+
}
66+
}
67+
}
4568
engine, err := keep.Load(cfg.RulesDir, engineOpts...)
4669
if err != nil {
4770
fmt.Fprintf(os.Stderr, "error loading rules: %v\n", err)
Collapse file

‎internal/gateway/config/config.go‎

Copy file name to clipboardExpand all lines: internal/gateway/config/config.go
+8Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,13 @@ import (
1010
"github.com/majorcontext/keep/llm"
1111
)
1212

13+
// JudgeConfig holds configuration for the LLM-as-judge provider.
14+
type JudgeConfig struct {
15+
Provider string `yaml:"provider"`
16+
APIKeyEnv string `yaml:"api_key_env"`
17+
BaseURL string `yaml:"base_url,omitempty"`
18+
}
19+
1320
// GatewayConfig holds the top-level gateway configuration.
1421
type GatewayConfig struct {
1522
Listen string `yaml:"listen"`
@@ -20,6 +27,7 @@ type GatewayConfig struct {
2027
Upstream string `yaml:"upstream"`
2128
Scope string `yaml:"scope"`
2229
Decompose DecomposeConfig `yaml:"decompose,omitempty"`
30+
Judge *JudgeConfig `yaml:"judge,omitempty"`
2331
Log keepconfig.LogConfig `yaml:"log,omitempty"`
2432
}
2533

Collapse file

‎internal/gateway/config/config_test.go‎

Copy file name to clipboardExpand all lines: internal/gateway/config/config_test.go
+73Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -236,6 +236,79 @@ func TestDecomposeConfig_FieldParity(t *testing.T) {
236236
}
237237
}
238238

239+
func TestParseJudgeConfig(t *testing.T) {
240+
y := `
241+
listen: ":8080"
242+
rules_dir: "./rules"
243+
provider: anthropic
244+
upstream: "https://api.anthropic.com"
245+
scope: test-scope
246+
judge:
247+
provider: anthropic
248+
api_key_env: ANTHROPIC_API_KEY
249+
`
250+
path := writeTempYAML(t, y)
251+
cfg, err := Load(path)
252+
if err != nil {
253+
t.Fatalf("unexpected error: %v", err)
254+
}
255+
if cfg.Judge == nil {
256+
t.Fatal("expected judge config, got nil")
257+
}
258+
if cfg.Judge.Provider != "anthropic" {
259+
t.Errorf("judge.provider: got %q, want %q", cfg.Judge.Provider, "anthropic")
260+
}
261+
if cfg.Judge.APIKeyEnv != "ANTHROPIC_API_KEY" {
262+
t.Errorf("judge.api_key_env: got %q, want %q", cfg.Judge.APIKeyEnv, "ANTHROPIC_API_KEY")
263+
}
264+
}
265+
266+
func TestParseJudgeConfig_WithBaseURL(t *testing.T) {
267+
y := `
268+
listen: ":8080"
269+
rules_dir: "./rules"
270+
provider: anthropic
271+
upstream: "https://api.anthropic.com"
272+
scope: test-scope
273+
judge:
274+
provider: openai
275+
api_key_env: OPENAI_API_KEY
276+
base_url: "https://custom.openai.com"
277+
`
278+
path := writeTempYAML(t, y)
279+
cfg, err := Load(path)
280+
if err != nil {
281+
t.Fatalf("unexpected error: %v", err)
282+
}
283+
if cfg.Judge == nil {
284+
t.Fatal("expected judge config, got nil")
285+
}
286+
if cfg.Judge.Provider != "openai" {
287+
t.Errorf("judge.provider: got %q, want %q", cfg.Judge.Provider, "openai")
288+
}
289+
if cfg.Judge.BaseURL != "https://custom.openai.com" {
290+
t.Errorf("judge.base_url: got %q, want %q", cfg.Judge.BaseURL, "https://custom.openai.com")
291+
}
292+
}
293+
294+
func TestParseJudgeConfig_Absent(t *testing.T) {
295+
y := `
296+
listen: ":8080"
297+
rules_dir: "./rules"
298+
provider: anthropic
299+
upstream: "https://api.anthropic.com"
300+
scope: test-scope
301+
`
302+
path := writeTempYAML(t, y)
303+
cfg, err := Load(path)
304+
if err != nil {
305+
t.Fatalf("unexpected error: %v", err)
306+
}
307+
if cfg.Judge != nil {
308+
t.Errorf("expected nil judge config, got %+v", cfg.Judge)
309+
}
310+
}
311+
239312
// writeTempYAML writes content to a temp file and returns its path.
240313
func writeTempYAML(t *testing.T, content string) string {
241314
t.Helper()
Collapse file

‎internal/relay/config/config.go‎

Copy file name to clipboardExpand all lines: internal/relay/config/config.go
+8Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,21 @@ import (
99
keepconfig "github.com/majorcontext/keep/internal/config"
1010
)
1111

12+
// JudgeConfig holds configuration for the LLM-as-judge provider.
13+
type JudgeConfig struct {
14+
Provider string `yaml:"provider"`
15+
APIKeyEnv string `yaml:"api_key_env"`
16+
BaseURL string `yaml:"base_url,omitempty"`
17+
}
18+
1219
// RelayConfig holds the top-level relay configuration.
1320
type RelayConfig struct {
1421
Listen string `yaml:"listen"`
1522
RulesDir string `yaml:"rules_dir"`
1623
ProfilesDir string `yaml:"profiles_dir,omitempty"`
1724
PacksDir string `yaml:"packs_dir,omitempty"`
1825
Routes []Route `yaml:"routes"`
26+
Judge *JudgeConfig `yaml:"judge,omitempty"`
1927
Log keepconfig.LogConfig `yaml:"log,omitempty"`
2028
}
2129

Collapse file

‎internal/relay/config/config_test.go‎

Copy file name to clipboardExpand all lines: internal/relay/config/config_test.go
+73Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -267,6 +267,79 @@ routes:
267267
}
268268
}
269269

270+
func TestParseJudgeConfig(t *testing.T) {
271+
y := `
272+
listen: ":8090"
273+
rules_dir: "./rules"
274+
routes:
275+
- scope: test
276+
upstream: "https://example.com"
277+
judge:
278+
provider: anthropic
279+
api_key_env: ANTHROPIC_API_KEY
280+
`
281+
path := writeTempYAML(t, y)
282+
cfg, err := Load(path)
283+
if err != nil {
284+
t.Fatalf("unexpected error: %v", err)
285+
}
286+
if cfg.Judge == nil {
287+
t.Fatal("expected judge config, got nil")
288+
}
289+
if cfg.Judge.Provider != "anthropic" {
290+
t.Errorf("judge.provider: got %q, want %q", cfg.Judge.Provider, "anthropic")
291+
}
292+
if cfg.Judge.APIKeyEnv != "ANTHROPIC_API_KEY" {
293+
t.Errorf("judge.api_key_env: got %q, want %q", cfg.Judge.APIKeyEnv, "ANTHROPIC_API_KEY")
294+
}
295+
}
296+
297+
func TestParseJudgeConfig_WithBaseURL(t *testing.T) {
298+
y := `
299+
listen: ":8090"
300+
rules_dir: "./rules"
301+
routes:
302+
- scope: test
303+
upstream: "https://example.com"
304+
judge:
305+
provider: openai
306+
api_key_env: OPENAI_API_KEY
307+
base_url: "https://custom.openai.com"
308+
`
309+
path := writeTempYAML(t, y)
310+
cfg, err := Load(path)
311+
if err != nil {
312+
t.Fatalf("unexpected error: %v", err)
313+
}
314+
if cfg.Judge == nil {
315+
t.Fatal("expected judge config, got nil")
316+
}
317+
if cfg.Judge.Provider != "openai" {
318+
t.Errorf("judge.provider: got %q, want %q", cfg.Judge.Provider, "openai")
319+
}
320+
if cfg.Judge.BaseURL != "https://custom.openai.com" {
321+
t.Errorf("judge.base_url: got %q, want %q", cfg.Judge.BaseURL, "https://custom.openai.com")
322+
}
323+
}
324+
325+
func TestParseJudgeConfig_Absent(t *testing.T) {
326+
y := `
327+
listen: ":8090"
328+
rules_dir: "./rules"
329+
routes:
330+
- scope: test
331+
upstream: "https://example.com"
332+
`
333+
path := writeTempYAML(t, y)
334+
cfg, err := Load(path)
335+
if err != nil {
336+
t.Fatalf("unexpected error: %v", err)
337+
}
338+
if cfg.Judge != nil {
339+
t.Errorf("expected nil judge config, got %+v", cfg.Judge)
340+
}
341+
}
342+
270343
// writeTempYAML writes content to a temp file and returns its path.
271344
func writeTempYAML(t *testing.T, content string) string {
272345
t.Helper()

0 commit comments

Comments
0 (0)
You are visitor 01402792 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.