@nhonh/qabot 0.3.0 → 0.3.1
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.
- package/package.json +1 -1
- package/src/ai/ai-engine.js +25 -6
- package/src/core/constants.js +1 -1
package/package.json
CHANGED
package/src/ai/ai-engine.js
CHANGED
|
@@ -117,6 +117,7 @@ export class AIEngine {
|
|
|
117
117
|
messages: [{ role: "user", content: prompt }],
|
|
118
118
|
temperature: this.temperature,
|
|
119
119
|
max_tokens: this.maxTokens,
|
|
120
|
+
stream: false,
|
|
120
121
|
}),
|
|
121
122
|
});
|
|
122
123
|
if (!res.ok) {
|
|
@@ -195,24 +196,42 @@ export class AIEngine {
|
|
|
195
196
|
|
|
196
197
|
const headers = this.buildAuthHeaders();
|
|
197
198
|
|
|
198
|
-
const
|
|
199
|
+
const reqBody = {
|
|
199
200
|
messages: [{ role: "user", content: prompt }],
|
|
200
201
|
temperature: this.temperature,
|
|
201
202
|
max_tokens: this.maxTokens,
|
|
203
|
+
stream: false,
|
|
202
204
|
};
|
|
203
|
-
if (this.model)
|
|
205
|
+
if (this.model) reqBody.model = this.model;
|
|
204
206
|
|
|
205
207
|
const res = await fetch(this.baseUrl, {
|
|
206
208
|
method: "POST",
|
|
207
209
|
headers,
|
|
208
|
-
body: JSON.stringify(
|
|
210
|
+
body: JSON.stringify(reqBody),
|
|
209
211
|
});
|
|
210
212
|
if (!res.ok) {
|
|
211
|
-
const
|
|
212
|
-
throw new Error(`Proxy API error (${res.status}): ${
|
|
213
|
+
const errText = await res.text().catch(() => "");
|
|
214
|
+
throw new Error(`Proxy API error (${res.status}): ${errText}`);
|
|
213
215
|
}
|
|
214
216
|
|
|
215
|
-
const
|
|
217
|
+
const rawText = await res.text();
|
|
218
|
+
let data;
|
|
219
|
+
try {
|
|
220
|
+
data = JSON.parse(rawText);
|
|
221
|
+
} catch {
|
|
222
|
+
const jsonLine = rawText
|
|
223
|
+
.split("\n")
|
|
224
|
+
.find((l) => l.startsWith("data: ") && !l.includes("[DONE]"));
|
|
225
|
+
if (jsonLine) {
|
|
226
|
+
data = JSON.parse(jsonLine.slice(6));
|
|
227
|
+
if (data.choices?.[0]?.delta?.content) {
|
|
228
|
+
return data.choices[0].delta.content;
|
|
229
|
+
}
|
|
230
|
+
}
|
|
231
|
+
throw new Error(
|
|
232
|
+
`Proxy returned non-JSON response. First 200 chars: ${rawText.slice(0, 200)}`,
|
|
233
|
+
);
|
|
234
|
+
}
|
|
216
235
|
|
|
217
236
|
if (data.choices?.[0]?.message?.content)
|
|
218
237
|
return data.choices[0].message.content;
|
package/src/core/constants.js
CHANGED