MCPcopy
hub / github.com/docker/docker-agent / drainStream

Function drainStream

pkg/sessiontitle/generator.go:170–186  ·  view source on GitHub ↗

drainStream reads the entire content of a chat completion stream and returns the concatenated delta content. The stream is always closed before returning.

(stream chat.MessageStream)

Source from the content-addressed store, hash-verified

168// returns the concatenated delta content. The stream is always closed before
169// returning.
170func drainStream(stream chat.MessageStream) (string, error) {
171 defer stream.Close()
172
173 var content strings.Builder
174 for {
175 response, err := stream.Recv()
176 if errors.Is(err, io.EOF) {
177 return content.String(), nil
178 }
179 if err != nil {
180 return "", err
181 }
182 if len(response.Choices) > 0 {
183 content.WriteString(response.Choices[0].Delta.Content)
184 }
185 }
186}
187
188// buildPrompt formats the user messages into the system+user message pair
189// sent to the model.

Callers 1

generateOnceFunction · 0.70

Calls 3

CloseMethod · 0.65
RecvMethod · 0.65
StringMethod · 0.45

Tested by

no test coverage detected