Skip to content
This repository was archived by the owner on Jul 4, 2025. It is now read-only.

Commit 37fecbd

Browse files
feat: API to configure huggingface_token (#1699)
* feat: API for configuring huggingface token * chore: API docs * chore: Token docs * chore: docs --------- Co-authored-by: vansangpfiev <sang@jan.ai>
1 parent 9ff93c5 commit 37fecbd

File tree

5 files changed

+174
-11
lines changed

5 files changed

+174
-11
lines changed

docs/docs/configurations/token.mdx

Lines changed: 120 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,120 @@
1+
---
2+
title: Token
3+
description: Setting up token
4+
slug: "token"
5+
---
6+
7+
import Tabs from "@theme/Tabs";
8+
import TabItem from "@theme/TabItem";
9+
10+
:::warning
11+
🚧 Cortex.cpp is currently under development. Our documentation outlines the intended behavior of Cortex, which may not yet be fully implemented in the codebase.
12+
:::
13+
14+
# Token Configuration Guide
15+
16+
This document describes how to configure HuggingFace token settings for Cortex.
17+
18+
## Command Line Interface (CLI)
19+
20+
### Basic Usage
21+
22+
```bash
23+
cortex config [OPTIONS] [COMMAND]
24+
```
25+
26+
### Commands
27+
28+
- `status`: Display all current configurations
29+
30+
```bash
31+
cortex config status
32+
```
33+
34+
Example Output:
35+
36+
```bash
37+
+-----------------------+------------------------+
38+
| Config name | Value |
39+
+-----------------------+------------------------+
40+
| huggingface_token | |
41+
+-----------------------+------------------------+
42+
```
43+
44+
### Options
45+
46+
| Option | Description | Example |
47+
| ----------------------------------- | --------------------------- | ------------------------------------------------- |
48+
| `-h, --help` | Print help message and exit |
49+
| `--huggingface_token <token>` | Set HuggingFace token | `cortex config --huggingface_token token` |
50+
51+
## Token API Configuration
52+
53+
### Endpoints
54+
55+
#### Get Current Configuration
56+
57+
```http
58+
GET /v1/configs
59+
```
60+
61+
Retrieves the current configuration settings.
62+
63+
##### Response
64+
65+
```json
66+
{
67+
"allowed_origins": [
68+
"http://localhost:39281",
69+
"http://127.0.0.1:39281",
70+
"http://0.0.0.0:39281"
71+
],
72+
"cors": true,
73+
"huggingface_token": ""
74+
}
75+
```
76+
77+
#### Update Configuration
78+
79+
```http
80+
PATCH /v1/configs
81+
```
82+
83+
Updates HuggingFace token configuration settings.
84+
85+
##### Request Headers
86+
87+
```
88+
Content-Type: application/json
89+
```
90+
91+
##### Request Body
92+
93+
```json
94+
{
95+
"huggingface_token": "token"
96+
}
97+
```
98+
99+
##### Parameters
100+
101+
| Field | Type | Description |
102+
| ----------------------- | ------- | ------------------------------------------|
103+
| `huggingface_token` | string | HuggingFace token to pull models |
104+
105+
##### Response
106+
107+
```json
108+
{
109+
"config": {
110+
"allowed_origins": [
111+
"http://localhost:39281",
112+
"http://127.0.0.1:39281",
113+
"http://0.0.0.0:39281"
114+
],
115+
"cors": true,
116+
"huggingface_token": "token"
117+
},
118+
"message": "Configuration updated successfully"
119+
}
120+
```

docs/sidebars.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,11 @@ const sidebars: SidebarsConfig = {
100100
id: "configurations/proxy",
101101
label: "Proxy",
102102
},
103+
{
104+
type: "doc",
105+
id: "configurations/token",
106+
label: "Token",
107+
}
103108
],
104109
},
105110
{

docs/static/openapi/cortex.json

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1810,6 +1810,10 @@
18101810
"no_proxy": {
18111811
"type": "string",
18121812
"example": "localhost"
1813+
},
1814+
"huggingface_token": {
1815+
"type": "string",
1816+
"example": "your_token"
18131817
}
18141818
}
18151819
},
@@ -1826,7 +1830,8 @@
18261830
"verify_proxy_host_ssl": false,
18271831
"verify_peer_ssl": false,
18281832
"verify_host_ssl": false,
1829-
"no_proxy": "localhost"
1833+
"no_proxy": "localhost",
1834+
"huggingface_token": "your_token"
18301835
}
18311836
}
18321837
}
@@ -1896,6 +1901,11 @@
18961901
"type": "string",
18971902
"description": "List of hosts that should not be proxied.",
18981903
"example": "localhost"
1904+
},
1905+
"huggingface_token": {
1906+
"type": "string",
1907+
"description": "HuggingFace token to pull models.",
1908+
"example": "your_token"
18991909
}
19001910
}
19011911
}
@@ -1958,6 +1968,10 @@
19581968
"no_proxy": {
19591969
"type": "string",
19601970
"example": "localhost"
1971+
},
1972+
"huggingface_token": {
1973+
"type": "string",
1974+
"example": "your_token"
19611975
}
19621976
}
19631977
},

