修复AI分析SSE流断开:中间件透传Flusher、DB Key生效、错误提示不覆盖
This commit is contained in:
@@ -88,7 +88,7 @@ func (d *Deps) Analyze(w http.ResponseWriter, r *http.Request) {
|
||||
w.Header().Set("Cache-Control", "no-cache")
|
||||
w.Header().Set("Connection", "keep-alive")
|
||||
|
||||
if err := streamLLM(d.AIConfig, prompt, w, flusher); err != nil {
|
||||
if err := streamLLM(llmCfg, prompt, w, flusher); err != nil {
|
||||
log.Printf("[ai] stream error: %v", err)
|
||||
sendSSE(w, flusher, "error", err.Error())
|
||||
}
|
||||
|
||||
@@ -39,6 +39,13 @@ func (r *statusRecorder) WriteHeader(code int) {
|
||||
r.ResponseWriter.WriteHeader(code)
|
||||
}
|
||||
|
||||
// Flush 透传 http.Flusher,避免 SSE 流式响应被中间件阻断。
|
||||
func (r *statusRecorder) Flush() {
|
||||
if f, ok := r.ResponseWriter.(http.Flusher); ok {
|
||||
f.Flush()
|
||||
}
|
||||
}
|
||||
|
||||
func writeJSON(w http.ResponseWriter, status int, body any) {
|
||||
w.Header().Set("Content-Type", "application/json")
|
||||
w.WriteHeader(status)
|
||||
|
||||
Reference in New Issue
Block a user