Skip to content

SmythOS Studio: Open-Source Visual AI Agent Builder and deployable runtime stack from SmythOS. Start with an intuitive drag-and-drop workspace, extend with custom code, and deploy your agents anywhere — local, cloud, or edge — with full governance and control.

feat: add contextWindow and maxOutputTokens fields to user custom models

Forhad Hosain3aff6177c8b2
diff --git a/packages/app/src/backend/routes/router.helpers/userCustomLLM.helper.ts b/packages/app/src/backend/routes/router.helpers/userCustomLLM.helper.ts
index 55991959..30c25031 100644
--- a/packages/app/src/backend/routes/router.helpers/userCustomLLM.helper.ts
+++ b/packages/app/src/backend/routes/router.helpers/userCustomLLM.helper.ts
@@ -30,7 +30,9 @@ export interface UserCustomLLMInputParams {
modelId: string;
baseURL: string;
provider: string;
- fallbackLLM: string;
+ contextWindow?: number;
+ maxOutputTokens?: number;
+ fallbackLLM?: string;
features?: string[];
}
@@ -58,7 +60,9 @@ const userCustomLLMValidationSchema = Joi.object({
.uri({ scheme: ['http', 'https'] })
.max(500),
provider: Joi.string().trim().required().valid('OpenAI', 'Ollama'),
- fallbackLLM: Joi.string().trim().required().min(1).max(100),
+ contextWindow: Joi.number().integer().min(2048).max(2000000).optional(),
+ maxOutputTokens: Joi.number().integer().min(256).max(200000).optional(),
+ fallbackLLM: Joi.string().trim().optional().allow('').max(100),
features: Joi.array().items(Joi.string()).optional(),
});
//#endregion - Validation Schema
@@ -98,9 +102,11 @@ async function saveUserCustomLLM(req: Request, params: UserCustomLLMInputParams)
name: trimmedParams.name,
modelId: trimmedParams.modelId,
baseURL: trimmedParams.baseURL,
+ provider: trimmedParams.provider,
+ contextWindow: trimmedParams.contextWindow,
+ maxOutputTokens: trimmedParams.maxOutputTokens,
fallbackLLM: trimmedParams.fallbackLLM,
features: trimmedParams.features,
- provider: trimmedParams.provider,
};
// Save to team settings
diff --git a/packages/app/src/react/features/vault/components/create-user-custom-model-modal.tsx b/packages/app/src/react/features/vault/components/create-user-custom-model-modal.tsx
index 721a3913..c9f6a020 100644
--- a/packages/app/src/react/features/vault/components/create-user-custom-model-modal.tsx
+++ b/packages/app/src/react/features/vault/components/create-user-custom-model-modal.tsx
@@ -54,6 +54,8 @@ export function CreateUserCustomModelModal({
modelId: '',
baseURL: '',
provider: '',
+ contextWindow: undefined as number | undefined,
+ maxOutputTokens: undefined as number | undefined,
fallbackLLM: '',
features: ['text'],
});
@@ -76,6 +78,8 @@ export function CreateUserCustomModelModal({
modelId: editModel.modelId,
baseURL: editModel.baseURL,
provider: editModel.provider,
+ contextWindow: editModel.contextWindow,
+ maxOutputTokens: editModel.maxOutputTokens,
fallbackLLM: editModel.fallbackLLM || '',
features: editModel.features || ['text'],
});
@@ -85,6 +89,8 @@ export function CreateUserCustomModelModal({
modelId: '',
baseURL: '',
provider: '',
+ contextWindow: undefined,
+ maxOutputTokens: undefined,
fallbackLLM: '',
features: ['text'],
});
@@ -98,8 +104,7 @@ export function CreateUserCustomModelModal({
!formData.name?.trim() ||
!formData.modelId?.trim() ||
!formData.baseURL?.trim() ||
- !formData.provider?.trim() ||
- !formData.fallbackLLM?.trim()
+ !formData.provider?.trim()
) {
return;
}
@@ -114,12 +119,19 @@ export function CreateUserCustomModelModal({
}));
};
+ const handleNumericInputChange = (field: string, value: string) => {
+ const numValue = value === '' ? undefined : parseInt(value, 10);
+ setFormData((prev) => ({
+ ...prev,
+ [field]: numValue,
+ }));
+ };
+
const isFormValid =
formData.name?.trim() &&
formData.modelId?.trim() &&
formData.baseURL?.trim() &&
- formData.provider?.trim() &&
- formData.fallbackLLM?.trim();
+ formData.provider?.trim();
// Filter features to only show Text Completion and Function calling/Tool Use
const userCustomModelFeatures = CUSTOM_LLM_FEATURES.filter(
@@ -205,9 +217,49 @@ export function CreateUserCustomModelModal({
</Select>
</div>
+ <div className="space-y-2">
+ <Label htmlFor="contextWindow" className="text-base font-normal mr-2 text-[#1E1E1E]">
+ Context Window
+ </Label>
+ <Input
+ id="contextWindow"
+ type="number"
+ min="2048"
+ max="2000000"
+ value={formData.contextWindow || ''}
+ onChange={(e) => handleNumericInputChange('contextWindow', e.target.value)}
+ placeholder="e.g., 128000"
+ fullWidth
+ className="w-full"
+ />
+ <p className="text-xs text-gray-500">
+ Optional. Maximum number of tokens in the context window (2,048 - 2,000,000)
+ </p>
+ </div>
+
+ <div className="space-y-2">
+ <Label htmlFor="maxOutputTokens" className="text-base font-normal mr-2 text-[#1E1E1E]">
+ Maximum Output Tokens
+ </Label>
+ <Input
+ id="maxOutputTokens"
+ type="number"
+ min="256"
+ max="200000"
+ value={formData.maxOutputTokens || ''}
+ onChange={(e) => handleNumericInputChange('maxOutputTokens', e.target.value)}
+ placeholder="e.g., 4096"
+ fullWidth
+ className="w-full"
+ />
+ <p className="text-xs text-gray-500">
+ Optional. Maximum number of tokens that can be generated (256 - 200,000)
+ </p>
+ </div>
+
<div className="space-y-2">
<Label htmlFor="fallbackLLM">
- Fallback Model <span className="text-red-500">*</span>
+ Fallback Model
</Label>
<p className="text-xs text-gray-500">
The model used when the custom model is unavailable.
diff --git a/packages/app/src/react/features/vault/types/types.ts b/packages/app/src/react/features/vault/types/types.ts
index 3dc91c2a..3c460dd8 100644
--- a/packages/app/src/react/features/vault/types/types.ts
+++ b/packages/app/src/react/features/vault/types/types.ts
@@ -192,10 +192,21 @@ export interface UserCustomModel {
* Provider / Compatible SDK (e.g., 'OpenAI', 'Ollama')
*/
provider: string;
+
+ /**
+ * Context Window size in tokens (optional)
+ */
+ contextWindow?: number;
+
+ /**
+ * Maximum output tokens that can be generated (optional)
+ */
+ maxOutputTokens?: number;
+
/**
- * Fallback LLM ID from builtin LLMs
+ * Fallback LLM ID from builtin LLMs (optional)
*/
- fallbackLLM: string;
+ fallbackLLM?: string;
/**
* List of features supported by the model (e.g., 'text', 'tools')
diff --git a/packages/app/src/react/features/vault/vault-business-logic.ts b/packages/app/src/react/features/vault/vault-business-logic.ts
index 10a2a23a..9a8157e0 100644
--- a/packages/app/src/react/features/vault/vault-business-logic.ts
+++ b/packages/app/src/react/features/vault/vault-business-logic.ts
@@ -679,6 +679,8 @@ export const userCustomModelService = {
modelId: value.modelId,
baseURL: value.baseURL,
provider: value.provider,
+ contextWindow: value.contextWindow,
+ maxOutputTokens: value.maxOutputTokens,
fallbackLLM: value.fallbackLLM || '', // Provide default empty string for backward compatibility with cached data
features: value.features,
}));
@@ -721,6 +723,8 @@ export const userCustomModelService = {
modelId: modelDetails.modelId,
baseURL: modelDetails.baseURL,
provider: modelDetails.provider,
+ contextWindow: modelDetails.contextWindow,
+ maxOutputTokens: modelDetails.maxOutputTokens,
fallbackLLM: modelDetails.fallbackLLM,
features: modelDetails.features,
};
@@ -762,6 +766,8 @@ export const userCustomModelService = {
modelId: updatedFields.modelId || '',
baseURL: updatedFields.baseURL || '',
provider: updatedFields.provider || '',
+ contextWindow: updatedFields.contextWindow,
+ maxOutputTokens: updatedFields.maxOutputTokens,
fallbackLLM: updatedFields.fallbackLLM || '',
features: updatedFields.features,
};