TypeChat
TypeChat copied to clipboard
TypeChat design question: Aren't we mixing schema and data?
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.
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.
I am not sure how either approach would help with my initial doubts... 🤔
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.
Would you have a simple example that illustrates your approach @philkunz ?
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