-
Notifications
You must be signed in to change notification settings - Fork 1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base validator #35
base validator #35
Conversation
Please add documentation of the |
packages/core/src/utils/promptTemplateValidator/variableValidator.ts
Outdated
Show resolved
Hide resolved
Base Prompt TemplateIntroductionThe A base prompt template enables developers to define a template with placeholders that can be programmatically replaced with actual data at runtime. This approach allows for a high degree of flexibility and reusability in applications where the content needs to be tailored to individual users or contexts without hardcoding every possible variation. Use Cases
The Features
Operational Workflow
MethodsConstructorThe constructor initializes the template with optional parameters, such as input variables, the template string itself, and a validator. It also verifies that all declared input variables are utilized within the template. constructor(fields?: Partial<PromptTemplateParams>) addPrefix and addSuffixThese methods facilitate the addition of predefined text to the beginning or end of the template, respectively, allowing for enhanced customization of the output. public addPrefix(prefix: string): void
public addSuffix(suffix: string): void invokeThe invoke method is the class's core functionality, where placeholders in the template are replaced with actual values from the input object. This method involves validating the input (if a validator is set), processing the template, and generating the final text output. async invoke(input: CallInput, options?: Partial<CallOptions>): Promise<CallOutput> |
Variable Validator
Overview
The
variableValidator
class is designed to provide a flexible and robust mechanism for validating input data against a set of predefined rules. It's particularly useful in contexts where inputs need to be dynamically validated, such as in template processing or API input validation.Features
Usage
To use
variableValidator
, initialize an instance with an array of variable names you intend to validate and an optional set of rules.Initialization
Adding and Removing Rules
You can dynamically add or remove validation rules for specific variables or modify the exclusion list:
Validating Input
To validate an input object against the defined rules, use the validate method. It returns a ValidationResult object indicating whether the validation passed and an optional error message: