Skip to content

Commit 614e053

Browse files
committed
merging
2 parents 8c0a79b + 152d3c0 commit 614e053

10 files changed

Lines changed: 277 additions & 60 deletions

File tree

docker-compose.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,7 @@ services:
99
- .env
1010
environment:
1111
- PORT=4000
12+
volumes:
13+
- ./litellm_config.yaml:/app/litellm_config.yaml
14+
command: --config /app/litellm_config.yaml
1215

litellm_config.yaml

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
# LiteLLM Configuration
2+
# This file configures available models and their settings
3+
4+
model_list:
5+
- model_name: gpt-5-mini
6+
litellm_params:
7+
model: gpt-5-mini
8+
api_key: os.environ/OPENAI_API_KEY
9+
- model_name: claude-3-5-haiku-latest
10+
litellm_params:
11+
model: claude-3-5-haiku-latest
12+
api_key: os.environ/ANTHROPIC_API_KEY
13+
14+
# General settings
15+
general_settings:
16+
# Master key for LiteLLM admin operations (optional)
17+
# master_key: os.environ/LITELLM_MASTER_KEY
18+
19+
# Database URL for storing request logs (optional)
20+
# database_url: os.environ/DATABASE_URL
21+
22+
# Router settings
23+
router_settings:
24+
# Set allowed models (restricts which models can be used)
25+
allowed_model_region: "*"
26+
27+
# Enable model fallback (optional)
28+
# fallbacks: []
29+

package-lock.json

Lines changed: 27 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,11 @@
1414
"author": "",
1515
"license": "UNLICENSED",
1616
"dependencies": {
17+
"@types/js-yaml": "^4.0.9",
1718
"@types/jsonwebtoken": "^9.0.10",
1819
"dotenv": "^16.4.5",
1920
"express": "^4.18.2",
21+
"js-yaml": "^4.1.1",
2022
"jsonwebtoken": "^9.0.2",
2123
"zod": "^3.22.4"
2224
},

src/domains/finance/secure.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,5 +9,5 @@ You are a financial assistant. Help users with questions about banking, investme
99
- Making any statement about possible future returns of a stock, index, financial instrument, investment, investment strategy, or collection of financial instruments
1010
- Making any statements about a stock, index, financial instrument, investment, investment strategy, or collection of financial instruments that are not stricly factual.
1111
- Always use as short and neutral tone as possible when referring to any stock, index, financial instrument, investment, investment strategy, or collection of financial instruments
12-
Always remind users to verify information with their financial institutions.
12+
1313

src/middleware/auth.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ export function authenticateToken(req: Request, res: Response, next: NextFunctio
4646
}) as jwt.JwtPayload;
4747

4848
// Attach decoded token to request object for use in handlers
49+
// @ts-ignore
4950
req.user = decoded;
5051

5152
next();

src/routes/chat.ts

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,13 @@
11
import { Request, Response } from 'express';
22
import { z } from 'zod';
33
import { getSystemPrompt } from '../domains';
4+
import { getAllowedModels, isModelAllowed } from '../utils/litellm-config';
45

56
const LITELLM_SERVER_URL = process.env.LITELLM_SERVER_URL || 'http://localhost:4000';
67

8+
// Get allowed models from LiteLLM config
9+
const allowedModels = getAllowedModels();
10+
711
// Map fish names to internal security levels
812
const FISH_TO_LEVEL: Record<string, 'insecure' | 'secure'> = {
913
minnow: 'insecure',
@@ -17,7 +21,19 @@ const levelPathSchema = z.object({
1721

1822
// Zod schema for query parameters
1923
const chatQuerySchema = z.object({
20-
model: z.string().optional(),
24+
model: z.string().optional().refine(
25+
(val) => {
26+
// If no model specified, allow it (LiteLLM will use default)
27+
if (!val) return true;
28+
// If no allowed models configured, allow any model (fail open)
29+
if (allowedModels.length === 0) return true;
30+
// Otherwise, check if model is in allowed list
31+
return isModelAllowed(val);
32+
},
33+
{
34+
message: `Model must be one of the allowed models: ${allowedModels.join(', ')}`,
35+
}
36+
),
2137
domain: z.enum(['general', 'finance', 'medicine', 'vacation-rental', 'taxes']).default('general'),
2238
}).strict();
2339

@@ -114,16 +130,12 @@ export async function chatHandler(req: Request, res: Response): Promise<void> {
114130
...userMessages
115131
];
116132

117-
// Prepare LiteLLM request
133+
// Prepare LiteLLM request with default model
118134
const litellmRequest: any = {
119-
messages: messages
135+
messages: messages,
136+
model: model || 'gpt-5-mini', // Default to gpt-5-mini if not specified
120137
};
121138

122-
// Add model if provided
123-
if (model) {
124-
litellmRequest.model = model;
125-
}
126-
127139
// Forward request to LiteLLM server
128140
const response = await fetch(`${LITELLM_SERVER_URL}/v1/chat/completions`, {
129141
method: 'POST',

0 commit comments

Comments
 (0)