Spaces:
Paused
Paused
matt HOFFNER
commited on
Commit
·
284c9cc
1
Parent(s):
888d022
debug
Browse files- src/pages/api/stream.js +5 -16
src/pages/api/stream.js
CHANGED
@@ -25,7 +25,7 @@ export const LLMStream = async (
|
|
25 |
headers: {
|
26 |
'Content-Type': 'application/json',
|
27 |
...(OPENAI_API_TYPE === 'openai' && {
|
28 |
-
Authorization: `Bearer ${
|
29 |
})
|
30 |
},
|
31 |
method: 'POST',
|
@@ -69,6 +69,7 @@ export const LLMStream = async (
|
|
69 |
async start(controller) {
|
70 |
const onParse = async (event) => {
|
71 |
if (event.type === 'event') {
|
|
|
72 |
const data = event.data;
|
73 |
|
74 |
try {
|
@@ -86,25 +87,13 @@ export const LLMStream = async (
|
|
86 |
console.log(`Function call: ${fnName}, Arguments: ${args}`);
|
87 |
console.log(`Calling Function ${fnName} Result: ` + result);
|
88 |
|
89 |
-
|
90 |
-
|
91 |
-
content: "",
|
92 |
-
function_call: {
|
93 |
-
name: fnName,
|
94 |
-
arguments: args,
|
95 |
-
},
|
96 |
-
});
|
97 |
-
|
98 |
-
messages.push({
|
99 |
-
role: "function",
|
100 |
-
name: fnName,
|
101 |
-
content: JSON.stringify({ result: result }),
|
102 |
-
});
|
103 |
-
}
|
104 |
const text = json.choices[0].delta.content;
|
105 |
const queue = encoder.encode(text);
|
106 |
controller.enqueue(queue);
|
107 |
} catch (e) {
|
|
|
108 |
controller.error(e);
|
109 |
}
|
110 |
}
|
|
|
25 |
headers: {
|
26 |
'Content-Type': 'application/json',
|
27 |
...(OPENAI_API_TYPE === 'openai' && {
|
28 |
+
Authorization: `Bearer ${process.env.OPENAI_API_KEY}`
|
29 |
})
|
30 |
},
|
31 |
method: 'POST',
|
|
|
69 |
async start(controller) {
|
70 |
const onParse = async (event) => {
|
71 |
if (event.type === 'event') {
|
72 |
+
console.log(event);
|
73 |
const data = event.data;
|
74 |
|
75 |
try {
|
|
|
87 |
console.log(`Function call: ${fnName}, Arguments: ${args}`);
|
88 |
console.log(`Calling Function ${fnName} Result: ` + result);
|
89 |
|
90 |
+
|
91 |
+
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
92 |
const text = json.choices[0].delta.content;
|
93 |
const queue = encoder.encode(text);
|
94 |
controller.enqueue(queue);
|
95 |
} catch (e) {
|
96 |
+
console.log(e);
|
97 |
controller.error(e);
|
98 |
}
|
99 |
}
|