Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

docs: add cors docs #1652

Merged
merged 2 commits into from
Nov 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
176 changes: 176 additions & 0 deletions docs/docs/configurations/cors.mdx
Original file line number Diff line number Diff line change
@@ -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
12 changes: 12 additions & 0 deletions docs/docs/configurations/index.mdx
Original file line number Diff line number Diff line change
@@ -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.
67 changes: 51 additions & 16 deletions docs/sidebars.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ const sidebars: SidebarsConfig = {
label: "Installation",
link: {
type: "doc",
id: "installation"
id: "installation",
},
collapsed: true,
items: [
Expand Down Expand Up @@ -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",
Expand All @@ -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",
},
],
},
{
Expand All @@ -115,19 +140,25 @@ 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",
},
],
},
{
type: "category",
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" },
Expand All @@ -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",
Expand All @@ -172,9 +207,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;
Loading