-
Notifications
You must be signed in to change notification settings - Fork 0
Open
Description
in the chat api app/(chat)/api/chat/route.ts we currently only check if user can select certain model:
// Get user entitlements and available models to validate the selected model
const userEntitlements = entitlementsByUserRole[user.role];
const availableProviders = await getFilteredProviders(
user,
userEntitlements,
isTestEnvironment,
);
// Check if the selected model is available to this user
const selectedProvider = availableProviders[selectedChatModelProvider];
const isModelAvailable = selectedProvider?.models.some(
(model) => model.id === selectedChatModel,
);
if (!isModelAvailable) {
return new ChatSDKError(
'forbidden:chat',
'Model not available for user',
).toResponse();but not check whether user exceed the current usage limit. So you need to
- Refactor this code to a function call check userAvailablility that checks both model selection and usage limit
- Add user's spending limit to entitlement file
- Throw error if limit hit
- Add unit test with real db connection that similar to
lib/db/queries/vector-store.spec.tsusing real postgres db
Metadata
Metadata
Assignees
Labels
No labels