engine/common/api_server_configuration.h

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,13 @@ static const std::unordered_map<std::string, ApiConfigurationMetadata>
9090
.group = "Proxy",
9191
.accept_value = "[on|off]",
9292
.default_value = "on"}},
93+
{"huggingface_token",
94+
ApiConfigurationMetadata{.name = "huggingface_token",
95+
.desc = "HuggingFace token to pull models",
96+
.group = "Token",
97+
.accept_value = "string",
98+
.default_value = "",
99+
.allow_empty = true}},
93100
};
94101

95102
class ApiServerConfiguration {
@@ -99,7 +106,8 @@ class ApiServerConfiguration {
99106
bool verify_proxy_ssl = true, bool verify_proxy_host_ssl = true,
100107
const std::string& proxy_url = "", const std::string& proxy_username = "",
101108
const std::string& proxy_password = "", const std::string& no_proxy = "",
102-
bool verify_peer_ssl = true, bool verify_host_ssl = true)
109+
bool verify_peer_ssl = true, bool verify_host_ssl = true,
110+
const std::string& hf_token = "")
103111
: cors{cors},
104112
allowed_origins{allowed_origins},
105113
verify_proxy_ssl{verify_proxy_ssl},
@@ -109,7 +117,8 @@ class ApiServerConfiguration {
109117
proxy_password{proxy_password},
110118
no_proxy{no_proxy},
111119
verify_peer_ssl{verify_peer_ssl},
112-
verify_host_ssl{verify_host_ssl} {}
120+
verify_host_ssl{verify_host_ssl},
121+
hf_token{hf_token} {}
113122

114123
// cors
115124
bool cors{true};
@@ -127,6 +136,9 @@ class ApiServerConfiguration {
127136
bool verify_peer_ssl{true};
128137
bool verify_host_ssl{true};
129138

139+
// token
140+
std::string hf_token{""};
141+
130142
Json::Value ToJson() const {
131143
Json::Value root;
132144
root["cors"] = cors;
@@ -142,6 +154,7 @@ class ApiServerConfiguration {
142154
root["no_proxy"] = no_proxy;
143155
root["verify_peer_ssl"] = verify_peer_ssl;
144156
root["verify_host_ssl"] = verify_host_ssl;
157+
root["huggingface_token"] = hf_token;
145158

146159
return root;
147160
}
@@ -225,6 +238,15 @@ class ApiServerConfiguration {
225238
return true;
226239
}},
227240

241+
{"huggingface_token",
242+
[this](const Json::Value& value) -> bool {
243+
if (!value.isString()) {
244+
return false;
245+
}
246+
hf_token = value.asString();
247+
return true;
248+
}},
249+
228250
{"cors",
229251
[this](const Json::Value& value) -> bool {
230252
if (!value.isBool()) {

engine/services/config_service.cc

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,10 @@ cpp::result<ApiServerConfiguration, std::string>
66
ConfigService::UpdateApiServerConfiguration(const Json::Value& json) {
77
auto config = file_manager_utils::GetCortexConfig();
88
ApiServerConfiguration api_server_config{
9-
config.enableCors, config.allowedOrigins, config.verifyProxySsl,
10-
config.verifyProxyHostSsl, config.proxyUrl, config.proxyUsername,
11-
config.proxyPassword, config.noProxy, config.verifyPeerSsl,
12-
config.verifyHostSsl};
9+
config.enableCors, config.allowedOrigins, config.verifyProxySsl,
10+
config.verifyProxyHostSsl, config.proxyUrl, config.proxyUsername,
11+
config.proxyPassword, config.noProxy, config.verifyPeerSsl,
12+
config.verifyHostSsl, config.huggingFaceToken};
1313

1414
std::vector<std::string> updated_fields;
1515
std::vector<std::string> invalid_fields;
@@ -35,6 +35,8 @@ ConfigService::UpdateApiServerConfiguration(const Json::Value& json) {
3535
config.verifyPeerSsl = api_server_config.verify_peer_ssl;
3636
config.verifyHostSsl = api_server_config.verify_host_ssl;
3737

38+
config.huggingFaceToken = api_server_config.hf_token;
39+
3840
auto result = file_manager_utils::UpdateCortexConfig(config);
3941
return api_server_config;
4042
}
@@ -43,8 +45,8 @@ cpp::result<ApiServerConfiguration, std::string>
4345
ConfigService::GetApiServerConfiguration() {
4446
auto config = file_manager_utils::GetCortexConfig();
4547
return ApiServerConfiguration{
46-
config.enableCors, config.allowedOrigins, config.verifyProxySsl,
47-
config.verifyProxyHostSsl, config.proxyUrl, config.proxyUsername,
48-
config.proxyPassword, config.noProxy, config.verifyPeerSsl,
49-
config.verifyHostSsl};
48+
config.enableCors, config.allowedOrigins, config.verifyProxySsl,
49+
config.verifyProxyHostSsl, config.proxyUrl, config.proxyUsername,
50+
config.proxyPassword, config.noProxy, config.verifyPeerSsl,
51+
config.verifyHostSsl, config.huggingFaceToken};
5052
}

0 commit comments

Comments
 (0)