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

should we read interface as a text file? #142

Open dcsan opened 7 months ago

dcsan commented 7 months ago

looking at the examples:

https://github.com/microsoft/TypeChat/blob/main/examples/calendar/src/main.ts#L11C25-L11C25 https://github.com/microsoft/TypeChat/blob/main/examples/restaurant/src/main.ts#L15

const schema = fs.readFileSync(path.join(__dirname, "calendarActionsSchema.ts"), "utf8");

I find it odd that we read in the typescript schema as a text file. after the code is transpiled, those .ts files won't exist.

I guess I could manually copy over to the /dist after building but that seems a hack

Is there a method to just import the schema or pass a typescript type?

gchartier commented 7 months ago

Seems like one argument for keeping reading it as a text file is to enable the use of comments alongside the types for added context to guide the model.

But I agree, it's kind of inelegant.

DanielRosenwasser commented 6 months ago

The current approach here is to make sure the .ts file is ingestible via either

  1. copying the .ts file into the output directory, or
  2. using a runner like ts-node or tsx to execute your TypeScript directly.

We're also looking at another approach, using a runtime type validation library called Zod - you can see more at @ahejlsberg's PR at #147.