Single object is coming in 2 parts in 2 different chunks #653

Closed
opened 2026-02-21 17:27:54 -05:00 by yindo · 2 comments
Owner

Originally created by @Rohit3523 on GitHub (Nov 5, 2023).

Dify version

0.3.28

Cloud or Self Hosted

Self Hosted

Steps to reproduce

  1. Have some custom dataset
  2. Ask a question related to anything that is present in dataset
  3. Set the response mode to "Streaming"
  4. Listen to response

✔️ Expected Behavior

It should return full object in one chunk

Actual Behavior

It is giving half part of object in 1st chunk and rest part in another

 LOG  data: {"event": "message", "task_id": "209e2453-f2ab-4b99-a3b9-e6a0d0a5042c", "id": "50527dca-8
 LOG  be4-4555-b6be-f27a9b1b820a", "answer": ",", "created_at": 1699212290, "conversation_id": "bd5db6d2-7d05-4196-bfec-9d24462dc043"}
Originally created by @Rohit3523 on GitHub (Nov 5, 2023). ### Dify version 0.3.28 ### Cloud or Self Hosted Self Hosted ### Steps to reproduce 1. Have some custom dataset 2. Ask a question related to anything that is present in dataset 3. Set the response mode to "Streaming" 4. Listen to response ### ✔️ Expected Behavior It should return full object in one chunk ### ❌ Actual Behavior It is giving half part of object in 1st chunk and rest part in another ``` LOG data: {"event": "message", "task_id": "209e2453-f2ab-4b99-a3b9-e6a0d0a5042c", "id": "50527dca-8 LOG be4-4555-b6be-f27a9b1b820a", "answer": ",", "created_at": 1699212290, "conversation_id": "bd5db6d2-7d05-4196-bfec-9d24462dc043"} ```
yindo added the 🐞 bug label 2026-02-21 17:27:54 -05:00
yindo closed this issue 2026-02-21 17:27:54 -05:00
Author
Owner

@Rohit3523 commented on GitHub (Nov 5, 2023):

Here is my code

async function* streamAsyncIterable(stream) {
            const reader = stream.getReader()
            try {
              while (true) {
                const { done, value } = await reader.read()
                if (done) {
                  return
                }
                yield value
              }
            } finally {
              reader.releaseLock()
            }
        }

const res = await fetch("http://**************************/v1/chat-messages", {
                    method: "POST",
                    headers: {
                        'Authorization': 'Bearer app-*****',
                        'Content-Type': 'application/json'
                    },
                    body: JSON.stringify({
                        "inputs": {},
                        "query": text,
                        "response_mode": "streaming",
                        "conversation_id": conversationId,
                        "user": user
                    })
                });
                

                for await (const chunk of streamAsyncIterable(res.body)) {
                    const str = new TextDecoder().decode(chunk);
                    console.log(str)
                }```
@Rohit3523 commented on GitHub (Nov 5, 2023): Here is my code ``` async function* streamAsyncIterable(stream) { const reader = stream.getReader() try { while (true) { const { done, value } = await reader.read() if (done) { return } yield value } } finally { reader.releaseLock() } } const res = await fetch("http://**************************/v1/chat-messages", { method: "POST", headers: { 'Authorization': 'Bearer app-*****', 'Content-Type': 'application/json' }, body: JSON.stringify({ "inputs": {}, "query": text, "response_mode": "streaming", "conversation_id": conversationId, "user": user }) }); for await (const chunk of streamAsyncIterable(res.body)) { const str = new TextDecoder().decode(chunk); console.log(str) }```
Author
Owner

@crazywoola commented on GitHub (Nov 5, 2023):

See the streamParser in https://github.com/crazywoola/dify-bot/blob/main/src/util.ts

@crazywoola commented on GitHub (Nov 5, 2023): See the `streamParser` in https://github.com/crazywoola/dify-bot/blob/main/src/util.ts
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: langgenius/dify#653