Spaces:
Paused
Paused
djmuted
commited on
Commit
·
d899182
1
Parent(s):
1e956de
Fix response
Browse files- src/openai.js +8 -18
src/openai.js
CHANGED
@@ -58,22 +58,6 @@ openaiRouter.post("/chat/completions", jsonParser, async (req, res) => {
|
|
58 |
});
|
59 |
}
|
60 |
|
61 |
-
const generateResponse = (content) => {
|
62 |
-
return {
|
63 |
-
id, created,
|
64 |
-
object: 'chat.completion',
|
65 |
-
model: spoofModelName,
|
66 |
-
choices: [{
|
67 |
-
message: {
|
68 |
-
role: 'assistant',
|
69 |
-
content,
|
70 |
-
},
|
71 |
-
finish_reason: 'stop',
|
72 |
-
index: 0,
|
73 |
-
}]
|
74 |
-
};
|
75 |
-
}
|
76 |
-
|
77 |
const promptTokens = Math.ceil(buildPrompt(messages).length / 4);
|
78 |
let completionTokens = 0;
|
79 |
|
@@ -91,7 +75,7 @@ openaiRouter.post("/chat/completions", jsonParser, async (req, res) => {
|
|
91 |
|
92 |
const result = await myq.run(async () => {
|
93 |
await slack.sendChatReset();
|
94 |
-
await slack.waitForWebSocketResponse(messagesSplit, onData);
|
95 |
});
|
96 |
|
97 |
if (stream) {
|
@@ -110,7 +94,13 @@ openaiRouter.post("/chat/completions", jsonParser, async (req, res) => {
|
|
110 |
res.write('event: data\n');
|
111 |
res.write('data: [DONE]\n\n');
|
112 |
} else {
|
113 |
-
res.json(
|
|
|
|
|
|
|
|
|
|
|
|
|
114 |
}
|
115 |
} catch (error) {
|
116 |
console.error(error);
|
|
|
58 |
});
|
59 |
}
|
60 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
61 |
const promptTokens = Math.ceil(buildPrompt(messages).length / 4);
|
62 |
let completionTokens = 0;
|
63 |
|
|
|
75 |
|
76 |
const result = await myq.run(async () => {
|
77 |
await slack.sendChatReset();
|
78 |
+
return await slack.waitForWebSocketResponse(messagesSplit, onData);
|
79 |
});
|
80 |
|
81 |
if (stream) {
|
|
|
94 |
res.write('event: data\n');
|
95 |
res.write('data: [DONE]\n\n');
|
96 |
} else {
|
97 |
+
res.json(dataToResponse(
|
98 |
+
result,
|
99 |
+
promptTokens,
|
100 |
+
completionTokens,
|
101 |
+
stream,
|
102 |
+
'stop'
|
103 |
+
));
|
104 |
}
|
105 |
} catch (error) {
|
106 |
console.error(error);
|