diff --git a/docs/docs/configurations/cors.mdx b/docs/docs/configurations/cors.mdx new file mode 100644 index 000000000..2ea6907de --- /dev/null +++ b/docs/docs/configurations/cors.mdx @@ -0,0 +1,176 @@ +--- +title: CORS +description: Setting up CORS +slug: "cors" +--- + +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. +::: + +# CORS Configuration Guide + +This document describes how to configure Cross-Origin Resource Sharing (CORS) settings for the API server using both CLI commands and HTTP API endpoints. + +## 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 | + +-----------------+-------------------+ + | allowed_origins | http://localhost | + +-----------------+-------------------+ + | allowed_origins | https://cortex.so | + +-----------------+-------------------+ + | cors | true | + +-----------------+-------------------+ + ``` + +### Options + +| Option | Description | Example | +| ----------------------------- | ------------------------------------------------------------ | -------------------------------------------------------------------- | +| `-h, --help` | Print help message and exit | +| `--cors [on/off]` | Toggle CORS functionality | cortex config --cors on | +| `--allowed_origins [origins]` | Set allowed origins for CORS, comma separated without spaces | `cortex config --allowed_origins http://localhost,https://cortex.so` | + +### Examples + +1. Toggle CORS on: + + ```bash + cortex config --cors on + ``` + +2. Toggle CORS off: + + ```bash + cortex config --cors off + ``` + +3. Set allowed origins: + + ```bash + cortex config --allowed_origins http://localhost,https://cortex.so + ``` + +4. View current configuration: + ```bash + cortex config status + ``` + +## CORS API Configuration + +This document describes the REST API endpoints available for managing CORS configurations. + +### Endpoints + +#### Get Current Configuration + +```http +GET /v1/configs +``` + +Retrieves the current CORS configuration settings. + +##### Response + +```json +{ + "allowed_origins": ["http://localhost:39281"], + "cors": true +} +``` + +#### Update Configuration + +```http +PATCH /v1/configs +``` + +Updates CORS configuration settings. + +##### Request Headers + +``` +Content-Type: application/json +``` + +##### Request Body + +```json +{ + "cors": true, + "allowed_origins": ["http://localhost:39281"] +} +``` + +##### Parameters + +| Field | Type | Description | +| ----------------- | -------- | ---------------------------- | +| `cors` | boolean | Enable or disable CORS | +| `allowed_origins` | string[] | Array of allowed origin URLs | + +##### Response + +```json +{ + "config": { + "allowed_origins": ["http://localhost:39281"], + "cors": true + }, + "message": "Configuration updated successfully" +} +``` + +### Example cURL Commands + +#### Get Configuration + +```bash +curl --location 'http://127.0.0.1:39281/v1/configs' +``` + +#### Update Configuration + +```bash +curl --location --request PATCH 'http://127.0.0.1:39281/v1/configs' \ +--header 'Content-Type: application/json' \ +--data '{ + "cors": true, + "allowed_origins": [ + "http://localhost:39281" + ] +}' +``` + +## Notes + +- Origins for CORS should be provided as comma-separated values without spaces +- The `--allowed_origins` option only takes effect when CORS is enabled + +## Best Practices + +1. Always verify CORS status after toggling +2. Double-check allowed origins to prevent security issues +3. Use the `status` command to confirm changes have been applied correctly diff --git a/docs/docs/configurations/index.mdx b/docs/docs/configurations/index.mdx new file mode 100644 index 000000000..38e7d8e92 --- /dev/null +++ b/docs/docs/configurations/index.mdx @@ -0,0 +1,12 @@ +--- +slug: /configurations +title: Cortex configurations +--- + +# Cortex Configurations + +Welcome to the Cortex configurations documentation. Here you will find detailed guides and references for configuring various aspects of Cortex, including: + +- **CORS**: Learn how to set up Cross-Origin Resource Sharing. + +Use the sidebar to navigate through the different configuration topics. diff --git a/docs/sidebars.ts b/docs/sidebars.ts index 5249c743d..126673f1a 100644 --- a/docs/sidebars.ts +++ b/docs/sidebars.ts @@ -36,7 +36,7 @@ const sidebars: SidebarsConfig = { label: "Installation", link: { type: "doc", - id: "installation" + id: "installation", }, collapsed: true, items: [ @@ -74,11 +74,28 @@ const sidebars: SidebarsConfig = { }, collapsed: true, items: [ - { type: "doc", id: "architecture/data-folder", label: "Cortex Data Folder" }, + { + type: "doc", + id: "architecture/data-folder", + label: "Cortex Data Folder", + }, { type: "doc", id: "architecture/cortex-db", label: "cortex.db" }, { type: "doc", id: "architecture/cortexrc", label: ".cortexrc" }, { type: "doc", id: "architecture/updater", label: "Updater" }, - ] + ], + }, + { + type: "category", + label: "Configurations", + link: { type: "doc", id: "configurations/index" }, + collapsed: true, + items: [ + { + type: "doc", + id: "configurations/cors", + label: "CORS", + }, + ], }, { type: "html", @@ -99,11 +116,19 @@ const sidebars: SidebarsConfig = { { type: "category", label: "Running Models", - link: { type: "doc", id: "capabilities/models/index"}, + link: { type: "doc", id: "capabilities/models/index" }, collapsed: true, items: [ - { type: "doc", id: "capabilities/models/model-yaml", label: "model.yaml" }, - { type: "doc", id: "capabilities/models/presets", label: "Model Presets" }, + { + type: "doc", + id: "capabilities/models/model-yaml", + label: "model.yaml", + }, + { + type: "doc", + id: "capabilities/models/presets", + label: "Model Presets", + }, ], }, { @@ -115,8 +140,11 @@ const sidebars: SidebarsConfig = { { type: "doc", id: "engines/llamacpp", label: "llama.cpp" }, // { type: "doc", id: "engines/tensorrt-llm", label: "TensorRT-LLM" }, // { type: "doc", id: "engines/onnx", label: "ONNX" }, - { type: "doc", id: "engines/engine-extension", label: "Building Engine Extensions" }, - + { + type: "doc", + id: "engines/engine-extension", + label: "Building Engine Extensions", + }, ], }, { @@ -124,10 +152,13 @@ const sidebars: SidebarsConfig = { label: "Hardware Awareness", link: { type: "doc", id: "capabilities/hardware/index" }, collapsed: true, - items: [ - ], + items: [], + }, + { + type: "doc", + id: "capabilities/text-generation", + label: "Text Generation", }, - { type: "doc", id: "capabilities/text-generation", label: "Text Generation" }, // { type: "doc", id: "capabilities/image-generation", label: "Image Generation" }, // { type: "doc", id: "capabilities/vision", label: "Vision" }, // { type: "doc", id: "capabilities/audio-generation", label: "Audio Generation" }, @@ -141,14 +172,18 @@ const sidebars: SidebarsConfig = { value: "GUIDES", className: "sidebar-divider", }, - { type: "doc", id: "guides/function-calling", label: "Function Calling"}, - { type: "doc", id: "guides/structured-outputs", label: "Structured Outputs"}, + { type: "doc", id: "guides/function-calling", label: "Function Calling" }, + { + type: "doc", + id: "guides/structured-outputs", + label: "Structured Outputs", + }, { type: "html", value: "ASSISTANTS", className: "sidebar-divider", }, - { type: "doc", id: "assistants/index", label: "Assistants"}, + { type: "doc", id: "assistants/index", label: "Assistants" }, { type: "category", label: "Tools", @@ -173,9 +208,9 @@ const sidebars: SidebarsConfig = { { type: "doc", id: "cli/models/index", label: "cortex models" }, { type: "doc", id: "cli/engines/index", label: "cortex engines" }, { type: "doc", id: "cli/ps", label: "cortex ps" }, - { type: "doc", id: "cli/update", label: "cortex update" }, + { type: "doc", id: "cli/update", label: "cortex update" }, { type: "doc", id: "cli/stop", label: "cortex stop" }, - ] + ], }; export default sidebars;