MCPcopy Create free account
hub / github.com/coder/coder / writeResponsesAPIResponse

Method writeResponsesAPIResponse

coderd/x/chatd/chattest/openai.go:293–320  ·  view source on GitHub ↗
(w http.ResponseWriter, req *OpenAIRequest, resp OpenAIResponse)

Source from the content-addressed store, hash-verified

291}
292
293func (s *openAIServer) writeResponsesAPIResponse(w http.ResponseWriter, req *OpenAIRequest, resp OpenAIResponse) {
294 if resp.Error != nil {
295 writeErrorResponse(s.t, w, resp.Error)
296 return
297 }
298
299 hasStreaming := resp.StreamingChunks != nil
300 hasNonStreaming := resp.Response != nil
301
302 switch {
303 case hasStreaming && hasNonStreaming:
304 http.Error(w, "handler returned both streaming and non-streaming responses", http.StatusInternalServerError)
305 return
306 case !hasStreaming && !hasNonStreaming:
307 http.Error(w, "handler returned empty response", http.StatusInternalServerError)
308 return
309 case req.Stream && !hasStreaming:
310 http.Error(w, "handler returned non-streaming response for streaming request", http.StatusInternalServerError)
311 return
312 case !req.Stream && !hasNonStreaming:
313 http.Error(w, "handler returned streaming response for non-streaming request", http.StatusInternalServerError)
314 return
315 case hasStreaming:
316 writeResponsesAPIStreaming(s.t, w, req.Request, resp)
317 default:
318 s.writeResponsesAPINonStreaming(w, resp.Response)
319 }
320}
321
322func writeChatCompletionsStreaming(w http.ResponseWriter, r *http.Request, chunks <-chan OpenAIChunk) {
323 w.Header().Set("Content-Type", "text/event-stream")

Callers 1

handleResponsesMethod · 0.95

Calls 4

writeErrorResponseFunction · 0.85
ErrorMethod · 0.45

Tested by

no test coverage detected