+
106
-

claude 3.5 api http返回的流式数据返回的前面几行数据为啥无法用 chunk.split('\n')获取?

claude 3.5 api http返回的流式数据返回的前面几行数据为啥无法用 chunk.split('\n')获取?

后面返回的又是正常的。

event: message_start
data: {"type":"message_start","message":{"id":"msg_vrtx_01MxDXNPAx8Ahv8Rpi8XUGpX","type":"message","role":"assistant","model":"claude-3-5-sonnet-20240620","content":[],"stop_reason":null,"stop_sequence":null,"usage":{"input_tokens":839,"output_tokens":2}}  }

event: ping
data: {"type": "ping"}

event: content_block_start
data: {"type":"content_block_start","index":0,"content_block":{"type":"text","text":""}     }

event: content_block_delta
data: {"type":"content_block_delta","index":0,"delta":{"type":"text_delta","text":"根"}     }

event: content_block_delta
data: {"type":"content_block_delta","index":0,"delta":{"type":"text_delta","text":"据您提"}            }

event: content_block_delta
data: {"type":"content_block_delta","index":0,"delta":{"type":"text_delta","text":"供"}               }

event: content_block_delta
data: {"type":"content_block_delta","index":0,"delta":{"type":"text_delta","text":"的信"}            }


网友回复

+
4
-

claude的前几行也单独处理,我的解决方案代码如下:

点击查看全文

我知道答案,我要回答