microsoft / TypeChat

TypeChat is a library that makes it easy to build natural language interfaces using types.
https://microsoft.github.io/TypeChat/
MIT License
8.06k stars 378 forks source link

Create a `validate_object` method for non-text inputs. #201

Closed DanielRosenwasser closed 4 months ago

DanielRosenwasser commented 4 months ago

In our TS codebase, we have a single validate method. The same is true of our Python codebase, but the input differs.

In the TS codebase, validate takes an object parsed from JSON.

In the Python codebase, validate takes a string presumed to be JSON. The reason for this is that internally Pydantic can parse and validate faster than going through a separate parse and validation phase.

Since it's already there, I

  1. Renamed the validate method to validate_json_text.
  2. Introduced a validate_object that works similarly to the TypeScript validate method.