Skip to content

Commit

Permalink
fix: 修复token计算方法
Browse files Browse the repository at this point in the history
  • Loading branch information
ikechan8370 committed Jul 1, 2023
1 parent a94017e commit f01d1d3
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 8 deletions.
2 changes: 1 addition & 1 deletion utils/openai/chatgpt-api.js
Original file line number Diff line number Diff line change
Expand Up @@ -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];
}
Expand Down
2 changes: 1 addition & 1 deletion utils/openai/chatgpt-api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -477,7 +477,7 @@ export class ChatGPTAPI {
break
}
messages = nextMessages
numTokens = nextNumTokensEstimate
numTokens = nextNumTokensEstimate + functionToken

if (!isValidPrompt) {
break
Expand Down
12 changes: 6 additions & 6 deletions utils/openai/fetch-sse.js
Original file line number Diff line number Diff line change
Expand Up @@ -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];
Expand Down

0 comments on commit f01d1d3

Please sign in to comment.