Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,3 @@ node_modules/
**/tsconfig.debug.json
!**/.vscode/launch.json
**/build.bat

113 changes: 113 additions & 0 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
{
"version": "0.2.0",
"configurations": [
{
"name": "sentiment",
"type": "node",
"request": "launch",
"program": "${workspaceFolder}/typescript/examples/sentiment/src/main.ts",
"stopOnEntry": false,
"args": [],
"cwd": "${workspaceFolder}/typescript/examples/sentiment",
"skipFiles": [
"<node_internals>/**"
],
"preLaunchTask": "build-sentiment",
"sourceMaps": true,
"outFiles": [
"${workspaceFolder}/typescript/examples/sentiment/dist/**/*.js"
],
"console": "integratedTerminal"
},
{
"name": "calendar",
"type": "node",
"request": "launch",
"program": "${workspaceFolder}/typescript/examples/calendar/src/main.ts",
"stopOnEntry": false,
"args": [],
"cwd": "${workspaceFolder}/typescript/examples/calendar",
"skipFiles": [
"<node_internals>/**"
],
"preLaunchTask": "build-calendar",
"sourceMaps": true,
"outFiles": [
"${workspaceFolder}/typescript/examples/calendar/dist/**/*.js"
],
"console": "integratedTerminal"
},
{
"name": "math",
"type": "node",
"request": "launch",
"program": "${workspaceFolder}/typescript/examples/math/src/main.ts",
"stopOnEntry": false,
"args": [],
"cwd": "${workspaceFolder}/typescript/examples/math",
"skipFiles": [
"<node_internals>/**"
],
"preLaunchTask": "build-math",
"sourceMaps": true,
"outFiles": [
"${workspaceFolder}/typescript/examples/math/dist/**/*.js"
],
"console": "integratedTerminal"
},
{
"name": "music",
"type": "node",
"request": "launch",
"program": "${workspaceFolder}/typescript/examples/music/src/main.ts",
"stopOnEntry": false,
"args": [],
"cwd": "${workspaceFolder}/typescript/examples/music",
"skipFiles": [
"<node_internals>/**"
],
"preLaunchTask": "build-music",
"sourceMaps": true,
"outFiles": [
"${workspaceFolder}/typescript/examples/music/dist/**/*.js"
],
"console": "integratedTerminal"
},
{
"name": "restaurant",
"type": "node",
"request": "launch",
"program": "${workspaceFolder}/typescript/examples/restaurant/src/main.ts",
"stopOnEntry": false,
"args": [],
"cwd": "${workspaceFolder}/typescript/examples/restaurant",
"skipFiles": [
"<node_internals>/**"
],
"preLaunchTask": "build-restaurant",
"sourceMaps": true,
"outFiles": [
"${workspaceFolder}/typescript/examples/restaurant/dist/**/*.js"
],
"console": "integratedTerminal"
},
{
"name": "coffeeShop",
"type": "node",
"request": "launch",
"program": "${workspaceFolder}/typescript/examples/coffeeShop/src/main.ts",
"stopOnEntry": false,
"args": [],
"cwd": "${workspaceFolder}/typescript/examples/coffeeShop",
"skipFiles": [
"<node_internals>/**"
],
"preLaunchTask": "build-coffeeShop",
"sourceMaps": true,
"outFiles": [
"${workspaceFolder}/typescript/examples/coffeeShop/dist/**/*.js"
],
"console": "integratedTerminal"
}
]
}
59 changes: 59 additions & 0 deletions .vscode/tasks.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
{
"version": "2.0.0",
"tasks": [
{
"label": "build-sentiment",
"type": "npm",
"script": "build",
"path": "typescript/examples/sentiment",
"group": "build",
"problemMatcher": [],
"detail": "tsc -p src"
},
{
"label": "build-calendar",
"type": "npm",
"script": "build",
"path": "typescript/examples/calendar",
"group": "build",
"problemMatcher": [],
"detail": "tsc -p src"
},
{
"label": "build-math",
"type": "npm",
"script": "build",
"path": "typescript/examples/math",
"group": "build",
"problemMatcher": [],
"detail": "tsc -p src"
},
{
"label": "build-music",
"type": "npm",
"script": "build",
"path": "typescript/examples/music",
"group": "build",
"problemMatcher": [],
"detail": "tsc -p src"
},
{
"label": "build-restaurant",
"type": "npm",
"script": "build",
"path": "typescript/examples/restaurant",
"group": "build",
"problemMatcher": [],
"detail": "tsc -p src"
},
{
"label": "build-coffeeShop",
"type": "npm",
"script": "build",
"path": "typescript/examples/coffeeShop",
"group": "build",
"problemMatcher": [],
"detail": "tsc -p src"
}
]
}
6 changes: 5 additions & 1 deletion typescript/examples/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ To use an Azure OpenAI endpoint, include the following environment variables:
| `AZURE_OPENAI_ENDPOINT` | The full URL of the Azure OpenAI REST API (e.g. `https://YOUR_RESOURCE_NAME.openai.azure.com/openai/deployments/YOUR_DEPLOYMENT_NAME/chat/completions?api-version=2023-05-15`) |
| `AZURE_OPENAI_API_KEY` | Your Azure OpenAI API key |

