Spaces:
Paused
Paused
djmuted
commited on
Commit
·
f406747
1
Parent(s):
830813f
Decode html entities
Browse files- package.json +1 -0
- src/openai.js +4 -2
- yarn.lock +5 -0
package.json
CHANGED
@@ -15,6 +15,7 @@
|
|
15 |
"express": "^4.18.2",
|
16 |
"express-bearer-token": "^2.4.0",
|
17 |
"form-data": "^4.0.0",
|
|
|
18 |
"uuid": "^9.0.0",
|
19 |
"ws": "^8.13.0",
|
20 |
"yup": "^1.1.1"
|
|
|
15 |
"express": "^4.18.2",
|
16 |
"express-bearer-token": "^2.4.0",
|
17 |
"form-data": "^4.0.0",
|
18 |
+
"html-entities": "^2.3.3",
|
19 |
"uuid": "^9.0.0",
|
20 |
"ws": "^8.13.0",
|
21 |
"yup": "^1.1.1"
|
src/openai.js
CHANGED
@@ -5,6 +5,7 @@ const slack = require('./slack');
|
|
5 |
const yup = require('yup');
|
6 |
const { splitJsonArray, dataToResponse, buildPrompt, wait, stats } = require("./utils");
|
7 |
const { Queue } = require('async-await-queue');
|
|
|
8 |
|
9 |
const messageArraySchema = yup.array().of(
|
10 |
yup.object().shape({
|
@@ -66,7 +67,8 @@ openaiRouter.post("/chat/completions", jsonParser, async (req, res) => {
|
|
66 |
let completionTokens = 0;
|
67 |
|
68 |
let lastContent = '';
|
69 |
-
const onData = (
|
|
|
70 |
if (stream) {
|
71 |
const data = newContent.slice(lastContent.length);
|
72 |
lastContent = newContent;
|
@@ -87,7 +89,7 @@ openaiRouter.post("/chat/completions", jsonParser, async (req, res) => {
|
|
87 |
const start = new Date();
|
88 |
await slack.sendChatReset(slackConfig);
|
89 |
await wait(500);
|
90 |
-
const response = await slack.waitForWebSocketResponse(slackConfig, messagesSplit, onData);
|
91 |
const end = new Date();
|
92 |
const time = end - start;
|
93 |
stats.prompts.push({ time, inputLength: inputPrompt.length, outputLength: response.length });
|
|
|
5 |
const yup = require('yup');
|
6 |
const { splitJsonArray, dataToResponse, buildPrompt, wait, stats } = require("./utils");
|
7 |
const { Queue } = require('async-await-queue');
|
8 |
+
const { encode, decode } = require('html-entities');
|
9 |
|
10 |
const messageArraySchema = yup.array().of(
|
11 |
yup.object().shape({
|
|
|
67 |
let completionTokens = 0;
|
68 |
|
69 |
let lastContent = '';
|
70 |
+
const onData = (newContentEncoded) => {
|
71 |
+
const newContent = decode(newContentEncoded)
|
72 |
if (stream) {
|
73 |
const data = newContent.slice(lastContent.length);
|
74 |
lastContent = newContent;
|
|
|
89 |
const start = new Date();
|
90 |
await slack.sendChatReset(slackConfig);
|
91 |
await wait(500);
|
92 |
+
const response = decode(await slack.waitForWebSocketResponse(slackConfig, messagesSplit, onData));
|
93 |
const end = new Date();
|
94 |
const time = end - start;
|
95 |
stats.prompts.push({ time, inputLength: inputPrompt.length, outputLength: response.length });
|
yarn.lock
CHANGED
@@ -285,6 +285,11 @@ has@^1.0.3:
|
|
285 |
dependencies:
|
286 |
function-bind "^1.1.1"
|
287 |
|
|
|
|
|
|
|
|
|
|
|
288 |
http-errors@2.0.0:
|
289 |
version "2.0.0"
|
290 |
resolved "https://registry.yarnpkg.com/http-errors/-/http-errors-2.0.0.tgz#b7774a1486ef73cf7667ac9ae0858c012c57b9d3"
|
|
|
285 |
dependencies:
|
286 |
function-bind "^1.1.1"
|
287 |
|
288 |
+
html-entities@^2.3.3:
|
289 |
+
version "2.3.3"
|
290 |
+
resolved "https://registry.yarnpkg.com/html-entities/-/html-entities-2.3.3.tgz#117d7626bece327fc8baace8868fa6f5ef856e46"
|
291 |
+
integrity sha512-DV5Ln36z34NNTDgnz0EWGBLZENelNAtkiFA4kyNOG2tDI6Mz1uSWiq1wAKdyjnJwyDiDO7Fa2SO1CTxPXL8VxA==
|
292 |
+
|
293 |
http-errors@2.0.0:
|
294 |
version "2.0.0"
|
295 |
resolved "https://registry.yarnpkg.com/http-errors/-/http-errors-2.0.0.tgz#b7774a1486ef73cf7667ac9ae0858c012c57b9d3"
|