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

TypeChat design question: Aren't we mixing schema and data? #123

Open ChristianWeyer opened 9 months ago

ChristianWeyer commented 9 months ago

Hi all,

When looking at the samples like CoffeeShop or Restaurant we can see schemas like:

export interface BakeryProducts {
    type: 'BakeryProducts';
    name: 'apple bran muffin' | 'blueberry muffin' | 'lemon poppyseed muffin' | 'bagel';
    options: (BakeryOptions | BakeryPreparations)[];
}

or

export type Pizza = {
    itemType: 'pizza';
    // default: large
    size?: 'small' | 'medium' | 'large' | 'extra large';
    // toppings requested (examples: pepperoni, arugula)
    addedToppings?: string[];
    // toppings requested to be removed (examples: fresh garlic, anchovies)
    removedToppings?: string[];
    // default: 1
    quantity?: number;
    // used if the requester references a pizza by name
    name?: "Hawaiian" | "Yeti" | "Pig In a Forest" | "Cherry Bomb";
};

Here, we use data like the pizza names or the bakery products inside the schema definitions.

Is this a realistic approach? Usually, we have data from a data source/store, e.g., all the pizzas a restaurant offers. They won't/cannot live inside the schema definitions file in real life :-).

Do you have any thoughts on this design?

Thank you.

danmarshall commented 9 months ago

This is intriguing. Either you'd generate the schema from your data, or you'd just use string and then add an additional validation call. I'm not sure the former is scalable.

ChristianWeyer commented 9 months ago

I am not sure how either approach would help with my initial doubts... 🤔

philkunz commented 9 months ago

You can just build a super TypeChat module that takes care of offering an updateable API and that then regenerates the schema and restarts the actual typechat process... The Schema does exactly what it is supposed to do -> Provide a schema for a response that needs to be adhered to.

ChristianWeyer commented 8 months ago

Would you have a simple example that illustrates your approach @philkunz ?

danmarshall commented 6 months ago

It looks like this issue can be addressed by the new Zod integration. Here's an example: https://github.com/microsoft/TypeChat/blob/34f3fd7cc1585b694806ade2fa13ab1e4bc1acf1/examples/coffeeShop-zod/src/coffeeShopSchema.ts#L39