From f01d1d39985fe68e60ed9d3562c36eb18c529e07 Mon Sep 17 00:00:00 2001 From: ikechan8370 Date: Sat, 1 Jul 2023 16:36:51 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E4=BF=AE=E5=A4=8Dtoken=E8=AE=A1?= =?UTF-8?q?=E7=AE=97=E6=96=B9=E6=B3=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- utils/openai/chatgpt-api.js | 2 +- utils/openai/chatgpt-api.ts | 2 +- utils/openai/fetch-sse.js | 12 ++++++------ 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/utils/openai/chatgpt-api.js b/utils/openai/chatgpt-api.js index 3a90f87..0d2ec75 100644 --- a/utils/openai/chatgpt-api.js +++ b/utils/openai/chatgpt-api.js @@ -517,7 +517,7 @@ var ChatGPTAPI = /** @class */ (function () { return [3 /*break*/, 27]; } messages = nextMessages; - numTokens = nextNumTokensEstimate; + numTokens = nextNumTokensEstimate + functionToken; if (!isValidPrompt) { return [3 /*break*/, 27]; } diff --git a/utils/openai/chatgpt-api.ts b/utils/openai/chatgpt-api.ts index 9eb0691..4d0b342 100644 --- a/utils/openai/chatgpt-api.ts +++ b/utils/openai/chatgpt-api.ts @@ -477,7 +477,7 @@ export class ChatGPTAPI { break } messages = nextMessages - numTokens = nextNumTokensEstimate + numTokens = nextNumTokensEstimate + functionToken if (!isValidPrompt) { break diff --git a/utils/openai/fetch-sse.js b/utils/openai/fetch-sse.js index ca00317..a9d2358 100644 --- a/utils/openai/fetch-sse.js +++ b/utils/openai/fetch-sse.js @@ -53,19 +53,19 @@ var __asyncValues = (this && this.__asyncValues) || function (o) { function settle(resolve, reject, d, v) { Promise.resolve(v).then(function(v) { resolve({ value: v, done: d }); }, reject); } }; import { createParser } from 'eventsource-parser'; -import * as types from './types.js'; -import fetch from 'node-fetch'; -import { streamAsyncIterable } from './stream-async-iterable.js'; -export function fetchSSE(url, options, fetchFn) { +import * as types from './types'; +import { fetch as nodefetch } from 'node-fetch'; +import { streamAsyncIterable } from './stream-async-iterable'; +export function fetchSSE(url, options, fetch) { var _a, e_1, _b, _c; - if (fetchFn === void 0) { fetchFn = fetch; } + if (fetch === void 0) { fetch = nodefetch; } return __awaiter(this, void 0, void 0, function () { var onMessage, onError, fetchOptions, res, reason, err_1, msg, error, parser, feed, body_1, _d, _e, _f, chunk, str, e_1_1; return __generator(this, function (_g) { switch (_g.label) { case 0: onMessage = options.onMessage, onError = options.onError, fetchOptions = __rest(options, ["onMessage", "onError"]); - return [4 /*yield*/, fetchFn(url, fetchOptions)]; + return [4 /*yield*/, fetch(url, fetchOptions)]; case 1: res = _g.sent(); if (!!res.ok) return [3 /*break*/, 6];