feat(AI): add done channel for faster response
This commit is contained in:
parent
5e65a2ce32
commit
39868f4f07
3 changed files with 11 additions and 3 deletions
|
|
@ -51,6 +51,7 @@ type ChatResponseStream struct {
|
|||
Created int
|
||||
Model string
|
||||
Stream chan string
|
||||
Done chan struct{}
|
||||
Err error
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -77,11 +77,15 @@ func (c *Client) ChatCompletionStream(request ChatRequest) (*ChatResponseStream,
|
|||
return nil, errors.Errorf("status code: %d, body: %q", resp.StatusCode(), respBodyStr)
|
||||
}
|
||||
|
||||
ret := &ChatResponseStream{Stream: make(chan string, 1024)}
|
||||
ret := &ChatResponseStream{
|
||||
Stream: make(chan string, 1024),
|
||||
Done: make(chan struct{}),
|
||||
}
|
||||
go func() {
|
||||
defer func() {
|
||||
rbody.Close()
|
||||
close(ret.Stream)
|
||||
close(ret.Done)
|
||||
}()
|
||||
|
||||
var contentBegan bool
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue