瀏覽代碼

Update example CLI UI

Inquirer has been substituted with clack for extensibility.
master
TheoryOfNekomata 1 年之前
父節點
當前提交
558229615c
共有 5 個文件被更改,包括 46 次插入193 次删除
  1. +1
    -1
      examples/cli/package.json
  2. +0
    -53
      examples/cli/src/events.ts
  3. +29
    -20
      examples/cli/src/index.ts
  4. +13
    -118
      examples/cli/yarn.lock
  5. +3
    -1
      src/platforms/openai/usage.ts

+ 1
- 1
examples/cli/package.json 查看文件

@@ -50,8 +50,8 @@
"access": "restricted"
},
"dependencies": {
"@clack/core": "^0.3.2",
"esbuild-plugin-wasm": "^1.0.0",
"inquirer": "^9.1.5",
"yargs": "^17.7.1"
},
"types": "./dist/types/index.d.ts",


+ 0
- 53
examples/cli/src/events.ts 查看文件

@@ -1,53 +0,0 @@
import { PlatformEventEmitter, OpenAi } from '@modal-sh/mio-ai';

export const addEvents = (aiClient: PlatformEventEmitter, resolve?: Function, reject?: Function) => {
let result: Partial<OpenAi.ChatCompletion> | undefined;

aiClient.on<OpenAi.ChatCompletionChunkDataEvent>('data', (d) => {
d.choices.forEach((c) => {
if (!result) {
result = {
id: d.id,
object: OpenAi.ChatCompletionDataEventObjectType.CHAT_COMPLETION,
created: d.created,
model: d.model,
};
}

if (!Array.isArray(result?.choices)) {
result.choices = [];
}

if (!result.choices[c.index]) {
result.choices[c.index] = {
message: { content: '' },
index: c.index,
finish_reason: c.finish_reason,
};
}

if (result.choices[c.index].message) {
if (c.delta.role) {
(result.choices[c.index].message as Record<string, unknown>).role = c.delta.role;
}

if (c.delta.content) {
(result.choices[c.index].message as Record<string, unknown>)
.content += c.delta.content;
}
}

if (c.finish_reason) {
result.choices[c.index].finish_reason = c.finish_reason;
}
});
});

aiClient.on('end', () => {
resolve?.(result);
});

aiClient.on('error', (error: Error) => {
reject?.(error);
});
};

+ 29
- 20
examples/cli/src/index.ts 查看文件

@@ -1,26 +1,37 @@
import yargs from 'yargs';
import { hideBin } from 'yargs/helpers';
import { createOpenAiClient } from './app';
import { OpenAi, PlatformEventEmitter } from '@modal-sh/mio-ai';
import { TextPrompt, isCancel } from '@clack/core';
import { createOpenAiClient } from './app';

export type Argv = Record<string, unknown>;

