TypeChat icon indicating copy to clipboard operation
TypeChat copied to clipboard

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

Open ChristianWeyer opened this issue 2 years ago • 5 comments
trafficstars

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.

ChristianWeyer avatar Sep 16 '23 15:09 ChristianWeyer

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.

danmarshall avatar Sep 18 '23 18:09 danmarshall

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

ChristianWeyer avatar Sep 18 '23 18:09 ChristianWeyer

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.

philkunz avatar Oct 07 '23 11:10 philkunz

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

ChristianWeyer avatar Oct 15 '23 15:10 ChristianWeyer

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

danmarshall avatar Dec 13 '23 19:12 danmarshall