JSONResponseValidator class
Parses any JSON returned by the model and optionally verifies it against a JSON schema.
Constructors
JSONResponse |
Creates a new |
Properties
error |
Feedback prefix given when schema errors are detected. |
missing |
Feedback given when no JSON is returned. |
schema | JSON schema to validate the response against. |
Methods
validate |
Validates a response to a prompt. |
Constructor Details
JSONResponseValidator<TValue>(Schema, string, string)
Creates a new JSONResponseValidator
instance.
new JSONResponseValidator(schema?: Schema, missingJsonFeedback?: string, errorFeedback?: string)
Parameters
- schema
-
Schema
Optional. JSON schema to validate the response against.
- missingJsonFeedback
-
string
Optional. Custom feedback to give when no JSON is returned.
- errorFeedback
-
string
Optional. Custom feedback prefix to use when schema errors are detected.
Property Details
errorFeedback
Feedback prefix given when schema errors are detected.
errorFeedback: string
Property Value
string
missingJsonFeedback
Feedback given when no JSON is returned.
missingJsonFeedback: string
Property Value
string
schema
JSON schema to validate the response against.
schema?: Schema
Property Value
Schema
Method Details
validateResponse(TurnContext, Memory, Tokenizer, PromptResponse<string>, number)
Validates a response to a prompt.
function validateResponse(context: TurnContext, memory: Memory, tokenizer: Tokenizer, response: PromptResponse<string>, remaining_attempts: number): Promise<Validation<TValue>>
Parameters
- context
-
TurnContext
Context for the current turn of conversation with the user.
- memory
- Memory
An interface for accessing state values.
- tokenizer
- Tokenizer
Tokenizer to use for encoding and decoding text.
- response
-
PromptResponse<string>
Response to validate.
- remaining_attempts
-
number
Number of remaining attempts to validate the response.
Returns
Promise<Validation<TValue>>
A Validation
object.