const receiveData = (aiClient: PlatformEventEmitter, theContent: string, argv: Record<string, unknown>) => new Promise<void>((r2, rj) => {
let countTokens: number;
let completionTokens: number;

const model = (
argv.model as OpenAi.ChatCompletionModel
?? OpenAi.ChatCompletionModel.GPT_3_5_TURBO
);

aiClient.on<OpenAi.ChatCompletionChunkDataEvent>('data', (d) => {
if (d.choices?.[0]?.delta?.role) {
process.stdout.write(`${d.choices[0].delta.role}: `);
process.stdout.write(`${d.choices[0].delta.role}:\n`);
}

if (d.choices?.[0]?.delta?.content) {
countTokens += 1;
completionTokens += 1;
process.stdout.write(d.choices[0].delta.content);
}
});

aiClient.on('end', () => {
process.stdout.write('\n\n');
process.stdout.write(`info: ${countTokens} completion tokens.\n\n`);
const { length: promptTokens } = OpenAi.getPromptTokens(
OpenAi.normalizeChatMessage(theContent),
model,
);
process.stdout.write(`info:\n${promptTokens} prompt tokens\n${completionTokens} completion tokens\n\n`);
// TODO count tokens
r2();
});
@@ -31,9 +42,9 @@ const receiveData = (aiClient: PlatformEventEmitter, theContent: string, argv: R
rj(error);
});

countTokens = 0;
completionTokens = 0;
aiClient.createChatCompletion({
model: OpenAi.ChatCompletionModel.GPT_3_5_TURBO,
model,
messages: theContent,
temperature: argv.temperature as number,
maxTokens: argv.maxTokens as number,
@@ -52,25 +63,23 @@ const main = (argv: Argv) => new Promise<number>(async (resolve) => {
process.stdout.write('You can also send empty messages to exit.\n');
process.stdout.write('Alternatively, you can press Ctrl+C anytime to exit.\n\n');
do {
process.stdout.write('---\n\n');
process.stdout.write('--------\n\n');
const aiClient = createOpenAiClient({
apiKey: process.env.OPENAI_API_KEY as string,
organizationId: process.env.OPENAI_ORGANIZATION_ID as string,
apiVersion: OpenAi.ApiVersion.V1,
});
const { createPromptModule } = await import('inquirer');
const prompt = createPromptModule();
let content: string;
try {
const answers = await prompt([
{
type: 'input',
name: 'content',
prefix: '',
message: `${OpenAi.MessageRole.USER}:`,
const textPrompt = new TextPrompt({
render(): string | void {
return `${OpenAi.MessageRole.USER}:\n${this.valueWithCursor ?? ''}`;
},
]);
content = answers.content;
});
const contentRaw = await textPrompt.prompt();
if (isCancel(contentRaw)) {
done = true;
}
const content = contentRaw as string;
if (content.trim().length < 1) {
done = true;
break;
@@ -83,7 +92,7 @@ const main = (argv: Argv) => new Promise<number>(async (resolve) => {
}
} while (!done);

process.stdout.write('Bye!\n');
process.stdout.write('Bye!\n\n');
resolve(resolveResult);
});



+ 13
- 118
examples/cli/yarn.lock 查看文件

@@ -233,6 +233,14 @@
"@babel/helper-validator-identifier" "^7.19.1"
to-fast-properties "^2.0.0"
"@clack/core@^0.3.2":
version "0.3.2"
resolved "https://js.pack.modal.sh/@clack%2fcore/-/core-0.3.2.tgz#23c6e440ed263c2f012b1cc0806386481e78420b"
integrity sha512-FZnsNynwGDIDktx6PEZK1EuCkFpY4ldEX6VYvfl0dqeoLPb9Jpw1xoUXaVcGR8ExmYNm1w2vdGdJkEUYD/2pqg==
dependencies:
picocolors "^1.0.0"
sisteransi "^1.0.5"
"@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"
@@ -704,13 +712,6 @@ ajv@^6.10.0, ajv@^6.12.4:
json-schema-traverse "^0.4.1"
uri-js "^4.2.2"
ansi-escapes@^6.0.0:
version "6.1.0"
resolved "https://registry.yarnpkg.com/ansi-escapes/-/ansi-escapes-6.1.0.tgz#f2912cdaa10785f3f51f4b562a2497b885aadc5e"
integrity sha512-bQyg9bzRntwR/8b89DOEhGwctcwCrbWW/TuqTQnpqpy5Fz3aovcOTj5i8NJV6AHc8OGNdMaqdxAWww8pz2kiKg==
dependencies:
type-fest "^3.0.0"
ansi-regex@^5.0.1:
version "5.0.1"
resolved "https://registry.yarnpkg.com/ansi-regex/-/ansi-regex-5.0.1.tgz#082cb2c89c9fe8659a311a53bd6a4dc5301db304"
@@ -740,7 +741,7 @@ ansi-styles@^5.0.0:
resolved "https://registry.yarnpkg.com/ansi-styles/-/ansi-styles-5.2.0.tgz#07449690ad45777d1924ac2abb2fc8895dba836b"
integrity sha512-Cxwpt2SfTzTtXcfOlzGEee8O+c+MmUgGrNiBcXnuWxuFJHe6a5Hz7qwhwe5OgaSYI0IJvkLqWX1ASG+cJOkEiA==
ansi-styles@^6.0.0, ansi-styles@^6.1.0:
ansi-styles@^6.0.0:
version "6.2.1"
resolved "https://registry.yarnpkg.com/ansi-styles/-/ansi-styles-6.2.1.tgz#0e62320cf99c21afff3b3012192546aacbfb05c5"
integrity sha512-bN798gFfQX+viw3R7yrGWRqnrN2oRkEkUjjl4JNn4E8GxxbjtG3FbrEIIY3l8/hrwUwIeCZvi4QuOTP4MErVug==
@@ -966,16 +967,11 @@ chalk@^4.0.0:
ansi-styles "^4.1.0"
supports-color "^7.1.0"
chalk@^5.0.0, chalk@^5.2.0:
chalk@^5.0.0:
version "5.2.0"
resolved "https://registry.yarnpkg.com/chalk/-/chalk-5.2.0.tgz#249623b7d66869c673699fb66d65723e54dfcfb3"
integrity sha512-ree3Gqw/nazQAPuJJEy+avdl7QfZMcUvmHIKgEZkGL+xOBzRvup5Hxo6LHuMceSxOabuJLJm5Yp/92R9eMmMvA==
chardet@^0.7.0:
version "0.7.0"
resolved "https://registry.yarnpkg.com/chardet/-/chardet-0.7.0.tgz#90094849f0937f2eedc2425d0d28a9e5f0cbad9e"
integrity sha512-mT8iDcrh03qDGRRmoA2hmBJnxpllMR+0/0qlzjqZES6NdiWDcZkCNAk4rPFZ9Q85r27unkiNNg8ZOiwZXBHwcA==
check-error@^1.0.2:
version "1.0.2"
resolved "https://registry.yarnpkg.com/check-error/-/check-error-1.0.2.tgz#574d312edd88bb5dd8912e9286dd6c0aed4aac82"
@@ -1001,11 +997,6 @@ cli-truncate@^3.1.0:
slice-ansi "^5.0.0"
string-width "^5.0.0"
cli-width@^4.0.0:
version "4.0.0"
resolved "https://registry.yarnpkg.com/cli-width/-/cli-width-4.0.0.tgz#a5622f6a3b0a9e3e711a25f099bf2399f608caf6"
integrity sha512-ZksGS2xpa/bYkNzN3BAw1wEjsLV/ZKOf/CCrJ/QOBsxx6fOARIkwTutxp1XIOIohi6HKmOFjMoK/XaqDVUpEEw==
cliui@^6.0.0:
version "6.0.0"
resolved "https://registry.yarnpkg.com/cliui/-/cliui-6.0.0.tgz#511d702c0c4e41ca156d7d0e96021f23e13225b1"
@@ -1382,11 +1373,6 @@ escape-string-regexp@^4.0.0:
resolved "https://registry.yarnpkg.com/escape-string-regexp/-/escape-string-regexp-4.0.0.tgz#14ba83a5d373e3d311e5afca29cf5bfad965bf34"
integrity sha512-TtpcNJ3XAzx3Gq8sWRzJaVajRs0uVxA2YAkdb1jm2YkPz4G6egUFAyA3n5vtEIZefPk5Wa4UXbKuS5fKkJWdgA==
escape-string-regexp@^5.0.0:
version "5.0.0"
resolved "https://registry.yarnpkg.com/escape-string-regexp/-/escape-string-regexp-5.0.0.tgz#4683126b500b61762f2dbebace1806e8be31b1c8"
integrity sha512-/veY75JbMK4j1yjvuUxuVsiS/hr/4iHs9FTT6cgTexxdE0Ly/glccBAkloH/DofkjRbZU3bnoj38mOmhkZ0lHw==
eslint-config-airbnb-base@^15.0.0:
version "15.0.0"
resolved "https://registry.yarnpkg.com/eslint-config-airbnb-base/-/eslint-config-airbnb-base-15.0.0.tgz#6b09add90ac79c2f8d723a2580e07f3925afd236"
@@ -1698,15 +1684,6 @@ execa@^5.1.1:
signal-exit "^3.0.3"
strip-final-newline "^2.0.0"
external-editor@^3.0.3:
version "3.1.0"
resolved "https://registry.yarnpkg.com/external-editor/-/external-editor-3.1.0.tgz#cb03f740befae03ea4d283caed2741a83f335495"
integrity sha512-hMQ4CX1p1izmuLYyZqLMO/qGNw10wSv9QDCPfzXfyFrOaCSSoRfqE1Kf1s5an66J5JZC62NewG+mK49jOCtQew==
dependencies:
chardet "^0.7.0"
iconv-lite "^0.4.24"
tmp "^0.0.33"
fast-deep-equal@^3.1.1, fast-deep-equal@^3.1.3:
version "3.1.3"
resolved "https://registry.yarnpkg.com/fast-deep-equal/-/fast-deep-equal-3.1.3.tgz#3a7d56b559d6cbc3eb512325244e619a65c6c525"
@@ -1747,14 +1724,6 @@ fetch-ponyfill@^7.1.0:
dependencies:
node-fetch "~2.6.1"
figures@^5.0.0:
version "5.0.0"
resolved "https://registry.yarnpkg.com/figures/-/figures-5.0.0.tgz#126cd055052dea699f8a54e8c9450e6ecfc44d5f"
integrity sha512-ej8ksPF4x6e5wvK9yevct0UCXh8TTFlWGVLlgjZuoBH1HwjIfKE/IdL5mq89sFA7zELi1VhKpmtDnrs7zWyeyg==
dependencies:
escape-string-regexp "^5.0.0"
is-unicode-supported "^1.2.0"
file-entry-cache@^6.0.1:
version "6.0.1"
resolved "https://registry.yarnpkg.com/file-entry-cache/-/file-entry-cache-6.0.1.tgz#211b2dd9659cb0394b073e7323ac3c933d522027"
@@ -2057,13 +2026,6 @@ human-signals@^2.1.0:
resolved "https://registry.yarnpkg.com/human-signals/-/human-signals-2.1.0.tgz#dc91fcba42e4d06e4abaed33b3e7a3c02f514ea0"
integrity sha512-B4FFZ6q/T2jhhksgkbEW3HBvWIfDW85snkQgawt07S7J5QXTk6BkNV+0yAeZrM5QpMAdYlocGoljn0sJ/WQkFw==
iconv-lite@^0.4.24:
version "0.4.24"
resolved "https://registry.yarnpkg.com/iconv-lite/-/iconv-lite-0.4.24.tgz#2022b4b25fbddc21d2f524974a474aafe733908b"
integrity sha512-v3MXnZAcvnywkTUEZomIActle7RXXeedOR31wwl7VlyoXO4Qi9arvSenNQWne1TcRwhCL1HwLI21bEqdpj8/rA==
dependencies:
safer-buffer ">= 2.1.2 < 3"
ieee754@^1.2.1:
version "1.2.1"
resolved "https://registry.yarnpkg.com/ieee754/-/ieee754-1.2.1.tgz#8eb7a10a63fff25d15a57b001586d177d1b0d352"
@@ -2105,27 +2067,6 @@ ini@^1.3.5:
resolved "https://registry.yarnpkg.com/ini/-/ini-1.3.8.tgz#a29da425b48806f34767a4efce397269af28432c"
integrity sha512-JV/yugV2uzW5iMRSiZAyDtQd+nxtUnjeLt0acNdw98kKLrvuRVyB80tsREOE7yvGVgalhZ6RNXCmEHkUKBKxew==
inquirer@^9.1.5:
version "9.1.5"
resolved "https://registry.yarnpkg.com/inquirer/-/inquirer-9.1.5.tgz#2aa48cd3ab76b2d759c86756023dfb107cbb7d45"
integrity sha512-3ygAIh8gcZavV9bj6MTdYddG2zPSYswP808fKS46NOwlF0zZljVpnLCHODDqItWJDbDpLb3aouAxGaJbkxoppA==
dependencies:
ansi-escapes "^6.0.0"
chalk "^5.2.0"
cli-cursor "^4.0.0"
cli-width "^4.0.0"
external-editor "^3.0.3"
figures "^5.0.0"
lodash "^4.17.21"
mute-stream "1.0.0"
ora "^6.1.2"
run-async "^2.4.0"
rxjs "^7.8.0"
string-width "^5.1.2"
strip-ansi "^7.0.1"
through "^2.3.6"
wrap-ansi "^8.1.0"
internal-slot@^1.0.3, internal-slot@^1.0.4, internal-slot@^1.0.5:
version "1.0.5"
resolved "https://registry.yarnpkg.com/internal-slot/-/internal-slot-1.0.5.tgz#f2a2ee21f668f8627a4667f309dc0f4fb6674986"
@@ -2305,7 +2246,7 @@ is-typedarray@^1.0.0:
resolved "https://registry.yarnpkg.com/is-typedarray/-/is-typedarray-1.0.0.tgz#e479c80858df0c1b11ddda6940f96011fcda4a9a"
integrity sha512-cyA56iCMHAh5CdzjJIa4aohJyeO1YbwLi3Jc35MmRU6poroFjIGZzUzupGiRPOjgHg9TLu43xbpwXk523fMxKA==
is-unicode-supported@^1.1.0, is-unicode-supported@^1.2.0:
is-unicode-supported@^1.1.0:
version "1.3.0"
resolved "https://registry.yarnpkg.com/is-unicode-supported/-/is-unicode-supported-1.3.0.tgz#d824984b616c292a2e198207d4a609983842f714"
integrity sha512-43r2mRvz+8JRIKnWJ+3j8JtjRKZ6GmjzfaE/qiBJnikNnYv/6bagRJ1kUhNk8R5EX/GkobD+r+sfxCPJsiKBLQ==
@@ -2576,11 +2517,6 @@ ms@^2.1.1:
resolved "https://registry.yarnpkg.com/ms/-/ms-2.1.3.tgz#574c8138ce1d2b5861f0b44579dbadd60c6615b2"
integrity sha512-6FlzubTLZG3J2a/NVCAleEhjzq5oxgHyaCU9yYXvcLsvoVaHJq/s5xXI6/XXP6tz7R9xAOtHnSO/tXtF3WRTlA==
mute-stream@1.0.0:
version "1.0.0"
resolved "https://registry.yarnpkg.com/mute-stream/-/mute-stream-1.0.0.tgz#e31bd9fe62f0aed23520aa4324ea6671531e013e"
integrity sha512-avsJQhyd+680gKXyG/sQc0nXaC6rBkPOfyHYcFb9+hdkqQkR9bdnkJ0AMZhke0oesPqIO+mFFJ+IdBc7mst4IA==
nanoid@^3.3.6:
version "3.3.6"
resolved "https://registry.yarnpkg.com/nanoid/-/nanoid-3.3.6.tgz#443380c856d6e9f9824267d960b4236ad583ea4c"
@@ -2745,11 +2681,6 @@ ora@^6.1.2:
strip-ansi "^7.0.1"
wcwidth "^1.0.1"
os-tmpdir@~1.0.2:
version "1.0.2"
resolved "https://registry.yarnpkg.com/os-tmpdir/-/os-tmpdir-1.0.2.tgz#bbe67406c79aa85c5cfec766fe5734555dfa1274"
integrity sha512-D2FR03Vir7FIu45XBY20mTb+/ZSWB00sjU9jdQXt83gDrI4Ztz5Fs7/yy74g2N5SVQY4xY1qDr4rNddwYRVX0g==
p-limit@^2.2.0:
version "2.3.0"
resolved "https://registry.yarnpkg.com/p-limit/-/p-limit-2.3.0.tgz#3dd33c647a214fdfffd835933eb086da0dc21db1"
@@ -3037,11 +2968,6 @@ rollup@^3.18.0:
optionalDependencies:
fsevents "~2.3.2"
run-async@^2.4.0:
version "2.4.1"
resolved "https://registry.yarnpkg.com/run-async/-/run-async-2.4.1.tgz#8440eccf99ea3e70bd409d49aab88e10c189a455"
integrity sha512-tvVnVv01b8c1RrA6Ep7JkStj85Guv/YrMcwqYQnwjsAS2cTmmPGBBjAjpCW7RrSodNSoE2/qg9O4bceNvUuDgQ==
run-parallel@^1.1.9:
version "1.2.0"
resolved "https://registry.yarnpkg.com/run-parallel/-/run-parallel-1.2.0.tgz#66d1368da7bdf921eb9d95bd1a9229e7f21a43ee"
@@ -3049,7 +2975,7 @@ run-parallel@^1.1.9:
dependencies:
queue-microtask "^1.2.2"
rxjs@^7.2.0, rxjs@^7.8.0:
rxjs@^7.2.0:
version "7.8.0"
resolved "https://registry.yarnpkg.com/rxjs/-/rxjs-7.8.0.tgz#90a938862a82888ff4c7359811a595e14e1e09a4"
integrity sha512-F2+gxDshqmIub1KdvZkaEfGDwLNpPvk9Fs6LD/MyQxNgMds/WH9OdDDXOmxUZpME+iSK3rQCctkL0DYyytUqMg==
@@ -3070,11 +2996,6 @@ safe-regex-test@^1.0.0:
get-intrinsic "^1.1.3"
is-regex "^1.1.4"
"safer-buffer@>= 2.1.2 < 3":
version "2.1.2"
resolved "https://registry.yarnpkg.com/safer-buffer/-/safer-buffer-2.1.2.tgz#44fa161b0187b9549dd84bb91802f9bd8385cd6a"
integrity sha512-YZo3K82SD7Riyi0E1EQPojLz7kpepnSQI9IyPbHHg1XXXevb5dJI7tpyN2ADxGcQbHG7vcyRHk0cbwqcQriUtg==
semver@7.3.8:
version "7.3.8"
resolved "https://registry.yarnpkg.com/semver/-/semver-7.3.8.tgz#07a78feafb3f7b32347d725e33de7e2a2df67798"
@@ -3204,7 +3125,7 @@ string-width@^4.1.0, string-width@^4.2.0, string-width@^4.2.3:
is-fullwidth-code-point "^3.0.0"
strip-ansi "^6.0.1"
string-width@^5.0.0, string-width@^5.0.1, string-width@^5.1.2:
string-width@^5.0.0:
version "5.1.2"
resolved "https://registry.yarnpkg.com/string-width/-/string-width-5.1.2.tgz#14f8daec6d81e7221d2a357e668cab73bdbca794"
integrity sha512-HnLOCR3vjcY8beoNLtcjZ5/nxn2afmME6lhrDrebokqMap+XbeW8n9TXpPDOqdGK5qcI3oT0GKTW6wC7EMiVqA==
@@ -3334,11 +3255,6 @@ text-table@^0.2.0:
resolved "https://registry.yarnpkg.com/text-table/-/text-table-0.2.0.tgz#7f5ee823ae805207c00af2df4a84ec3fcfa570b4"
integrity sha512-N+8UisAXDGk8PFXP4HAzVR9nbfmVJ3zYLAWiTIoqC5v5isinhr+r5uaO8+7r3BMfuNIufIsA7RdpVgacC2cSpw==
through@^2.3.6:
version "2.3.8"
resolved "https://registry.yarnpkg.com/through/-/through-2.3.8.tgz#0dd4c9ffaabc357960b1b724115d7e0e86a2e1f5"
integrity sha512-w89qg7PI8wAdvX60bMDP+bFoD5Dvhm9oLheFp5O4a2QF0cSBGsBX4qZmadPMvVqlLJBBci+WqGGOAPvcDeNSVg==
tiny-glob@^0.2.9:
version "0.2.9"
resolved "https://registry.yarnpkg.com/tiny-glob/-/tiny-glob-0.2.9.tgz#2212d441ac17928033b110f8b3640683129d31e2"
@@ -3362,13 +3278,6 @@ tinyspy@^1.0.2:
resolved "https://registry.yarnpkg.com/tinyspy/-/tinyspy-1.1.1.tgz#0cb91d5157892af38cb2d217f5c7e8507a5bf092"
integrity sha512-UVq5AXt/gQlti7oxoIg5oi/9r0WpF7DGEVwXgqWSMmyN16+e3tl5lIvTaOpJ3TAtu5xFzWccFRM4R5NaWHF+4g==
tmp@^0.0.33:
version "0.0.33"
resolved "https://registry.yarnpkg.com/tmp/-/tmp-0.0.33.tgz#6d34335889768d21b2bcda0aa277ced3b1bfadf9"
integrity sha512-jRCJlojKnZ3addtTOjdIqoRuPEKBvNXcGYqzO6zWZX8KfKEpnGY5jfggJQ3EjKuu8D4bJRr0y+cYJFmYbImXGw==
dependencies:
os-tmpdir "~1.0.2"
to-fast-properties@^2.0.0:
version "2.0.0"
resolved "https://registry.yarnpkg.com/to-fast-properties/-/to-fast-properties-2.0.0.tgz#dc5e698cbd079265bc73e0377681a4e4e83f616e"
@@ -3430,11 +3339,6 @@ type-fest@^0.20.2:
resolved "https://registry.yarnpkg.com/type-fest/-/type-fest-0.20.2.tgz#1bf207f4b28f91583666cb5fbd327887301cd5f4"
integrity sha512-Ne+eE4r0/iWnpAxD852z3A+N0Bt5RN//NjJwRd2VFHEmrywxf5vsZlh4R6lixl6B+wz/8d+maTSAkN1FIkI3LQ==
type-fest@^3.0.0:
version "3.8.0"
resolved "https://registry.yarnpkg.com/type-fest/-/type-fest-3.8.0.tgz#ce80d1ca7c7d11c5540560999cbd410cb5b3a385"
integrity sha512-FVNSzGQz9Th+/9R6Lvv7WIAkstylfHN2/JYxkyhhmKFYh9At2DST8t6L6Lref9eYO8PXFTfG9Sg1Agg0K3vq3Q==
typed-array-length@^1.0.4:
version "1.0.4"
resolved "https://registry.yarnpkg.com/typed-array-length/-/typed-array-length-1.0.4.tgz#89d83785e5c4098bec72e08b319651f0eac9c1bb"
@@ -3673,15 +3577,6 @@ wrap-ansi@^7.0.0:
string-width "^4.1.0"
strip-ansi "^6.0.0"
wrap-ansi@^8.1.0:
version "8.1.0"
resolved "https://registry.yarnpkg.com/wrap-ansi/-/wrap-ansi-8.1.0.tgz#56dc22368ee570face1b49819975d9b9a5ead214"
integrity sha512-si7QWI6zUMq56bESFvagtmzMdGOtoxfR+Sez11Mobfc7tm+VkUckk9bW2UeffTGVUbOksxmSw0AA2gs8g71NCQ==
dependencies:
ansi-styles "^6.1.0"
string-width "^5.0.1"
strip-ansi "^7.0.1"
wrap-text@^1.0.8:
version "1.0.9"
resolved "https://registry.yarnpkg.com/wrap-text/-/wrap-text-1.0.9.tgz#0b4d7ba2c5e45dc92d0fab63d5c479ab1aff1f1a"


+ 3
- 1
src/platforms/openai/usage.ts 查看文件

@@ -43,7 +43,9 @@ export const getTokens = (chatTokens: string, model: TiktokenModel) => {
[SEPARATOR_TOKEN]: 100266,
})
: encodingForModel(model);
return enc.encode(chatTokens, 'all');
const theTokens = enc.encode(chatTokens, 'all');
enc.free();
return theTokens;
};

export const getPromptTokens = (normalizedMessageArray: MessageObject[], model: TiktokenModel) => {


Loading…
取消
儲存