GitHub - bricks-cloud/BricksLLM: Simplifying LLM ops in production
source link: https://github.com/bricks-cloud/BricksLLM
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
BricksLLM: AI Gateway For Putting LLM In Production
BricksLLM is a cloud native AI gateway written in Go. Currently, it serves as a proxy to OpenAI. We let you create API keys that have rate limits, cost limits and TTLs. The API keys can be used in both development and production to achieve fine-grained access control that is not provided by OpenAI at the moment. The proxy is compatible with OpenAI API and its SDKs.
The vision of BricksLLM is to support many more large language models such as LLama2, Claude, PaLM2 etc, and streamline LLM operations.
Roadmap
- Access control via API key with rate limit, cost limit and ttl
- Logging integration
- Statsd integration
- Custom Provider Integration
- PII detection and masking 🚧
Getting Started
The easiest way to get started with BricksLLM is through BricksLLM-Docker.
Step 1 - Clone BricksLLM-Docker repository
git clone https://github.com/bricks-cloud/BricksLLM-Docker
Step 2 - Change to BricksLLM-Docker directory
cd BricksLLM-Docker
Step 3 - Deploy BricksLLM locally with Postgresql and Redis
docker-compose up
You can run this in detach mode use the -d flag: docker-compose up -d
Step 4 - Create a provider setting
curl -X PUT http://localhost:8001/api/provider-settings \
-H "Content-Type: application/json" \
-d '{
"provider":"openai",
"setting": {
"apikey": "YOUR_OPENAI_KEY"
}
}'
Copy the id
from the response.
Step 5 - Create a Bricks API key
Use id
from the previous step as settingId
to create a key with a rate limit of 2 req/min and a spend limit of 25 cents.
curl -X PUT http://localhost:8001/api/key-management/keys \
-H "Content-Type: application/json" \
-d '{
"name": "My Secret Key",
"key": "my-secret-key",
"tags": ["mykey"],
"settingId": "ID_FROM_STEP_FOUR",
"rateLimitOverTime": 2,
"rateLimitUnit": "m",
"costLimitInUsd": 0.25
}'
Congratulations you are done!!!
Then, just redirect your requests to us and use OpenAI as you would normally. For example:
curl -X POST http://localhost:8002/api/providers/openai/v1/chat/completions \
-H "Authorization: Bearer my-secret-key" \
-H "Content-Type: application/json" \
-d '{
"model": "gpt-3.5-turbo",
"messages": [
{
"role": "system",
"content": "hi"
}
]
}'
Or if you're using an SDK, you could change its baseURL
to point to us. For example:
// OpenAI Node SDK v4
import OpenAI from 'openai';
const openai = new OpenAI({
apiKey: "some-secret-key", // key created earlier
baseURL: "http://localhost:8002/api/providers/openai/v1", // redirect to us
});
How to Update?
For updating to the latest version
docker pull luyuanxin1995/bricksllm:latest
For updating to a particular version
docker pull luyuanxin1995/bricksllm:1.4.0
Documentation
Environment variables
Name type description default POSTGRESQL_HOSTS
required Hosts for Postgresql DB. Seperated by , localhost
POSTGRESQL_DB_NAME
optional Name for Postgresql DB. POSTGRESQL_USERNAME
required Postgresql DB username POSTGRESQL_PASSWORD
required Postgresql DB password POSTGRESQL_SSL_MODE
optional Postgresql SSL mode disable
POSTGRESQL_PORT
optional The port that Postgresql DB runs on 5432
POSTGRESQL_READ_TIME_OUT
optional Timeout for Postgresql read operations 2s
POSTGRESQL_WRITE_TIME_OUT
optional Timeout for Postgresql write operations 1s
REDIS_HOSTS
required Host for Redis. Seperated by , localhost
REDIS_PASSWORD
optional Redis Password REDIS_PORT
optional The port that Redis DB runs on 6379
REDIS_READ_TIME_OUT
optional Timeout for Redis read operations 1s
REDIS_WRITE_TIME_OUT
optional Timeout for Redis write operations 500ms
IN_MEMORY_DB_UPDATE_INTERVAL
optional The interval BricksLLM API gateway polls Postgresql DB for latest key configurations 1s
STATS_PROVIDER
optional This value can only be datadog. Required for integration with Datadog. PROXY_TIMEOUT
optional This value can only be datadog. Required for integration with Datadog.
Configuration Endpoints
The configuration server runs on Port 8001
.
Get keys: GET
/api/key-management/keys
Create key: PUT
/api/key-management/keys
Update key: PATCH
/api/key-management/keys/{keyId}
Create a provider setting: POST
/api/provider-settings
Get all provider settings: GET
/api/provider-settings
Update a provider setting: PATCH
/api/provider-settings/:id
Retrieve Metrics: POST
/api/reporting/events
Get events: GET
/api/events
Create custom provider: POST
/api/custom/providers
Update custom provider: PATCH
/api/custom/providers/:id
Get custom providers: GET
/api/custom/providers
OpenAI Proxy
The OpenAI proxy runs on Port 8002
.
Headers
name type data type description x-custom-event-id
optional string
Custom Id that can be used to retrieve an event associated with each proxy request.
Chat Completion
Call OpenAI chat completions: POST
/api/providers/openai/v1/chat/completions
Embeddings
Call OpenAI embeddings: POST
/api/providers/openai/v1/embeddings
Moderations
Call OpenAI moderations: POST
/api/providers/openai/v1/moderations
Models
Get OpenAI models: GET
/api/providers/openai/v1/models
Retrieve an OpenAI model: GET
/api/providers/openai/v1/models/:model
Files
List files: GET
/api/providers/openai/v1/files
Upload a file: POST
/api/providers/openai/v1/files
Delete a file: POST
/api/providers/openai/v1/files/:file_id
Retrieve a file: GET
/api/providers/openai/v1/files/:file_id
Retrieve file content: GET
/api/providers/openai/v1/files/:file_id/content
Assistants
Create assistant: POST
/api/providers/openai/v1/assistants
Retrieve assistant: GET
/api/providers/openai/v1/assistants/:assistant_id
Modify assistant: POST
/api/providers/openai/v1/assistants/:assistant_id
Delete assistant: DELETE
/api/providers/openai/v1/assistants/:assistant_id
List assistants: GET
/api/providers/openai/v1/assistants
Create assistant file: POST
/api/providers/openai/v1/assistants/:assistant_id/files
Retrieve assistant file: GET
/api/providers/openai/v1/assistants/:assistant_id/files/:file_id
Delete assistant file: DELETE
/api/providers/openai/v1/assistants/:assistant_id/files/:file_id
List assistant files: GET
/api/providers/openai/v1/assistants/:assistant_id/files
Create thread: POST
/api/providers/openai/v1/threads
Retrieve thread: GET
/api/providers/openai/v1/threads/:thread_id
Modify thread: POST
/api/providers/openai/v1/threads/:thread_id
Delete thread: DELETE
/api/providers/openai/v1/threads/:thread_id
Create message: POST
/api/providers/openai/v1/threads/:thread_id/messages
Retrieve message: GET
/api/providers/openai/v1/threads/:thread_id/messages/:message_id
Modify message: POST
/api/providers/openai/v1/files/:file_id/content
List messages: GET
/api/providers/openai/v1/threads/:thread_id/messages
Retrieve message file: GET
/api/providers/openai/v1/threads/:thread_id/messages/:message_id/files/:file_id
List message files: GET
/api/providers/openai/v1/threads/:thread_id/messages/:message_id/files
Create run: POST
/api/providers/openai/v1/threads/:thread_id/runs
Retrieve run: GET
/api/providers/openai/v1/threads/:thread_id/runs/:run_id
Modify run: POST
/api/providers/openai/v1/threads/:thread_id/runs/:run_id
List runs: GET
/api/providers/openai/v1/threads/runs
Submit tool outputs to run: POST
/api/providers/openai/v1/threads/runs
Cancel a run: POST
/api/providers/openai/v1/threads/:thread_id/runs/:run_id/cancel
Create thread and run: POST
/api/providers/openai/v1/threads/runs
Retrieve run step: GET
/api/providers/openai/v1/threads/:thread_id/runs/:run_id/steps/:step_id
List run steps: GET
/api/providers/openai/v1/threads/:thread_id/runs/:run_id/steps
Anthropic Proxy
The custom provider proxy runs on Port 8002
.
Create Anthropic completion: POST
/api/providers/anthropic/v1/complete
Custom Provider Proxy
The custom provider proxy runs on Port 8002
.
Call custom providers: POST
/api/custom/providers/:provider/*
Recommend
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK