Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/armandris/gpt-broker
Keeps your OpenAi token safe and your frontend GPT'ed.
https://github.com/armandris/gpt-broker
authentication docker jwt koa microservice openai prometheus rate-limiting rest-api security supabase
Last synced: about 2 months ago
JSON representation
Keeps your OpenAi token safe and your frontend GPT'ed.
- Host: GitHub
- URL: https://github.com/armandris/gpt-broker
- Owner: ArmanDris
- Created: 2024-07-28T08:43:52.000Z (6 months ago)
- Default Branch: main
- Last Pushed: 2024-12-11T02:59:00.000Z (about 2 months ago)
- Last Synced: 2024-12-11T03:29:50.273Z (about 2 months ago)
- Topics: authentication, docker, jwt, koa, microservice, openai, prometheus, rate-limiting, rest-api, security, supabase
- Language: JavaScript
- Homepage:
- Size: 111 KB
- Stars: 0
- Watchers: 1
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# GPT Broker 💼
GPT Broker keeps your OpenAI token out of frontend code and ensures only authenticated users access sensitive endpoints.
For Prometheus integration a /metrics endpoint with basic traffic information is exposed. Make sure public requests are denied from accessing it.
## Endpoints:
### /v2/advanced-gpt-4o-mini-complete
This version has small syntax tweaks and lets the caller specify a temperature to pass to gpt
- **Request Headers:** - An Authorization header with the user's access token, in the format "Authorization": "Bearer "
- **Request Body:** An object with a "messages" field and an optional "temperature" field. Messages Must be a valid array of messages that ChatGPT accepts. Ie, in the format: `[ { role: 'system', content: "Write me a poem" }, ... ]`### /advanced-gpt-4o-mini-complete
More complicated but allows full control over the prompts passed to ChatGPT. Requires:
- **Autentication** - A header with the user's access token, in the format "Bearer "
- **messages** passed in the message body as JSON. Must be a valid array of messages that ChatGPT accepts. Ie, in the format: `[ { role: 'system', content: "Write me a poem" }, ... ]`### /simple-gpt-4o-mini-complete
For simple requests that fit in a URL. Requires:
- **prompt** - A URL parameter to give to ChatGPT
- **Autentication** - A header with the user's access token, in the format "Bearer "### /metrics
Application metrics for Prometheus## Setup:
Make a .env file in the root directory with the following. Then run `docker compose up` to start **gpt_broker**.
```
OPENAI_API_KEY=your-openai-api-key-here
SUPABASE_URL=your-supabase-url-here
SUPABASE_KEY=your-supabase-service-key-here
DAILY_LIMIT=50
ID_WHITE_LIST=[]
```## Testing:
There is an End to End test to make sure the whole process still works.
To run the test start the docker container (needs to be exposed on
default port 8011) then run
```
cd test-gpt-broker
pnpm test
```