@longline/aqua-ui 1.0.204 → 1.0.205
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -69,10 +69,10 @@ var useOpenAIStream = function (url) {
|
|
|
69
69
|
}
|
|
70
70
|
return __awaiter(void 0, __spreadArray([prompt_1, onText_1], args_1, true), void 0, function (prompt, onText, options) {
|
|
71
71
|
var controller, response, reader, decoder, buffer, isDone, _a, done, value, parts, _b, parts_1, part, jsonStr, data, content, err_1;
|
|
72
|
-
var _c, _d, _e
|
|
72
|
+
var _c, _d, _e;
|
|
73
73
|
if (options === void 0) { options = { temperature: 0, top_p: 0 }; }
|
|
74
|
-
return __generator(this, function (
|
|
75
|
-
switch (
|
|
74
|
+
return __generator(this, function (_f) {
|
|
75
|
+
switch (_f.label) {
|
|
76
76
|
case 0:
|
|
77
77
|
controller = new AbortController();
|
|
78
78
|
abortRef.current = controller;
|
|
@@ -80,7 +80,7 @@ var useOpenAIStream = function (url) {
|
|
|
80
80
|
method: 'POST',
|
|
81
81
|
headers: {
|
|
82
82
|
'Content-Type': 'application/json',
|
|
83
|
-
'X-XSRF-TOKEN':
|
|
83
|
+
//'X-XSRF-TOKEN': getCsrfTokenFromCookie() ?? '',
|
|
84
84
|
'Accept': 'text/event-stream',
|
|
85
85
|
'Connection': 'keep-alive',
|
|
86
86
|
'Cache-Control': 'no-cache, no-transform'
|
|
@@ -90,11 +90,11 @@ var useOpenAIStream = function (url) {
|
|
|
90
90
|
temperature: options.temperature || 0,
|
|
91
91
|
top_p: options.top_p || 0
|
|
92
92
|
}),
|
|
93
|
-
credentials: 'include',
|
|
93
|
+
//credentials: 'include',
|
|
94
94
|
signal: controller.signal
|
|
95
95
|
})];
|
|
96
96
|
case 1:
|
|
97
|
-
response =
|
|
97
|
+
response = _f.sent();
|
|
98
98
|
if (!response.ok) {
|
|
99
99
|
console.error("OpenAI stream request failed: ".concat(response.statusText));
|
|
100
100
|
return [2 /*return*/];
|
|
@@ -107,19 +107,19 @@ var useOpenAIStream = function (url) {
|
|
|
107
107
|
decoder = new TextDecoder('utf-8');
|
|
108
108
|
buffer = '';
|
|
109
109
|
isDone = false;
|
|
110
|
-
|
|
110
|
+
_f.label = 2;
|
|
111
111
|
case 2:
|
|
112
112
|
if (!!isDone) return [3 /*break*/, 11];
|
|
113
113
|
return [4 /*yield*/, reader.read()];
|
|
114
114
|
case 3:
|
|
115
|
-
_a =
|
|
115
|
+
_a = _f.sent(), done = _a.done, value = _a.value;
|
|
116
116
|
if (done)
|
|
117
117
|
return [3 /*break*/, 11];
|
|
118
118
|
buffer += decoder.decode(value, { stream: true });
|
|
119
119
|
parts = buffer.split('\n\n');
|
|
120
120
|
buffer = parts.pop(); // Keep partial data for next chunk
|
|
121
121
|
_b = 0, parts_1 = parts;
|
|
122
|
-
|
|
122
|
+
_f.label = 4;
|
|
123
123
|
case 4:
|
|
124
124
|
if (!(_b < parts_1.length)) return [3 /*break*/, 10];
|
|
125
125
|
part = parts_1[_b];
|
|
@@ -129,19 +129,19 @@ var useOpenAIStream = function (url) {
|
|
|
129
129
|
isDone = true;
|
|
130
130
|
return [3 /*break*/, 10];
|
|
131
131
|
}
|
|
132
|
-
|
|
132
|
+
_f.label = 5;
|
|
133
133
|
case 5:
|
|
134
|
-
|
|
134
|
+
_f.trys.push([5, 8, , 9]);
|
|
135
135
|
data = JSON.parse(jsonStr);
|
|
136
|
-
content = (
|
|
136
|
+
content = (_e = (_d = (_c = data.choices) === null || _c === void 0 ? void 0 : _c[0]) === null || _d === void 0 ? void 0 : _d.delta) === null || _e === void 0 ? void 0 : _e.content;
|
|
137
137
|
if (!content) return [3 /*break*/, 7];
|
|
138
138
|
return [4 /*yield*/, onText(content)];
|
|
139
139
|
case 6:
|
|
140
|
-
|
|
141
|
-
|
|
140
|
+
_f.sent();
|
|
141
|
+
_f.label = 7;
|
|
142
142
|
case 7: return [3 /*break*/, 9];
|
|
143
143
|
case 8:
|
|
144
|
-
err_1 =
|
|
144
|
+
err_1 = _f.sent();
|
|
145
145
|
console.error('Failed to parse chunk:', jsonStr);
|
|
146
146
|
return [3 /*break*/, 9];
|
|
147
147
|
case 9:
|