Overview
TheisModelSelected() function checks whether a valid model configuration exists in the ScryxCLI settings. It ensures both the model name and API key are present and non-empty.
Function Signature
Return Value
Returns
true if a valid model configuration exists, false otherwise.How It Works
The function performs the following validation checks:- Retrieves Configuration: Loads the ScryxCLI configuration using
getConfig() - Model Name Check: Verifies
config.model.modelNameexists - Model Key Check: Verifies
config.model.modelKeyexists - Non-Empty Validation: Ensures both values are non-empty strings
The function returns
false if any validation check fails or if an error occurs during execution.Valid Model Configuration
For a model to be considered properly selected, all of the following must be true:- Configuration contains
config.model.modelName - Configuration contains
config.model.modelKey modelNameis a non-empty string (!== '')modelKeyis a non-empty string (!== '')
Implementation Details
Usage Example
Combining with Authentication
Error Handling
The function includes comprehensive error handling:- Missing Configuration: Returns
falseif config cannot be retrieved - Missing Model Name: Returns
falseifmodelNameis undefined or null - Missing Model Key: Returns
falseifmodelKeyis undefined or null - Empty Strings: Returns
falseif either field is an empty string - Exceptions: Logs errors to console and returns
false
Unlike
isAuthenticated(), this function logs errors to the console before returning false, which can help with debugging model configuration issues.Configuration Structure
The function expects the following structure in the ScryxCLI configuration:Related Functions
getConfig()- Retrieves the ScryxCLI configurationisAuthenticated()- Checks if user has valid JWT token
Source Location
src/lib/isModelSelected.ts:6