We recommend setting environment variables by creating a `.env` file in the root directory of the project that looks like the following:
Copy [`.env.example`](../../.env.example) to `.env` in the repository root, then fill in the values for the endpoint you want to use:

```ini
# For OpenAI
Expand All @@ -92,6 +92,8 @@ AZURE_OPENAI_ENDPOINT=...
AZURE_OPENAI_API_KEY=...
```

Examples that search for `.env` look in the current working directory and its parent directories. If no file is found, they print a setup message and exit with status `1`, without an assertion stack trace.

### Using a proxy (optional)

If the model endpoint can only be reached through a proxy (for example in restricted regions),
Expand All @@ -117,6 +119,8 @@ Examples can be found in the `examples` directory.

To run an example interactively, type `node ./dist/main.js` from the example's directory and enter requests when prompted. Type `quit` or `exit` to end the session. You can also open in VS Code the selected example's directory and press <kbd>F5</kbd> to launch it in debug mode.

To debug from the repository root in VS Code, choose an example configuration in Run and Debug and press <kbd>F5</kbd>. Configure `.env` as described above before starting the debugger.

Note that there are various sample "prose" files (e.g. `input.txt`) provided in each `src` directory that can give a sense of what you can run.

To run an example with one of these input files, run `node ./dist/main.js <input-file-path>`.
Expand Down
9 changes: 7 additions & 2 deletions typescript/examples/calendar/src/main.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import assert from "assert";
import dotenv from "dotenv";
import findConfig from "find-config";
import fs from "fs";
Expand All @@ -9,7 +8,13 @@ import { processRequests } from "typechat/interactive";
import { CalendarActions } from './calendarActionsSchema';

const dotEnvPath = findConfig(".env");
assert(dotEnvPath, ".env file not found!");
if (!dotEnvPath) {
console.error(
"Error: .env file not found.\n" +
"Copy .env.example to .env in the repository root and configure your OpenAI or Azure OpenAI credentials."
);
process.exit(1);
}
dotenv.config({ path: dotEnvPath });

const model = createLanguageModel(process.env);
Expand Down
9 changes: 7 additions & 2 deletions typescript/examples/coffeeShop-zod/src/main.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import assert from "assert";
import dotenv from "dotenv";
import findConfig from "find-config";
import { createJsonTranslator, createLanguageModel } from "typechat";
Expand All @@ -8,7 +7,13 @@ import { z } from "zod";
import { CoffeeShopSchema } from "./coffeeShopSchema";

const dotEnvPath = findConfig(".env");
assert(dotEnvPath, ".env file not found!");
if (!dotEnvPath) {
console.error(
"Error: .env file not found.\n" +
"Copy .env.example to .env in the repository root and configure your OpenAI or Azure OpenAI credentials."
);
process.exit(1);
}
dotenv.config({ path: dotEnvPath });

const model = createLanguageModel(process.env);
Expand Down
9 changes: 7 additions & 2 deletions typescript/examples/coffeeShop/src/main.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import assert from "assert";
import dotenv from "dotenv";
import findConfig from "find-config";
import fs from "fs";
Expand All @@ -9,7 +8,13 @@ import { processRequests } from "typechat/interactive";
import { Cart } from "./coffeeShopSchema";

const dotEnvPath = findConfig(".env");
assert(dotEnvPath, ".env file not found!");
if (!dotEnvPath) {
console.error(
"Error: .env file not found.\n" +
"Copy .env.example to .env in the repository root and configure your OpenAI or Azure OpenAI credentials."
);
process.exit(1);
}
dotenv.config({ path: dotEnvPath });

