From e8c63786867dcfd9b2af895af03f92b5c8080a7c Mon Sep 17 00:00:00 2001 From: Andrew Wray Date: Sun, 13 Jul 2025 16:33:02 +0100 Subject: [PATCH] Route questions to ChatGPT --- README.md | 1 + cmd/sea/main_test.go | 11 +++++++++++ cmd/sea/nginx.conf.tmpl | 2 ++ nginx.conf | 4 ++++ 4 files changed, 18 insertions(+) diff --git a/README.md b/README.md index 04f5996..072faea 100644 --- a/README.md +++ b/README.md @@ -17,6 +17,7 @@ applied to `nginx`. security profile, as there is no web app to exploit. - **Optimized Matching**: Regex rules are evaluated once per request using NGINX's `map` directive. Enable `pcre_jit` for the best performance. +- **Question Detection**: Queries ending with a question mark are automatically routed to ChatGPT. ## Installation diff --git a/cmd/sea/main_test.go b/cmd/sea/main_test.go index c7582f1..81f43de 100644 --- a/cmd/sea/main_test.go +++ b/cmd/sea/main_test.go @@ -98,3 +98,14 @@ func TestGenerateNginx(t *testing.T) { t.Errorf("generated config missing error log disable: %s", out) } } + +func TestQuestionMarkRulePresent(t *testing.T) { + cfg := Config{} + out, err := generateNginx(cfg) + if err != nil { + t.Fatalf("failed to generate nginx: %v", err) + } + if !strings.Contains(out, "\\?\\s*$") { + t.Errorf("question mark routing rule missing: %s", out) + } +} diff --git a/cmd/sea/nginx.conf.tmpl b/cmd/sea/nginx.conf.tmpl index 6240802..68cda49 100644 --- a/cmd/sea/nginx.conf.tmpl +++ b/cmd/sea/nginx.conf.tmpl @@ -26,6 +26,8 @@ map $arg_q $sea_dest { ~*(?i)^(style|proofread|review|listen|plot|graph|chart|map)\b chatgpt; ~*(?i)^(diagram|simulate|predict|forecast|estimate|answer|reply)\b chatgpt; ~*(?i)^(respond|inquire|query|request|discuss)\b chatgpt; + # route any query ending with a question mark to ChatGPT + ~*(?i)\?\s*$ chatgpt; # explicit wiki keywords ~*(?i)\bwikipedia\b|\bwiki\b wikipedia; {{- range .CustomKeywords }} diff --git a/nginx.conf b/nginx.conf index 64ab506..679f55c 100644 --- a/nginx.conf +++ b/nginx.conf @@ -26,6 +26,8 @@ map $arg_q $sea_dest { ~*(?i)^(style|proofread|review|listen|plot|graph|chart|map)\b chatgpt; ~*(?i)^(diagram|simulate|predict|forecast|estimate|answer|reply)\b chatgpt; ~*(?i)^(respond|inquire|query|request|discuss)\b chatgpt; + # route any query ending with a question mark to ChatGPT + ~*(?i)\?\s*$ chatgpt; # explicit wiki keywords ~*(?i)\bwikipedia\b|\bwiki\b wikipedia; default google; @@ -45,6 +47,8 @@ server { listen 80; listen [::]:80; server_name search.localhost; + access_log off; + error_log /dev/null crit; location / { return 302 $sea_target;