Skip to content

Commit 45ff58a

Browse files
committed
add cli option to explicitly enable the prompt toggle
Signed-off-by: Huamin Chen <[email protected]>
1 parent b034e46 commit 45ff58a

File tree

3 files changed

+398
-16
lines changed

3 files changed

+398
-16
lines changed

src/semantic-router/cmd/main.go

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,14 @@ import (
1515
func main() {
1616
// Parse command-line flags
1717
var (
18-
configPath = flag.String("config", "config/config.yaml", "Path to the configuration file")
19-
port = flag.Int("port", 50051, "Port to listen on for gRPC ExtProc")
20-
apiPort = flag.Int("api-port", 8080, "Port to listen on for Classification API")
21-
metricsPort = flag.Int("metrics-port", 9190, "Port for Prometheus metrics")
22-
enableAPI = flag.Bool("enable-api", true, "Enable Classification API server")
23-
secure = flag.Bool("secure", false, "Enable secure gRPC server with TLS")
24-
certPath = flag.String("cert-path", "", "Path to TLS certificate directory (containing tls.crt and tls.key)")
18+
configPath = flag.String("config", "config/config.yaml", "Path to the configuration file")
19+
port = flag.Int("port", 50051, "Port to listen on for gRPC ExtProc")
20+
apiPort = flag.Int("api-port", 8080, "Port to listen on for Classification API")
21+
metricsPort = flag.Int("metrics-port", 9190, "Port for Prometheus metrics")
22+
enableAPI = flag.Bool("enable-api", true, "Enable Classification API server")
23+
enableSystemPromptAPI = flag.Bool("enable-system-prompt-api", false, "Enable system prompt configuration endpoints (SECURITY: only enable in trusted environments)")
24+
secure = flag.Bool("secure", false, "Enable secure gRPC server with TLS")
25+
certPath = flag.String("cert-path", "", "Path to TLS certificate directory (containing tls.crt and tls.key)")
2526
)
2627
flag.Parse()
2728

@@ -58,7 +59,7 @@ func main() {
5859
if *enableAPI {
5960
go func() {
6061
observability.Infof("Starting Classification API server on port %d", *apiPort)
61-
if err := api.StartClassificationAPI(*configPath, *apiPort); err != nil {
62+
if err := api.StartClassificationAPI(*configPath, *apiPort, *enableSystemPromptAPI); err != nil {
6263
observability.Errorf("Classification API server error: %v", err)
6364
}
6465
}()

src/semantic-router/pkg/api/server.go

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,9 @@ import (
1717

1818
// ClassificationAPIServer holds the server state and dependencies
1919
type ClassificationAPIServer struct {
20-
classificationSvc *services.ClassificationService
21-
config *config.RouterConfig
20+
classificationSvc *services.ClassificationService
21+
config *config.RouterConfig
22+
enableSystemPromptAPI bool
2223
}
2324

2425
// ModelsInfoResponse represents the response for models info endpoint
@@ -101,7 +102,7 @@ type ClassificationOptions struct {
101102
}
102103

103104
// StartClassificationAPI starts the Classification API server
104-
func StartClassificationAPI(configPath string, port int) error {
105+
func StartClassificationAPI(configPath string, port int, enableSystemPromptAPI bool) error {
105106
// Load configuration
106107
cfg, err := config.LoadConfig(configPath)
107108
if err != nil {
@@ -139,8 +140,9 @@ func StartClassificationAPI(configPath string, port int) error {
139140

140141
// Create server instance
141142
apiServer := &ClassificationAPIServer{
142-
classificationSvc: classificationSvc,
143-
config: cfg,
143+
classificationSvc: classificationSvc,
144+
config: cfg,
145+
enableSystemPromptAPI: enableSystemPromptAPI,
144146
}
145147

146148
// Create HTTP server with routes
@@ -203,9 +205,14 @@ func (s *ClassificationAPIServer) setupRoutes() *http.ServeMux {
203205
mux.HandleFunc("GET /config/classification", s.handleGetConfig)
204206
mux.HandleFunc("PUT /config/classification", s.handleUpdateConfig)
205207

206-
// System prompt configuration endpoints
207-
mux.HandleFunc("GET /config/system-prompts", s.handleGetSystemPrompts)
208-
mux.HandleFunc("PUT /config/system-prompts", s.handleUpdateSystemPrompts)
208+
// System prompt configuration endpoints (only if explicitly enabled)
209+
if s.enableSystemPromptAPI {
210+
observability.Infof("System prompt configuration endpoints enabled")
211+
mux.HandleFunc("GET /config/system-prompts", s.handleGetSystemPrompts)
212+
mux.HandleFunc("PUT /config/system-prompts", s.handleUpdateSystemPrompts)
213+
} else {
214+
observability.Infof("System prompt configuration endpoints disabled for security")
215+
}
209216

210217
return mux
211218
}

0 commit comments

Comments
 (0)