Add a new llm service that proxies chat-completion requests from AI web extensions to a configured OpenAI-compatible endpoint, replacing the standalone Node.js sidecar. It is part of the oCIS single binary, opt-in via OCIS_ADD_RUN_SERVICES=llm, and exposed through the proxy at POST /graph/v1beta1/extensions/org.libregraph/llm/chat/completions. Authentication is delegated to oCIS. Requests are rate-limited per user with a sliding window backed by the shared store, and the request body is sanitized before forwarding. Streaming requests are rejected. Signed-off-by: Lukas Hirt <info@hirt.cz>
39 lines
1.3 KiB
Go
39 lines
1.3 KiB
Go
// services/llm/pkg/server/debug/server.go
|
|
package debug
|
|
|
|
import (
|
|
"net/http"
|
|
|
|
"github.com/owncloud/ocis/v2/ocis-pkg/checks"
|
|
"github.com/owncloud/ocis/v2/ocis-pkg/handlers"
|
|
"github.com/owncloud/ocis/v2/ocis-pkg/service/debug"
|
|
"github.com/owncloud/ocis/v2/ocis-pkg/version"
|
|
)
|
|
|
|
// Server initializes the debug service and server.
|
|
func Server(opts ...Option) (*http.Server, error) {
|
|
options := newOptions(opts...)
|
|
|
|
checkHandler := handlers.NewCheckHandler(
|
|
handlers.NewCheckHandlerConfiguration().
|
|
WithLogger(options.Logger).
|
|
WithCheck("llm reachability", checks.NewHTTPCheck(options.Config.HTTP.Addr)),
|
|
)
|
|
|
|
return debug.NewService(
|
|
debug.Logger(options.Logger),
|
|
debug.Name(options.Config.Service.Name),
|
|
debug.Version(version.GetString()),
|
|
debug.Address(options.Config.Debug.Addr),
|
|
debug.Token(options.Config.Debug.Token),
|
|
debug.Pprof(options.Config.Debug.Pprof),
|
|
debug.Zpages(options.Config.Debug.Zpages),
|
|
debug.Health(checkHandler),
|
|
debug.Ready(checkHandler),
|
|
debug.CorsAllowedOrigins(options.Config.HTTP.CORS.AllowedOrigins),
|
|
debug.CorsAllowedMethods(options.Config.HTTP.CORS.AllowedMethods),
|
|
debug.CorsAllowedHeaders(options.Config.HTTP.CORS.AllowedHeaders),
|
|
debug.CorsAllowCredentials(options.Config.HTTP.CORS.AllowCredentials),
|
|
), nil
|
|
}
|