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

Add support for Python tuple types #193

Closed DanielRosenwasser closed 4 months ago

DanielRosenwasser commented 4 months ago

This change adds support for translating tuple types in Python.

A fixed-length tuple is translated to a corresponding array-backed tuple in a TypeScript schema.

target_type = [int, str] # is `[number, string]` in TS

target_type = [int] # is `[number]` in TS

target_type = [()] # is `[]`, the empty tuple, in TS

An unbounded homogeneous tuple is simply translated into an array.

target_type = [int, ...] # is 'number[]' in TS

Any unsupported form is typically translated into any[].