Browse Source

Update example CLI

Declare main package as dependency.
master
TheoryOfNekomata 1 year ago
parent
commit
054e9390a6
5 changed files with 27 additions and 20 deletions
  1. +2
    -1
      examples/cli/package.json
  2. +14
    -11
      examples/cli/src/index.ts
  3. +1
    -4
      examples/cli/tsconfig.eslint.json
  4. +1
    -4
      examples/cli/tsconfig.json
  5. +9
    -0
      examples/cli/yarn.lock

+ 2
- 1
examples/cli/package.json View File

@@ -52,7 +52,8 @@
"dependencies": {
"@clack/core": "^0.3.2",
"esbuild-plugin-wasm": "^1.0.0",
"yargs": "^17.7.1"
"yargs": "^17.7.1",
"@modal-sh/mio-ai": "link:../.."
},
"types": "./dist/types/index.d.ts",
"main": "./dist/cjs/production/index.js",


+ 14
- 11
examples/cli/src/index.ts View File

@@ -42,12 +42,11 @@ const receiveData = (
});
memory.push(assistantMessage as OpenAi.MessageObject);
process.stdout.write('\n\n');
// const { length: promptTokens } = OpenAi.getPromptTokens(
// normalizedChatMessage,
// model,
// );
// process.stdout.write(`info:\n${promptTokens} prompt tokens\n${completionTokens} completion tokens`);
process.stdout.write(`info:\n${completionTokens} completion tokens`);
const { length: promptTokens } = OpenAi.getPromptTokens(
normalizedChatMessage,
model,
);
process.stdout.write(`info:\n${promptTokens} prompt tokens\n${completionTokens} completion tokens`);
if (argv.memory) {
process.stdout.write(`\n${memory.length} memory items`);
}
@@ -87,7 +86,7 @@ const receiveData = (
});
});

const main = (argv: Argv) => new Promise<number>(async (resolve) => {
const main = async (argv: Argv) => {
let done = false;
let resolveResult = 0;
const memory = [] as OpenAi.MessageObject[];
@@ -111,6 +110,7 @@ const main = (argv: Argv) => new Promise<number>(async (resolve) => {
return `${OpenAi.MessageRole.USER}:\n${this.valueWithCursor ?? ''}`;
},
});
// eslint-disable-next-line no-await-in-loop
const contentRaw = await textPrompt.prompt();
if (isCancel(contentRaw)) {
done = true;
@@ -121,6 +121,7 @@ const main = (argv: Argv) => new Promise<number>(async (resolve) => {
break;
}
process.stdout.write('\n');
// eslint-disable-next-line no-await-in-loop
await receiveData(aiClient, content, argv, memory);
} catch {
resolveResult = -1;
@@ -129,8 +130,8 @@ const main = (argv: Argv) => new Promise<number>(async (resolve) => {
} while (!done);

process.stdout.write('\ninfo:\nUser exited loop\n\n');
resolve(resolveResult);
});
return resolveResult;
};

main(
yargs(hideBin(process.argv))
@@ -160,7 +161,9 @@ main(
.then((result) => {
process.exit(result);
})
.catch((error) => {
console.error(error);
.catch((errRaw) => {
const error = errRaw as Error;
process.stderr.write(error.message);
process.stderr.write('\n');
process.exit(-1);
});

+ 1
- 4
examples/cli/tsconfig.eslint.json View File

@@ -16,9 +16,6 @@
"moduleResolution": "node",
"jsx": "react",
"esModuleInterop": true,
"target": "es2018",
"paths": {
"@modal-sh/mio-ai": ["./src/packages/@modal-sh/mio-ai"]
}
"target": "esnext"
}
}

+ 1
- 4
examples/cli/tsconfig.json View File

@@ -16,9 +16,6 @@
"moduleResolution": "node",
"jsx": "react",
"esModuleInterop": true,
"target": "esnext",
"paths": {
"@modal-sh/mio-ai": ["./src/packages/@modal-sh/mio-ai/src/index.ts"],
}
"target": "esnext"
}
}

+ 9
- 0
examples/cli/yarn.lock View File

@@ -241,6 +241,11 @@
picocolors "^1.0.0"
sisteransi "^1.0.5"
"@dqbd/tiktoken@^1.0.6":
version "1.0.6"
resolved "https://js.pack.modal.sh/@dqbd%2ftiktoken/-/tiktoken-1.0.6.tgz#96bfd0a4909726c61551a8c783493f01841bd163"
integrity sha512-umSdeZTy/SbPPKVuZKV/XKyFPmXSN145CcM3iHjBbmhlohBJg7vaDp4cPCW+xNlWL6L2U1sp7T2BD+di2sUKdA==
"@esbuild/android-arm64@0.17.17":
version "0.17.17"
resolved "https://registry.yarnpkg.com/@esbuild/android-arm64/-/android-arm64-0.17.17.tgz#164b054d58551f8856285f386e1a8f45d9ba3a31"
@@ -444,6 +449,10 @@
resolved "https://registry.yarnpkg.com/@mdn/browser-compat-data/-/browser-compat-data-5.2.50.tgz#f83a9a97f50e06402b8b633bf6bd3247baed1302"
integrity sha512-3qGRdT2lrIloY8xotSRTW7k3oIRJAO7WSsJymTLN1sqeB1qiWPcbQdAiDG/IQWCA2QCVQewTeT2kfZf/you94w==
"@modal-sh/mio-ai@link:../..":
version "0.0.0"
uid ""
"@next/eslint-plugin-next@^13.2.4":
version "13.3.0"
resolved "https://registry.yarnpkg.com/@next/eslint-plugin-next/-/eslint-plugin-next-13.3.0.tgz#3a4742b0817575cc0dd4d152cb10363584c215ac"


Loading…
Cancel
Save