mirror of
https://github.com/sune-org/ORP.git
synced 2026-01-13 16:17:59 +00:00
Revert: Update index.js
This commit is contained in:
12
index.js
12
index.js
@@ -333,24 +333,24 @@ export class MyDurableObject {
|
|||||||
const client = new OpenRouter({ apiKey, defaultHeaders: { 'HTTP-Referer': 'https://sune.chat', 'X-Title': 'Sune' } });
|
const client = new OpenRouter({ apiKey, defaultHeaders: { 'HTTP-Referer': 'https://sune.chat', 'X-Title': 'Sune' } });
|
||||||
const stream = await client.chat.send({ ...body, stream: true });
|
const stream = await client.chat.send({ ...body, stream: true });
|
||||||
let hasReasoning = false, hasContent = false;
|
let hasReasoning = false, hasContent = false;
|
||||||
const collectedImages = [];
|
|
||||||
for await (const chunk of stream) {
|
for await (const chunk of stream) {
|
||||||
if (this.phase !== 'running') break;
|
if (this.phase !== 'running') break;
|
||||||
const delta = chunk?.choices?.[0]?.delta;
|
const delta = chunk?.choices?.[0]?.delta;
|
||||||
if (!delta) continue;
|
const images = delta?.images;
|
||||||
|
|
||||||
if (delta.reasoning && body.reasoning?.exclude !== true) {
|
if (delta?.reasoning && body.reasoning?.exclude !== true) {
|
||||||
this.queueDelta(delta.reasoning);
|
this.queueDelta(delta.reasoning);
|
||||||
hasReasoning = true;
|
hasReasoning = true;
|
||||||
}
|
}
|
||||||
if (delta.content) {
|
if (delta?.content) {
|
||||||
if (hasReasoning && !hasContent) this.queueDelta('\n');
|
if (hasReasoning && !hasContent) this.queueDelta('\n');
|
||||||
this.queueDelta(delta.content);
|
this.queueDelta(delta.content);
|
||||||
hasContent = true;
|
hasContent = true;
|
||||||
}
|
}
|
||||||
if (Array.isArray(delta.images)) collectedImages.push(...delta.images);
|
if (images) {
|
||||||
|
this.queueDelta('', images);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if (collectedImages.length) this.queueDelta('', collectedImages);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
stop() {
|
stop() {
|
||||||
|
|||||||
Reference in New Issue
Block a user