Skip to content

Commit

Permalink
Add support for debug option, change details structure, bump to 2.0.0 (
Browse files Browse the repository at this point in the history
…#11)

* Adds support for debug option.
* Adds a docs script so we can test and experiment locally.
* Refactors the types to prefer undefined over null, to simplify the conditions the consumer must consider.
* Changes the details structure (breaking change that bumps the major to 2.0.0) so that it's easier to consume.
* Surfaces summary.prompt and chat.rephrasedQuery in debug response.
* Adds unit tests using msw. Exports createStreamingServer as part of the module's interface so consumers can use it in their tests.
  • Loading branch information
cjcenizal authored Apr 20, 2024
1 parent 4c93777 commit b664b49
Show file tree
Hide file tree
Showing 23 changed files with 16,945 additions and 387 deletions.
24 changes: 24 additions & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
module.exports = {
extends: [
"eslint:recommended",
"plugin:@typescript-eslint/recommended",
"prettier",
],
parser: "@typescript-eslint/parser",
plugins: ["@typescript-eslint"],
root: true,
ignorePatterns: [
".eslintrc.js",
"jest.config.js",
"build.js",
"buildConfigs.js",
"docs/build.js",
"docs/buildConfigs.js",
"docs/docsServer.js",
"docs/public/",
"lib/",
],
rules: {
"@typescript-eslint/no-unused-vars": "error",
},
};
7 changes: 5 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
/node_modules
/coverage
/docs/node_modules/
/docs/public/script.js
/docs/public/script.js.map
/lib

/node_modules
.DS_Store
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,9 @@ const sendQuery = async () => {
queryValue: "Who put the ram in the ramalamadingdong?",
summaryNumResults: 5,
language: "eng",
debug: true,
enableFactualConsistencyScore: true,
summaryPromptName: "summary-prompt-name",
};

const onStreamUpdate = (update: StreamUpdate) => {
Expand Down
14 changes: 2 additions & 12 deletions build.js
Original file line number Diff line number Diff line change
@@ -1,19 +1,9 @@
const { build } = require("esbuild");
const { devDependencies } = require("./package.json");
const config = require("./buildConfig");

build({
bundle: true,
...config,
entryPoints: ["src/index.ts"],
logLevel: "info",
treeShaking: true,
minify: true,

// Removing source maps theoretically shaves around 100kb of the package size.
// Initially setting this to false and will verify the npm package size.
sourcemap: false,
external: [...Object.keys(devDependencies)],
target: ["esnext", "node12.22.0"],
outdir: "./lib",
outbase: "./src",
format: "cjs",
});
15 changes: 15 additions & 0 deletions buildConfig.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
const { devDependencies } = require("./package.json");

module.exports = {
bundle: true,
logLevel: "info",
treeShaking: true,
minify: true,

// Removing source maps theoretically shaves around 100kb of the package size.
// Initially setting this to false and will verify the npm package size.
sourcemap: false,
external: [...Object.keys(devDependencies)],
target: ["esnext", "node12.22.0"],
format: "cjs",
};
4 changes: 4 additions & 0 deletions docs/build.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
const { build } = require("esbuild");
const { config } = require("./buildConfigs");

build(config);
13 changes: 13 additions & 0 deletions docs/buildConfigs.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
module.exports = {
config: {
bundle: true,
define: {
"process.env.NODE_ENV": JSON.stringify(
process.env.NODE_ENV || "development"
),
},
entryPoints: ["src/index.tsx"],
outfile: "public/script.js",
sourcemap: false,
},
};
35 changes: 35 additions & 0 deletions docs/docsServer.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
const esbuild = require("esbuild");
const chokidar = require("chokidar");
const liveServer = require("live-server");
const buildConfig = require("../buildConfig");
const { config: devScriptBuildConfig } = require("./buildConfigs");

(async () => {
// Builder for the component package
const packageBuilder = await esbuild.context({
...buildConfig,
entryPoints: ["../src/index.ts"],
outdir: "../lib",
outbase: "../src",
});

// Builder for the development page
const devPageBuilder = await esbuild.context(devScriptBuildConfig);

chokidar
// Watch for changes to dev env code or react-search src
.watch(["src/*.{ts,tsx}", "src/**/*.{ts,tsx}", "../src/**/*.{ts,tsx}"], {
interval: 0, // No delay
})
.on("all", async () => {
await packageBuilder.rebuild();
devPageBuilder.rebuild();
});

// `liveServer` local server for hot reload.
liveServer.start({
open: true,
port: +process.env.PORT || 8080,
root: "public",
});
})();
Loading

0 comments on commit b664b49

Please sign in to comment.