cnn_settings.go 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. package main
  2. import (
  3. "net/http"
  4. prout "imuslab.com/arozos/mod/prouter"
  5. "imuslab.com/arozos/mod/utils"
  6. )
  7. /*
  8. CNN Inference Settings Manager
  9. Registers the "CNN Inference" tab in System Settings > AI Integration and
  10. exposes the admin-only endpoints used to configure the external CXNNAIO
  11. vision-inference server (endpoint, token, request timeout) and to test
  12. connectivity against it.
  13. The AGI "cnn" library (mod/agi/agi.cnn.go) consumes the same configuration
  14. and is what AGI scripts actually call via requirelib("cnn"); the wire
  15. protocol itself lives in the standalone mod/aiservers/cnn client package.
  16. GET /system/cnn/config – masked connection config
  17. POST /system/cnn/config – save connection config
  18. POST /system/cnn/test – connectivity test (health + model listing)
  19. All endpoints require administrator privileges.
  20. */
  21. func CNNInferenceSettingInit() {
  22. //Register the settings tab in the "AI Integration" group.
  23. registerSetting(settingModule{
  24. Name: "CNN Inference",
  25. Desc: "Configure an external CXNNAIO vision-inference server for image/face recognition",
  26. IconPath: "SystemAO/system_setting/img/cnn.svg",
  27. Group: "AInteg",
  28. StartDir: "SystemAO/advance/cnninference.html",
  29. RequireAdmin: true,
  30. })
  31. //Admin-only router. The connection config may contain a sensitive API
  32. //token, so every endpoint here is restricted to administrators.
  33. adminRouter := prout.NewModuleRouter(prout.RouterOption{
  34. ModuleName: "System Settings",
  35. AdminOnly: true,
  36. UserHandler: userHandler,
  37. DeniedHandler: func(w http.ResponseWriter, r *http.Request) {
  38. utils.SendErrorResponse(w, "Permission Denied")
  39. },
  40. })
  41. adminRouter.HandleFunc("/system/cnn/config", AGIGateway.HandleCNNConfig)
  42. adminRouter.HandleFunc("/system/cnn/test", AGIGateway.HandleCNNTest)
  43. }