Skip to content

Commit 79cc368

Browse files
authored
Merge pull request #12 from j4ys0n/request-limit
Request limit
2 parents 9001802 + 3896331 commit 79cc368

File tree

5 files changed

+16
-5
lines changed

5 files changed

+16
-5
lines changed

Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# Use an official Node.js runtime as the base image
2-
FROM node:18.20.4-bullseye
2+
FROM node:18.20.3-bullseye
33

44
# Install Nginx
55
RUN apt-get update && apt-get install -y nginx certbot python3-certbot-dns-cloudflare

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "llm-proxy",
3-
"version": "1.2.1",
3+
"version": "1.3.0",
44
"description": "Manages Nginx for reverse proxy to multiple LLMs, with TLS & Bearer Auth tokens",
55
"main": "dist/index.js",
66
"scripts": {

src/controllers/llm.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { Express, NextFunction, Request, RequestHandler, Response } from 'express'
2-
import { log, md5, sleep } from '../utils/general'
2+
import { log, md5, sleep, extractDomainName } from '../utils/general'
33
import axios, { AxiosRequestConfig } from 'axios'
44

55
export interface Model {
@@ -19,7 +19,7 @@ async function fetchModels(targetUrls: string[]): Promise<ModelMap> {
1919
try {
2020
const response = await axios.get(`${url}/v1/models`)
2121
const models = response.data.data || []
22-
22+
const hostId = extractDomainName(url)
2323
models.forEach((model: Model) => {
2424
const hash = md5(model.id)
2525
tmp[hash] = { url, model }

src/index.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import dotenv from 'dotenv'
22
import express from 'express'
3+
import bodyParser from 'body-parser'
34
import { NginxController } from './controllers/nginx'
45
import { LLMController } from './controllers/llm'
56
import { tokenMiddleware } from './utils/auth'
@@ -13,9 +14,15 @@ const targetUrls = (process.env.TARGET_URLS || 'http://example.com').split(',').
1314

1415
app.use(express.json())
1516

17+
const payloadLimit = process.env.PAYLOAD_LIMIT || '250kb'
18+
//support application/json type post data (default limit is 100kb)
19+
app.use(bodyParser.json({ limit: payloadLimit }))
20+
//support application/x-www-form-urlencoded post data (default limit is 100kb)
21+
app.use(bodyParser.urlencoded({ limit: payloadLimit, extended: false }))
22+
1623
// Express routes
1724
app.get('/', (req, res) => {
18-
res.send('LLM Aggregation Proxy')
25+
res.send('LLM Proxy')
1926
})
2027

2128
const authController = new AuthController({ app })

src/utils/general.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,3 +15,7 @@ export function md5(data: Object | string): string {
1515
export function sleep(ms: number) {
1616
return new Promise((r) => setTimeout(r, ms))
1717
}
18+
19+
export function extractDomainName(url: string) {
20+
return url.replace('https://', '').replace('http://', '').split('/')[0].replace(/\./g, '_')
21+
}

0 commit comments

Comments
 (0)