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 379 forks source link

Python: Add math example #156

Closed hillary-mutisya closed 6 months ago

hillary-mutisya commented 6 months ago

This change adds a simple calculator example which uses JsonProgram for its schema. This is similar to the math example in the typescript implementation. Some changes:

  1. The JsonProgram validator and translator are included in the example folder. We'll evaluate whether to include them in the main typechat python implementation at a later date.
  2. The translator takes an API that exposes the functions a model can call. The example shows two ways of providing this- either as a TypedDict with Callable values (schema.py) or as a Protocol with instance methods (schemaV2.py).