From a57223a051d08b15ea2fb55793d9dc92d076e07b Mon Sep 17 00:00:00 2001 From: Daniel Rosenwasser Date: Fri, 15 Mar 2024 14:58:50 -0700 Subject: [PATCH 01/20] Manually disable `envFile` loading in VS Code. (#214) --- .vscode/settings.json | 6 ++++++ 1 file changed, 6 insertions(+) create mode 100644 .vscode/settings.json diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 00000000..681dda24 --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,6 @@ +{ + // TODO: + // * https://github.com/microsoft/vscode-python/issues/23078 + // * https://github.com/microsoft/vscode/issues/197603 + "python.envFile": "${workspaceFolder}/.file-that-should-hopefully-not-exist" +} \ No newline at end of file From 6030f35016192d0f7ddafd210ca930856b2bac96 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Sun, 17 Mar 2024 21:20:05 -0700 Subject: [PATCH 02/20] Bump follow-redirects from 1.15.5 to 1.15.6 in /typescript (#213) Bumps [follow-redirects](https://github.com/follow-redirects/follow-redirects) from 1.15.5 to 1.15.6. - [Release notes](https://github.com/follow-redirects/follow-redirects/releases) - [Commits](https://github.com/follow-redirects/follow-redirects/compare/v1.15.5...v1.15.6) --- updated-dependencies: - dependency-name: follow-redirects dependency-type: indirect ... Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> --- typescript/package-lock.json | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/typescript/package-lock.json b/typescript/package-lock.json index 00b91101..e4042f96 100644 --- a/typescript/package-lock.json +++ b/typescript/package-lock.json @@ -1115,9 +1115,9 @@ } }, "node_modules/follow-redirects": { - "version": "1.15.5", - "resolved": "https://registry.npmjs.org/follow-redirects/-/follow-redirects-1.15.5.tgz", - "integrity": "sha512-vSFWUON1B+yAw1VN4xMfxgn5fTUiaOzAJCKBwIIgT/+7CuGy9+r+5gITvP62j3RmaD5Ph65UaERdOSRGUzZtgw==", + "version": "1.15.6", + "resolved": "https://registry.npmjs.org/follow-redirects/-/follow-redirects-1.15.6.tgz", + "integrity": "sha512-wWN62YITEaOpSK584EZXJafH1AGpO8RVgElfkuXbTOrPX4fIfOyEpW/CsiNd8JdYrAoOvafRTOEnvsO++qCqFA==", "funding": [ { "type": "individual", From f193e63e97ee35f866a6bbfa0c12605a228f3ef9 Mon Sep 17 00:00:00 2001 From: Jake Bailey <5341706+jakebailey@users.noreply.github.com> Date: Mon, 18 Mar 2024 22:44:43 -0700 Subject: [PATCH 03/20] Make typescript and zod optional peer dependencies (#174) * Make zod an optional peer dependency * typescript too * Make real deps --- typescript/examples/calendar/package.json | 6 +- typescript/examples/coffeeShop/package.json | 6 +- typescript/examples/healthData/package.json | 6 +- .../examples/healthData/src/translator.ts | 2 +- typescript/examples/math/package.json | 6 +- typescript/examples/multiSchema/package.json | 6 +- typescript/examples/music/package.json | 6 +- typescript/examples/music/src/trackFilter.ts | 2 +- typescript/examples/restaurant/package.json | 6 +- typescript/examples/sentiment/package.json | 6 +- typescript/package-lock.json | 64 +++++++++++-------- typescript/package.json | 11 +++- 12 files changed, 72 insertions(+), 55 deletions(-) diff --git a/typescript/examples/calendar/package.json b/typescript/examples/calendar/package.json index 840eb676..881c8e34 100644 --- a/typescript/examples/calendar/package.json +++ b/typescript/examples/calendar/package.json @@ -13,12 +13,12 @@ "dependencies": { "dotenv": "^16.3.1", "find-config": "^1.0.0", - "typechat": "^0.1.0" + "typechat": "^0.1.0", + "typescript": "^5.3.3" }, "devDependencies": { "@types/find-config": "1.0.4", "@types/node": "^20.10.4", - "copyfiles": "^2.4.1", - "typescript": "^5.3.3" + "copyfiles": "^2.4.1" } } diff --git a/typescript/examples/coffeeShop/package.json b/typescript/examples/coffeeShop/package.json index 199b8c7f..ba9719b3 100644 --- a/typescript/examples/coffeeShop/package.json +++ b/typescript/examples/coffeeShop/package.json @@ -13,12 +13,12 @@ "dependencies": { "dotenv": "^16.3.1", "find-config": "^1.0.0", - "typechat": "^0.1.0" + "typechat": "^0.1.0", + "typescript": "^5.3.3" }, "devDependencies": { "@types/find-config": "1.0.4", "@types/node": "^20.10.4", - "copyfiles": "^2.4.1", - "typescript": "^5.3.3" + "copyfiles": "^2.4.1" } } diff --git a/typescript/examples/healthData/package.json b/typescript/examples/healthData/package.json index 79029d39..57108be5 100644 --- a/typescript/examples/healthData/package.json +++ b/typescript/examples/healthData/package.json @@ -13,12 +13,12 @@ "dependencies": { "dotenv": "^16.3.1", "find-config": "^1.0.0", - "typechat": "^0.1.0" + "typechat": "^0.1.0", + "typescript": "^5.1.3" }, "devDependencies": { "@types/find-config": "1.0.4", "@types/node": "^20.3.1", - "copyfiles": "^2.4.1", - "typescript": "^5.1.3" + "copyfiles": "^2.4.1" } } diff --git a/typescript/examples/healthData/src/translator.ts b/typescript/examples/healthData/src/translator.ts index e9a284bb..c8e21658 100644 --- a/typescript/examples/healthData/src/translator.ts +++ b/typescript/examples/healthData/src/translator.ts @@ -1,5 +1,5 @@ import {Result, TypeChatLanguageModel, createJsonTranslator, TypeChatJsonTranslator} from "typechat"; -import { createTypeScriptJsonValidator } from "../../../dist/ts"; +import { createTypeScriptJsonValidator } from "typechat/ts"; type ChatMessage = { source: "system" | "user" | "assistant"; diff --git a/typescript/examples/math/package.json b/typescript/examples/math/package.json index 15df99a6..79df155c 100644 --- a/typescript/examples/math/package.json +++ b/typescript/examples/math/package.json @@ -13,12 +13,12 @@ "dependencies": { "dotenv": "^16.3.1", "find-config": "^1.0.0", - "typechat": "^0.1.0" + "typechat": "^0.1.0", + "typescript": "^5.3.3" }, "devDependencies": { "@types/find-config": "1.0.4", "@types/node": "^20.10.4", - "copyfiles": "^2.4.1", - "typescript": "^5.3.3" + "copyfiles": "^2.4.1" } } diff --git a/typescript/examples/multiSchema/package.json b/typescript/examples/multiSchema/package.json index 0340982b..f5abaf4f 100644 --- a/typescript/examples/multiSchema/package.json +++ b/typescript/examples/multiSchema/package.json @@ -15,12 +15,12 @@ "dotenv": "^16.3.1", "typechat": "^0.1.0", "find-config": "^1.0.0", - "music": "^0.0.1" + "music": "^0.0.1", + "typescript": "^5.3.3" }, "devDependencies": { "@types/find-config": "1.0.4", "@types/node": "^20.3.1", - "copyfiles": "^2.4.1", - "typescript": "^5.3.3" + "copyfiles": "^2.4.1" } } diff --git a/typescript/examples/music/package.json b/typescript/examples/music/package.json index fd267cd9..5c6fd1f4 100644 --- a/typescript/examples/music/package.json +++ b/typescript/examples/music/package.json @@ -21,14 +21,14 @@ "find-config": "^1.0.0", "open": "^7.0.4", "sqlite3": "^5.1.6", - "typechat": "^0.1.0" + "typechat": "^0.1.0", + "typescript": "^5.3.3" }, "devDependencies": { "@types/express": "^4.17.17", "@types/find-config": "1.0.4", "@types/node": "^20.10.4", "@types/spotify-api": "^0.0.22", - "copyfiles": "^2.4.1", - "typescript": "^5.3.3" + "copyfiles": "^2.4.1" } } diff --git a/typescript/examples/music/src/trackFilter.ts b/typescript/examples/music/src/trackFilter.ts index bfa4c1ad..cee22111 100644 --- a/typescript/examples/music/src/trackFilter.ts +++ b/typescript/examples/music/src/trackFilter.ts @@ -1,4 +1,4 @@ -import { TypeChatLanguageModel } from "../../../dist"; +import { TypeChatLanguageModel } from "typechat"; import { getArtist } from "./endpoints"; import { IClientContext } from "./main"; diff --git a/typescript/examples/restaurant/package.json b/typescript/examples/restaurant/package.json index 38bd86bb..eebfd3a5 100644 --- a/typescript/examples/restaurant/package.json +++ b/typescript/examples/restaurant/package.json @@ -13,12 +13,12 @@ "dependencies": { "dotenv": "^16.3.1", "find-config": "^1.0.0", - "typechat": "^0.1.0" + "typechat": "^0.1.0", + "typescript": "^5.3.3" }, "devDependencies": { "@types/find-config": "1.0.4", "@types/node": "^20.10.4", - "copyfiles": "^2.4.1", - "typescript": "^5.3.3" + "copyfiles": "^2.4.1" } } diff --git a/typescript/examples/sentiment/package.json b/typescript/examples/sentiment/package.json index d744058b..0d07ecc8 100644 --- a/typescript/examples/sentiment/package.json +++ b/typescript/examples/sentiment/package.json @@ -13,12 +13,12 @@ "dependencies": { "dotenv": "^16.3.1", "find-config": "^1.0.0", - "typechat": "^0.1.0" + "typechat": "^0.1.0", + "typescript": "^5.3.3" }, "devDependencies": { "@types/find-config": "1.0.4", "@types/node": "^20.10.4", - "copyfiles": "^2.4.1", - "typescript": "^5.3.3" + "copyfiles": "^2.4.1" } } diff --git a/typescript/package-lock.json b/typescript/package-lock.json index e4042f96..f4283de8 100644 --- a/typescript/package-lock.json +++ b/typescript/package-lock.json @@ -12,15 +12,23 @@ "./", "./examples/*" ], - "dependencies": { - "typescript": "^5.3.3", - "zod": "^3.22.4" - }, "devDependencies": { "@types/node": "^20.10.4" }, "engines": { "node": ">=18" + }, + "peerDependencies": { + "typescript": "^5.3.3", + "zod": "^3.22.4" + }, + "peerDependenciesMeta": { + "typescript": { + "optional": true + }, + "zod": { + "optional": true + } } }, "examples/calendar": { @@ -29,13 +37,13 @@ "dependencies": { "dotenv": "^16.3.1", "find-config": "^1.0.0", - "typechat": "^0.1.0" + "typechat": "^0.1.0", + "typescript": "^5.3.3" }, "devDependencies": { "@types/find-config": "1.0.4", "@types/node": "^20.10.4", - "copyfiles": "^2.4.1", - "typescript": "^5.3.3" + "copyfiles": "^2.4.1" } }, "examples/coffeeShop": { @@ -45,13 +53,13 @@ "dependencies": { "dotenv": "^16.3.1", "find-config": "^1.0.0", - "typechat": "^0.1.0" + "typechat": "^0.1.0", + "typescript": "^5.3.3" }, "devDependencies": { "@types/find-config": "1.0.4", "@types/node": "^20.10.4", - "copyfiles": "^2.4.1", - "typescript": "^5.3.3" + "copyfiles": "^2.4.1" } }, "examples/coffeeShop-zod": { @@ -78,13 +86,13 @@ "dependencies": { "dotenv": "^16.3.1", "find-config": "^1.0.0", - "typechat": "^0.1.0" + "typechat": "^0.1.0", + "typescript": "^5.1.3" }, "devDependencies": { "@types/find-config": "1.0.4", "@types/node": "^20.3.1", - "copyfiles": "^2.4.1", - "typescript": "^5.1.3" + "copyfiles": "^2.4.1" } }, "examples/math": { @@ -93,13 +101,13 @@ "dependencies": { "dotenv": "^16.3.1", "find-config": "^1.0.0", - "typechat": "^0.1.0" + "typechat": "^0.1.0", + "typescript": "^5.3.3" }, "devDependencies": { "@types/find-config": "1.0.4", "@types/node": "^20.10.4", - "copyfiles": "^2.4.1", - "typescript": "^5.3.3" + "copyfiles": "^2.4.1" } }, "examples/multiSchema": { @@ -110,13 +118,13 @@ "dotenv": "^16.3.1", "find-config": "^1.0.0", "music": "^0.0.1", - "typechat": "^0.1.0" + "typechat": "^0.1.0", + "typescript": "^5.3.3" }, "devDependencies": { "@types/find-config": "1.0.4", "@types/node": "^20.3.1", - "copyfiles": "^2.4.1", - "typescript": "^5.3.3" + "copyfiles": "^2.4.1" } }, "examples/music": { @@ -130,15 +138,15 @@ "find-config": "^1.0.0", "open": "^7.0.4", "sqlite3": "^5.1.6", - "typechat": "^0.1.0" + "typechat": "^0.1.0", + "typescript": "^5.3.3" }, "devDependencies": { "@types/express": "^4.17.17", "@types/find-config": "1.0.4", "@types/node": "^20.10.4", "@types/spotify-api": "^0.0.22", - "copyfiles": "^2.4.1", - "typescript": "^5.3.3" + "copyfiles": "^2.4.1" } }, "examples/restaurant": { @@ -147,13 +155,13 @@ "dependencies": { "dotenv": "^16.3.1", "find-config": "^1.0.0", - "typechat": "^0.1.0" + "typechat": "^0.1.0", + "typescript": "^5.3.3" }, "devDependencies": { "@types/find-config": "1.0.4", "@types/node": "^20.10.4", - "copyfiles": "^2.4.1", - "typescript": "^5.3.3" + "copyfiles": "^2.4.1" } }, "examples/sentiment": { @@ -162,13 +170,13 @@ "dependencies": { "dotenv": "^16.3.1", "find-config": "^1.0.0", - "typechat": "^0.1.0" + "typechat": "^0.1.0", + "typescript": "^5.3.3" }, "devDependencies": { "@types/find-config": "1.0.4", "@types/node": "^20.10.4", - "copyfiles": "^2.4.1", - "typescript": "^5.3.3" + "copyfiles": "^2.4.1" } }, "examples/sentiment-zod": { diff --git a/typescript/package.json b/typescript/package.json index 21b9d4f7..9c62bbcc 100644 --- a/typescript/package.json +++ b/typescript/package.json @@ -38,10 +38,19 @@ "README.md", "SECURITY.md" ], - "dependencies": { + "dependencies": {}, + "peerDependencies": { "typescript": "^5.3.3", "zod": "^3.22.4" }, + "peerDependenciesMeta": { + "typescript": { + "optional": true + }, + "zod": { + "optional": true + } + }, "devDependencies": { "@types/node": "^20.10.4" }, From 6a15d78f141c4a03d31e97dd55784996955b71e0 Mon Sep 17 00:00:00 2001 From: Anders Hejlsberg Date: Wed, 20 Mar 2024 06:59:01 -0700 Subject: [PATCH 04/20] Move processRequests function to 'typechat/interactive' package (#221) --- typescript/examples/calendar/src/main.ts | 3 ++- typescript/examples/coffeeShop-zod/src/main.ts | 3 ++- typescript/examples/coffeeShop/src/main.ts | 3 ++- typescript/examples/healthData/src/main.ts | 3 ++- typescript/examples/math/src/main.ts | 3 ++- typescript/examples/multiSchema/src/main.ts | 3 ++- typescript/examples/restaurant/src/main.ts | 4 +++- typescript/examples/sentiment-zod/src/main.ts | 3 ++- typescript/examples/sentiment/src/main.ts | 3 ++- typescript/package.json | 3 ++- typescript/src/index.ts | 1 - typescript/src/interactive/index.ts | 1 + typescript/src/{ => interactive}/interactive.ts | 0 13 files changed, 22 insertions(+), 11 deletions(-) create mode 100644 typescript/src/interactive/index.ts rename typescript/src/{ => interactive}/interactive.ts (100%) diff --git a/typescript/examples/calendar/src/main.ts b/typescript/examples/calendar/src/main.ts index f07f0eae..03d71244 100644 --- a/typescript/examples/calendar/src/main.ts +++ b/typescript/examples/calendar/src/main.ts @@ -3,8 +3,9 @@ import dotenv from "dotenv"; import findConfig from "find-config"; import fs from "fs"; import path from "path"; -import { createJsonTranslator, createLanguageModel, processRequests } from "typechat"; +import { createJsonTranslator, createLanguageModel } from "typechat"; import { createTypeScriptJsonValidator } from "typechat/ts"; +import { processRequests } from "typechat/interactive"; import { CalendarActions } from './calendarActionsSchema'; const dotEnvPath = findConfig(".env"); diff --git a/typescript/examples/coffeeShop-zod/src/main.ts b/typescript/examples/coffeeShop-zod/src/main.ts index 2bfa30f7..a97fe71b 100644 --- a/typescript/examples/coffeeShop-zod/src/main.ts +++ b/typescript/examples/coffeeShop-zod/src/main.ts @@ -1,8 +1,9 @@ import assert from "assert"; import dotenv from "dotenv"; import findConfig from "find-config"; -import { createJsonTranslator, createLanguageModel, processRequests } from "typechat"; +import { createJsonTranslator, createLanguageModel } from "typechat"; import { createZodJsonValidator } from "typechat/zod"; +import { processRequests } from "typechat/interactive"; import { z } from "zod"; import { CoffeeShopSchema } from "./coffeeShopSchema"; diff --git a/typescript/examples/coffeeShop/src/main.ts b/typescript/examples/coffeeShop/src/main.ts index f03bd6fe..fd6326f4 100644 --- a/typescript/examples/coffeeShop/src/main.ts +++ b/typescript/examples/coffeeShop/src/main.ts @@ -3,8 +3,9 @@ import dotenv from "dotenv"; import findConfig from "find-config"; import fs from "fs"; import path from "path"; -import { createJsonTranslator, createLanguageModel, processRequests } from "typechat"; +import { createJsonTranslator, createLanguageModel } from "typechat"; import { createTypeScriptJsonValidator } from "typechat/ts"; +import { processRequests } from "typechat/interactive"; import { Cart } from "./coffeeShopSchema"; const dotEnvPath = findConfig(".env"); diff --git a/typescript/examples/healthData/src/main.ts b/typescript/examples/healthData/src/main.ts index 82e7e817..fe3e134e 100644 --- a/typescript/examples/healthData/src/main.ts +++ b/typescript/examples/healthData/src/main.ts @@ -3,7 +3,8 @@ import dotenv from "dotenv"; import findConfig from "find-config"; import fs from "fs"; import path from "path"; -import { createLanguageModel, processRequests } from "typechat"; +import { createLanguageModel } from "typechat"; +import { processRequests } from "typechat/interactive"; import { HealthDataResponse } from "./healthDataSchema"; import { createHealthDataTranslator } from "./translator"; diff --git a/typescript/examples/math/src/main.ts b/typescript/examples/math/src/main.ts index 55cea745..cda811c3 100644 --- a/typescript/examples/math/src/main.ts +++ b/typescript/examples/math/src/main.ts @@ -3,7 +3,8 @@ import dotenv from "dotenv"; import findConfig from "find-config"; import fs from "fs"; import path from "path"; -import { createLanguageModel, getData, processRequests } from "typechat"; +import { createLanguageModel, getData } from "typechat"; +import { processRequests } from "typechat/interactive"; import { createModuleTextFromProgram, createProgramTranslator, evaluateJsonProgram } from "typechat/ts"; const dotEnvPath = findConfig(".env"); diff --git a/typescript/examples/multiSchema/src/main.ts b/typescript/examples/multiSchema/src/main.ts index f241bdee..8820a616 100644 --- a/typescript/examples/multiSchema/src/main.ts +++ b/typescript/examples/multiSchema/src/main.ts @@ -3,7 +3,8 @@ import dotenv from "dotenv"; import findConfig from "find-config"; import fs from "fs"; import path from "path"; -import { createLanguageModel, processRequests } from "typechat"; +import { createLanguageModel } from "typechat"; +import { processRequests } from "typechat/interactive"; import { createJsonMathAgent, createJsonPrintAgent } from "./agent"; import { createAgentRouter } from "./router"; diff --git a/typescript/examples/restaurant/src/main.ts b/typescript/examples/restaurant/src/main.ts index b0bf6afb..fd95e89b 100644 --- a/typescript/examples/restaurant/src/main.ts +++ b/typescript/examples/restaurant/src/main.ts @@ -6,8 +6,10 @@ import path from "path"; import { createJsonTranslator, createLanguageModel, - processRequests, } from "typechat"; +import { + processRequests, +} from "typechat/interactive"; import { createTypeScriptJsonValidator, } from "typechat/ts"; diff --git a/typescript/examples/sentiment-zod/src/main.ts b/typescript/examples/sentiment-zod/src/main.ts index 5f521707..d52a3795 100644 --- a/typescript/examples/sentiment-zod/src/main.ts +++ b/typescript/examples/sentiment-zod/src/main.ts @@ -1,7 +1,8 @@ import assert from "assert"; import dotenv from "dotenv"; import findConfig from "find-config"; -import { createJsonTranslator, createLanguageModel, processRequests } from "typechat"; +import { createJsonTranslator, createLanguageModel } from "typechat"; +import { processRequests } from "typechat/interactive"; import { createZodJsonValidator } from "typechat/zod"; import { SentimentSchema } from "./sentimentSchema"; diff --git a/typescript/examples/sentiment/src/main.ts b/typescript/examples/sentiment/src/main.ts index b07b2aaa..4a7590e4 100644 --- a/typescript/examples/sentiment/src/main.ts +++ b/typescript/examples/sentiment/src/main.ts @@ -3,7 +3,8 @@ import dotenv from "dotenv"; import findConfig from "find-config"; import fs from "fs"; import path from "path"; -import { createJsonTranslator, createLanguageModel, processRequests } from "typechat"; +import { createJsonTranslator, createLanguageModel } from "typechat"; +import { processRequests } from "typechat/interactive"; import { createTypeScriptJsonValidator } from "typechat/ts"; import { SentimentResponse } from "./sentimentSchema"; diff --git a/typescript/package.json b/typescript/package.json index 9c62bbcc..ddb93c06 100644 --- a/typescript/package.json +++ b/typescript/package.json @@ -27,7 +27,8 @@ "exports": { ".": "./dist/index.js", "./ts": "./dist/ts/index.js", - "./zod": "./dist/zod/index.js" + "./zod": "./dist/zod/index.js", + "./interactive": "./dist/interactive/index.js" }, "engines": { "node": ">=18" diff --git a/typescript/src/index.ts b/typescript/src/index.ts index aae46aba..7029f515 100644 --- a/typescript/src/index.ts +++ b/typescript/src/index.ts @@ -1,4 +1,3 @@ export * from './result'; export * from './model'; export * from './typechat'; -export * from './interactive'; diff --git a/typescript/src/interactive/index.ts b/typescript/src/interactive/index.ts new file mode 100644 index 00000000..aad61099 --- /dev/null +++ b/typescript/src/interactive/index.ts @@ -0,0 +1 @@ +export * from './interactive'; diff --git a/typescript/src/interactive.ts b/typescript/src/interactive/interactive.ts similarity index 100% rename from typescript/src/interactive.ts rename to typescript/src/interactive/interactive.ts From 11dd31668a833eb67806756bb78f2f521002b2c3 Mon Sep 17 00:00:00 2001 From: Daniel Rosenwasser Date: Wed, 20 Mar 2024 18:43:24 -0700 Subject: [PATCH 05/20] Add compliance and social media links to footer. (#223) --- site/src/_includes/footer.njk | 29 ++++++++++++++++++++--------- 1 file changed, 20 insertions(+), 9 deletions(-) diff --git a/site/src/_includes/footer.njk b/site/src/_includes/footer.njk index 4a186153..d7eae138 100644 --- a/site/src/_includes/footer.njk +++ b/site/src/_includes/footer.njk @@ -1,15 +1,26 @@ From 27cb545b9f807f34887ea54132896f472616176b Mon Sep 17 00:00:00 2001 From: Daniel Rosenwasser Date: Mon, 25 Mar 2024 11:19:40 -0700 Subject: [PATCH 06/20] Blog post for TypeChat 0.1.0. (#222) * Blog post for TypeChat 0.1.0. * grammar error * Address feedback. * Wrap up the blog post. --- site/src/blog/announcing-typechat-0-1-0.md | 212 +++++++++++++++++++++ 1 file changed, 212 insertions(+) create mode 100644 site/src/blog/announcing-typechat-0-1-0.md diff --git a/site/src/blog/announcing-typechat-0-1-0.md b/site/src/blog/announcing-typechat-0-1-0.md new file mode 100644 index 00000000..ce5a5f45 --- /dev/null +++ b/site/src/blog/announcing-typechat-0-1-0.md @@ -0,0 +1,212 @@ +--- +title: Announcing TypeChat 0.1.0 +layout: blog +tags: post +date: 2024-03-25 +authors: ["Daniel Rosenwasser"] +--- + +# {{title}} + +*{{date | formatDate}}{% if authors %} by {{authors | formatList}}{% endif %}* + +Today we've released a new version of TypeChat for TypeScript and JavaScript. To get it, you can run + +```sh +npm install typechat +``` + +As a refresher, TypeChat is an experimental library for getting structured output (like JSON) from AI language models. +The way it works is by using types in your programs to guide language models, and then using those same types to ensure that the responses match up with your types. +When they don't, TypeChat can use validation errors to guide language models to repair their responses. +You can [read our original announcement blog post](./introducing-typechat) for more details, but we should be able to catch you up to speed here too. + +Here's a few things that are new to TypeChat for TypeScript. + +## Pluggable Validators + +The original version of TypeChat actually leveraged the raw contents of a TypeScript schema file. +It looked something like this: + +```ts +// Load up the contents of our "Response" schema. +const schema = fs.readFileSync(path.join(__dirname, "sentimentSchema.ts"), "utf8"); +const translator = typechat.createJsonTranslator(model, schema, "SomeType"); + +// Process requests interactively. +typechat.processRequests("> ", /*inputFile*/ undefined, async (request) => { + const response = await translator.translate(request); + + if (response.success) { + console.log(`❌ ${response.message}`); + return; + } + + console.log("The request was translated into the following value:") + console.log(response.data); +}); +``` + +This worked, but had a few issues: + +1. The schema file had to be self-contained. Everything had to be in the same file for TypeChat. +1. The schema file also had to be present if you weren't running in-place. + + This often meant copying the schema file along to the output directory if you weren't using something like ts-node, tsx, or tsimp. + +1. The schema was fixed. While possible to generate a text schema on the fly, it's an error-prone task. + +While there are a lot of ergonomic benefits to using a textual TypeScript schema, we explored whether there we could add a bit more flexibility and made a few changes to TypeChat. + +The first is that we've broken out a piece of `TypeChatJsonTranslator` into a more granular concept: a `TypeChatJsonValidator`. +A `TypeChatJsonValidator` is responsible for generating a string schema representation to guide language models, and to actually make sure the data that comes back matches some type. +This means that to construct a `TypeChatJsonTranslator`, you need to make a `TypeChatJsonValidator` first; +but it also means that validators are swappable. +Here's what using that looks like now: + +```ts +import fs from "fs"; +import path from "path"; + +import { createLanguageModel, createJsonTranslator } from "typechat"; +import { createTypeScriptJsonValidator } from "typechat/ts"; + +import { SentimentResponse } from "./sentimentSchema"; + +const model = createLanguageModel(process.env); +const schema = fs.readFileSync(path.join(__dirname, "sentimentSchema.ts"), "utf8"); +const validator = createTypeScriptJsonValidator(schema, "SentimentResponse"); +const translator = createJsonTranslator(model, validator); + +translator.translate("hello world!").then(response => { + if (!response.success) { + console.log(response.message); + return; + } + console.log(`The sentiment is ${response.data.sentiment}`); +}); +``` + +Notice that instead of passing the schema into `createJsonTranslator`, we're passing it into `createTypeScriptJsonValidator` which we need to import from `typechat/ts`. +The created validator the needs to be passed into `createJsonTranslator`. + +For existing calls to `createJsonTranslator`, you'll probably see a message like: + +> TS2554: Expected 2 arguments, but got 3. + +you'll need to drop the name of the type, and substitute the argument schema with a validator. +Here's the effective diff: + +```diff + import { createJsonTranslator, createLanguageModel, processRequests } from "typechat"; ++ import { createTypeScriptJsonValidator } from "typechat/ts"; + import { SentimentResponse } from "./sentimentSchema"; + + // ... + +- const translator = createJsonTranslator(model, schema, "Sentiment") ++ const validator = createTypeScriptJsonValidator(schema, "SentimentResponse"); ++ const translator = createJsonTranslator(model, validator); + + // ... +``` + +## Zod Validators + +The second change builds on pluggable validators: TypeChat makes it possible to create validators from Zod schemas. +[If you're not familiar with Zod](https://zod.dev/), it's a popular library in the TypeScript/JavaScript ecosystem for validating data. +One strength of this library is that as Zod type validator objects are constructed, static types can be derived from them. +But for TypeChat, its more notable strength is the ability to construct schemas *dynamically*. + +To use a Zod-based schema, we first need to create a few Zod type validator objects and create an object defining all the ones we intend to use. + +```ts +// sentimentSchema.ts + +import { z } from "zod"; + +export const SentimentResponse = z.object({ + sentiment: z.enum(["negative", "neutral", "positive"]) + .describe("The sentiment of the text") +}); + +// Maps the property "SentimentResponse" to the above Zod validator. +export const SentimentSchema = { + SentimentResponse +}; +``` + +Note that while TypeScript schema files can use raw JavaScript/TypeScript `// comment` syntax, TypeChat generates comments from Zod based on [whatever we pass in to `.describe()` calls](https://zod.dev/?id=describe). + +Next, we have to construct a TypeChat Zod validator. +We pass in the object map of types, and specify which type we want the model to conform to: + +```ts +// main.ts + +import { createJsonTranslator, createLanguageModel } from "typechat"; +import { createZodJsonValidator } from "typechat/zod"; + +import { SentimentSchema } from "./sentimentSchema"; + +const model = createLanguageModel(process.env); +const validator = createZodJsonValidator(SentimentSchema, "SentimentResponse"); +const translator = createJsonTranslator(model, validator); + +translator.translate("hello world!").then(response => { + if (!response.success) { + console.log(response.message); + return; + } + console.log(`The sentiment is ${response.data.sentiment}`); +}); +``` + +That's it! + +While using a Zod schema has lots of advantages, you may still prefer the ergonomics of writing a plain TypeScript schema. +Either option works. + +For more information, [see the changes on GitHub](https://github.com/microsoft/TypeChat/pull/147). + +## A `validateInstance` Hook + +Another new addition to TypeChat is the `validateInstance` hook on `TypeChatJsonTranslator`s. +It allows you to tack on an extra level of validation beyond what the internal validator will perform. + +```ts +import { createJsonTranslator, error, success } from "typechat"; + +// ... + +const translator = createJsonTranslator(model, validator); +translator.validateInstance = summary => { + for (const person of summary.people) { + if (person.age < 0) { + return error( + `'{person.name}' has a negative age, that doesn't make sense.` + ) + } + } + return success(summary) +} +``` + +If `validateInstance` returns a TypeChat `Error`, then the translator will use the message to repair the AI response. + +You can [see specifics of this change on GitHub](https://github.com/microsoft/TypeChat/pull/115). + +## Other Changes + +Other changes to be aware of are: + +* `TypeChatJsonProgram` and related functions, such as `createModuleTextFromProgram`, `evaluateJsonProgram`, and `createProgramTranslator` all live in `typechat/ts` ([see PR](https://github.com/microsoft/TypeChat/pull/147)). +* The `processRequests` function for creating a REPL-like prompt now lives in `typechat/interactive` ([see PR](https://github.com/microsoft/TypeChat/pull/221)). + +## What's Next? + +We'll be trying to improve TypeChat based on the feedback we receive. +We're also working to bring TypeChat to other language ecosystems, like Python and .NET, so keep an eye out for that in the near future. + +Give TypeChat a try and let us know what you think over [on GitHub](https://github.com/microsoft/TypeChat/), where you can file an issue or post a topic in our discussion forum! + From f51015501a3854b23759bd6065a5f24a05a090d4 Mon Sep 17 00:00:00 2001 From: Daniel Rosenwasser Date: Wed, 27 Mar 2024 18:55:26 +0000 Subject: [PATCH 07/20] Fix link. --- site/src/blog/announcing-typechat-0-1-0.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/site/src/blog/announcing-typechat-0-1-0.md b/site/src/blog/announcing-typechat-0-1-0.md index ce5a5f45..37b32d03 100644 --- a/site/src/blog/announcing-typechat-0-1-0.md +++ b/site/src/blog/announcing-typechat-0-1-0.md @@ -19,7 +19,7 @@ npm install typechat As a refresher, TypeChat is an experimental library for getting structured output (like JSON) from AI language models. The way it works is by using types in your programs to guide language models, and then using those same types to ensure that the responses match up with your types. When they don't, TypeChat can use validation errors to guide language models to repair their responses. -You can [read our original announcement blog post](./introducing-typechat) for more details, but we should be able to catch you up to speed here too. +You can [read our original announcement blog post](/blog/introducing-typechat/) for more details, but we should be able to catch you up to speed here too. Here's a few things that are new to TypeChat for TypeScript. From 6fa23f88896ddffa26a8c160538ebbb016146baa Mon Sep 17 00:00:00 2001 From: Daniel Rosenwasser Date: Thu, 28 Mar 2024 17:52:29 +0000 Subject: [PATCH 08/20] Update inline code color to address contrast issues, remove bottom border from footer links. --- site/src/_includes/footer.njk | 4 ++-- site/src/css/styles.css | 4 +++- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/site/src/_includes/footer.njk b/site/src/_includes/footer.njk index d7eae138..059cc107 100644 --- a/site/src/_includes/footer.njk +++ b/site/src/_includes/footer.njk @@ -1,5 +1,5 @@