const model = createLanguageModel(process.env);
Expand Down
9 changes: 7 additions & 2 deletions typescript/examples/crossword/src/main.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import assert from "assert";
import dotenv from "dotenv";
import findConfig from "find-config";
import fs from "fs";
Expand All @@ -10,7 +9,13 @@ import { CrosswordActions } from "./crosswordSchema";
import { createCrosswordActionTranslator } from "./translator";

const dotEnvPath = findConfig(".env");
assert(dotEnvPath, ".env file not found!");
if (!dotEnvPath) {
console.error(
"Error: .env file not found.\n" +
"Copy .env.example to .env in the repository root and configure your OpenAI or Azure OpenAI credentials."
);
process.exit(1);
}
dotenv.config({ path: dotEnvPath });

const model = createLanguageModel(process.env);
Expand Down
9 changes: 7 additions & 2 deletions typescript/examples/drawing/src/main.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import assert from "assert";
import dotenv from "dotenv";
import findConfig from "find-config";
import fs from "fs";
Expand All @@ -10,7 +9,13 @@ import { Drawing } from "./drawingSchema";
import { renderDrawingToSvg } from "./render";

const dotEnvPath = findConfig(".env");
assert(dotEnvPath, ".env file not found!");
if (!dotEnvPath) {
console.error(
"Error: .env file not found.\n" +
"Copy .env.example to .env in the repository root and configure your OpenAI or Azure OpenAI credentials."
);
process.exit(1);
}
dotenv.config({ path: dotEnvPath });

const model = createLanguageModel(process.env);
Expand Down
9 changes: 7 additions & 2 deletions typescript/examples/healthData/src/main.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import assert from "assert";
import dotenv from "dotenv";
import findConfig from "find-config";
import fs from "fs";
Expand All @@ -9,7 +8,13 @@ import { HealthDataResponse } from "./healthDataSchema";
import { createHealthDataTranslator } from "./translator";

const dotEnvPath = findConfig(".env");
assert(dotEnvPath, ".env file not found!");
if (!dotEnvPath) {
console.error(
"Error: .env file not found.\n" +
"Copy .env.example to .env in the repository root and configure your OpenAI or Azure OpenAI credentials."
);
process.exit(1);
}
dotenv.config({ path: dotEnvPath });

const healthInstructions = `
Expand Down
9 changes: 7 additions & 2 deletions typescript/examples/math/src/main.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import assert from "assert";
import dotenv from "dotenv";
import findConfig from "find-config";
import fs from "fs";
Expand All @@ -8,7 +7,13 @@ import { processRequests } from "typechat/interactive";
import { createModuleTextFromProgram, createProgramTranslator, evaluateJsonProgram } from "typechat/ts";

const dotEnvPath = findConfig(".env");
assert(dotEnvPath, ".env file not found!");
if (!dotEnvPath) {
console.error(
"Error: .env file not found.\n" +
"Copy .env.example to .env in the repository root and configure your OpenAI or Azure OpenAI credentials."
);
process.exit(1);
}
dotenv.config({ path: dotEnvPath });

const model = createLanguageModel(process.env);
Expand Down
9 changes: 7 additions & 2 deletions typescript/examples/multiSchema/src/main.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import assert from "assert";
import dotenv from "dotenv";
import findConfig from "find-config";
import fs from "fs";
Expand All @@ -9,7 +8,13 @@ import { createJsonMathAgent, createJsonPrintAgent } from "./agent";
import { createAgentRouter } from "./router";

const dotEnvPath = findConfig(".env");
assert(dotEnvPath, ".env file not found!");
if (!dotEnvPath) {
console.error(
"Error: .env file not found.\n" +
"Copy .env.example to .env in the repository root and configure your OpenAI or Azure OpenAI credentials."
);
process.exit(1);
}
dotenv.config({ path: dotEnvPath });

const model = createLanguageModel(process.env);
Expand Down
9 changes: 7 additions & 2 deletions typescript/examples/restaurant/src/main.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import assert from "assert";
import dotenv from "dotenv";
import findConfig from "find-config";
import fs from "fs";
Expand All @@ -16,7 +15,13 @@ import {
import { Order } from "./foodOrderViewSchema";

const dotEnvPath = findConfig(".env");
assert(dotEnvPath, ".env file not found!");
if (!dotEnvPath) {
console.error(
"Error: .env file not found.\n" +
"Copy .env.example to .env in the repository root and configure your OpenAI or Azure OpenAI credentials."
);
process.exit(1);
}
dotenv.config({ path: dotEnvPath });

const model = createLanguageModel(process.env);
Expand Down
Loading
Loading