You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Bot detected the issue body's language is not English, translate it automatically. 👯👭🏻🧑🤝🧑👫🧑🏿🤝🧑🏻👩🏾🤝👨🏿👬🏿
I am now processing GPT streaming returns. I can use Gin to achieve this. The Demo code is as follows:
r.GET("/stream", func(c *gin.Context) {
chanStream := make(chan string, 100)
c.Header("Content-Type", "text/event-stream; charset=utf-8")
go http.GetData("What is Three-Body Problem? Please introduce it in 100 words", chanStream)
c.Stream(func(w io.Writer) bool {
if msg, ok := <-chanStream; ok {
fmt.Println("msg:" + msg)
outputBytes := bytes.NewBufferString(msg)
c.Writer.Write(append(outputBytes.Bytes(), []byte("\n")...))
return true
}
return false
})
What should I do if I want to use go-zero? I looked at the httpx package and found that writeJson did not find a way to handle streaming writing.
Regarding your issue with handling streaming data using go-zero, it seems that go-zero currently doesn't offer built-in support for EventStream handling like Gin does. You might need to implement the streaming logic yourself by referencing other code examples.
我现在处理GPT流式返回,我用Gin可以实现,Demo代码如下:
如果我想用go-zero该怎么处理,我看了下httpx这个包,更多是writeJson没找到处理流式写入方法
The text was updated successfully, but these errors were encountered: