TypeChat: Improving Language Model Output with Artificial Intelligence

Artificial intelligence: TypeChat structures output of language models

A team at Microsoft, led by TypeScript inventor Anders Hejlsberg, has developed a new experimental library called TypeChat. This library is designed to create natural language interfaces and produce structured and type-safe answers for large language models (LLMs). TypeChat achieves this by utilizing TypeScript type definitions and JavaScript Object Notation (JSON).

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.

Currently, the TypeChat team is focused on developing the library exclusively for TypeScript and JavaScript. However, discussions regarding support for other languages can be conducted in the GitHub repository. Additional information about TypeChat can be found in a blog entry and the documentation provided for this experimental project.

Leave a Reply