TypeChat is particularly useful for applications that require a natural language interface. For example, the development team mentions an app for ordering coffee using voice input. In this case, the app needs to translate the input into specific information for ordering and billing. TypeChat offers three main benefits: increased precision, easier accessibility without prompt engineering, and increased security.
The need for TypeChat arose because traditional programs struggle with generating natural language responses from large language models. What these models need is a familiar structure, which TypeChat provides. It achieves this by using both the JSON schema and TypeScript types, utilizing TypeScript as a “specification language” for the responses of language models. TypeScript’s compiler API is used to validate the correctness of the typing.
With TypeChat, developers can define a scheme based on different types that suit their application. For instance, they can create a scheme for a shopping cart or a music app. TypeChat then takes care of creating a prompt for the large language model, validating the schema, and resolving any issues through further interaction with the language model. It also generates a summary of the interaction so that users can verify if it aligns with their intentions.
The blog entry showcasing TypeChat demonstrates its functionality using OpenAI’s ChatGPT. In the example, the user asks for suggestions of specific places to visit in Seattle on a rainy day. The language model generates a JSON response that complies with the TypeScript type Response. The output includes suggestions for places such as the Museum of Pop Culture, the Seattle Art Museum, and Pike Place Market.