diff --git a/docs/docs/configurations/token.mdx b/docs/docs/configurations/token.mdx new file mode 100644 index 000000000..687879cb4 --- /dev/null +++ b/docs/docs/configurations/token.mdx @@ -0,0 +1,120 @@ +--- +title: Token +description: Setting up token +slug: "token" +--- + +import Tabs from "@theme/Tabs"; +import TabItem from "@theme/TabItem"; + +:::warning +🚧 Cortex.cpp is currently under development. Our documentation outlines the intended behavior of Cortex, which may not yet be fully implemented in the codebase. +::: + +# Token Configuration Guide + +This document describes how to configure HuggingFace token settings for Cortex. + +## Command Line Interface (CLI) + +### Basic Usage + +```bash +cortex config [OPTIONS] [COMMAND] +``` + +### Commands + +- `status`: Display all current configurations + +```bash +cortex config status +``` + +Example Output: + +```bash ++-----------------------+------------------------+ +| Config name | Value | ++-----------------------+------------------------+ +| huggingface_token | | ++-----------------------+------------------------+ +``` + +### Options + +| Option | Description | Example | +| ----------------------------------- | --------------------------- | ------------------------------------------------- | +| `-h, --help` | Print help message and exit | +| `--huggingface_token ` | Set HuggingFace token | `cortex config --huggingface_token token` | + +## Token API Configuration + +### Endpoints + +#### Get Current Configuration + +```http +GET /v1/configs +``` + +Retrieves the current configuration settings. + +##### Response + +```json +{ + "allowed_origins": [ + "http://localhost:39281", + "http://127.0.0.1:39281", + "http://0.0.0.0:39281" + ], + "cors": true, + "huggingface_token": "" +} +``` + +#### Update Configuration + +```http +PATCH /v1/configs +``` + +Updates HuggingFace token configuration settings. + +##### Request Headers + +``` +Content-Type: application/json +``` + +##### Request Body + +```json +{ + "huggingface_token": "token" +} +``` + +##### Parameters + +| Field | Type | Description | +| ----------------------- | ------- | ------------------------------------------| +| `huggingface_token` | string | HuggingFace token to pull models | + +##### Response + +```json +{ + "config": { + "allowed_origins": [ + "http://localhost:39281", + "http://127.0.0.1:39281", + "http://0.0.0.0:39281" + ], + "cors": true, + "huggingface_token": "token" + }, + "message": "Configuration updated successfully" +} +``` \ No newline at end of file diff --git a/docs/sidebars.ts b/docs/sidebars.ts index 188d99317..8c0800345 100644 --- a/docs/sidebars.ts +++ b/docs/sidebars.ts @@ -100,6 +100,11 @@ const sidebars: SidebarsConfig = { id: "configurations/proxy", label: "Proxy", }, + { + type: "doc", + id: "configurations/token", + label: "Token", + } ], }, { diff --git a/docs/static/openapi/cortex.json b/docs/static/openapi/cortex.json index 9747a1830..1ac69d78e 100644 --- a/docs/static/openapi/cortex.json +++ b/docs/static/openapi/cortex.json @@ -1810,6 +1810,10 @@ "no_proxy": { "type": "string", "example": "localhost" + }, + "huggingface_token": { + "type": "string", + "example": "your_token" } } }, @@ -1826,7 +1830,8 @@ "verify_proxy_host_ssl": false, "verify_peer_ssl": false, "verify_host_ssl": false, - "no_proxy": "localhost" + "no_proxy": "localhost", + "huggingface_token": "your_token" } } } @@ -1896,6 +1901,11 @@ "type": "string", "description": "List of hosts that should not be proxied.", "example": "localhost" + }, + "huggingface_token": { + "type": "string", + "description": "HuggingFace token to pull models.", + "example": "your_token" } } } @@ -1958,6 +1968,10 @@ "no_proxy": { "type": "string", "example": "localhost" + }, + "huggingface_token": { + "type": "string", + "example": "your_token" } } }, diff --git a/engine/common/api_server_configuration.h b/engine/common/api_server_configuration.h index 5bfcbbdc5..03b3022a4 100644 --- a/engine/common/api_server_configuration.h +++ b/engine/common/api_server_configuration.h @@ -90,6 +90,13 @@ static const std::unordered_map .group = "Proxy", .accept_value = "[on|off]", .default_value = "on"}}, + {"huggingface_token", + ApiConfigurationMetadata{.name = "huggingface_token", + .desc = "HuggingFace token to pull models", + .group = "Token", + .accept_value = "string", + .default_value = "", + .allow_empty = true}}, }; class ApiServerConfiguration { @@ -99,7 +106,8 @@ class ApiServerConfiguration { bool verify_proxy_ssl = true, bool verify_proxy_host_ssl = true, const std::string& proxy_url = "", const std::string& proxy_username = "", const std::string& proxy_password = "", const std::string& no_proxy = "", - bool verify_peer_ssl = true, bool verify_host_ssl = true) + bool verify_peer_ssl = true, bool verify_host_ssl = true, + const std::string& hf_token = "") : cors{cors}, allowed_origins{allowed_origins}, verify_proxy_ssl{verify_proxy_ssl}, @@ -109,7 +117,8 @@ class ApiServerConfiguration { proxy_password{proxy_password}, no_proxy{no_proxy}, verify_peer_ssl{verify_peer_ssl}, - verify_host_ssl{verify_host_ssl} {} + verify_host_ssl{verify_host_ssl}, + hf_token{hf_token} {} // cors bool cors{true}; @@ -127,6 +136,9 @@ class ApiServerConfiguration { bool verify_peer_ssl{true}; bool verify_host_ssl{true}; + // token + std::string hf_token{""}; + Json::Value ToJson() const { Json::Value root; root["cors"] = cors; @@ -142,6 +154,7 @@ class ApiServerConfiguration { root["no_proxy"] = no_proxy; root["verify_peer_ssl"] = verify_peer_ssl; root["verify_host_ssl"] = verify_host_ssl; + root["huggingface_token"] = hf_token; return root; } @@ -225,6 +238,15 @@ class ApiServerConfiguration { return true; }}, + {"huggingface_token", + [this](const Json::Value& value) -> bool { + if (!value.isString()) { + return false; + } + hf_token = value.asString(); + return true; + }}, + {"cors", [this](const Json::Value& value) -> bool { if (!value.isBool()) { diff --git a/engine/services/config_service.cc b/engine/services/config_service.cc index 9c794bb38..ce5526090 100644 --- a/engine/services/config_service.cc +++ b/engine/services/config_service.cc @@ -6,10 +6,10 @@ cpp::result ConfigService::UpdateApiServerConfiguration(const Json::Value& json) { auto config = file_manager_utils::GetCortexConfig(); ApiServerConfiguration api_server_config{ - config.enableCors, config.allowedOrigins, config.verifyProxySsl, - config.verifyProxyHostSsl, config.proxyUrl, config.proxyUsername, - config.proxyPassword, config.noProxy, config.verifyPeerSsl, - config.verifyHostSsl}; + config.enableCors, config.allowedOrigins, config.verifyProxySsl, + config.verifyProxyHostSsl, config.proxyUrl, config.proxyUsername, + config.proxyPassword, config.noProxy, config.verifyPeerSsl, + config.verifyHostSsl, config.huggingFaceToken}; std::vector updated_fields; std::vector invalid_fields; @@ -35,6 +35,8 @@ ConfigService::UpdateApiServerConfiguration(const Json::Value& json) { config.verifyPeerSsl = api_server_config.verify_peer_ssl; config.verifyHostSsl = api_server_config.verify_host_ssl; + config.huggingFaceToken = api_server_config.hf_token; + auto result = file_manager_utils::UpdateCortexConfig(config); return api_server_config; } @@ -43,8 +45,8 @@ cpp::result ConfigService::GetApiServerConfiguration() { auto config = file_manager_utils::GetCortexConfig(); return ApiServerConfiguration{ - config.enableCors, config.allowedOrigins, config.verifyProxySsl, - config.verifyProxyHostSsl, config.proxyUrl, config.proxyUsername, - config.proxyPassword, config.noProxy, config.verifyPeerSsl, - config.verifyHostSsl}; + config.enableCors, config.allowedOrigins, config.verifyProxySsl, + config.verifyProxyHostSsl, config.proxyUrl, config.proxyUsername, + config.proxyPassword, config.noProxy, config.verifyPeerSsl, + config.verifyHostSsl, config.huggingFaceToken}; }