fix: return call failed when LLM not available (#16518)

### Summary

As title
This commit is contained in:
Haruko386
2026-07-01 20:10:42 +08:00
committed by GitHub
parent fb0376561f
commit 4a72c973e8
2 changed files with 21 additions and 0 deletions

View File

@@ -18,6 +18,7 @@ package service
import (
"context"
"strings"
"ragflow/internal/common"
modelModule "ragflow/internal/entity/models"
@@ -208,6 +209,11 @@ func (s *AskService) run(ctx context.Context, llm StreamingLLM, userID, question
// Phase 4: Finalize — citation insertion + reference formatting.
visible := ExtractVisibleAnswer(fullAnswer)
if strings.TrimSpace(visible) == "" {
common.Warn("AskService LLM stream completed without visible answer")
s.sendOrCancel(out, AskDelta{Kind: AskDeltaError, Value: "LLM call failed"}, ctx)
return
}
chunkRefs := ChunksFormat(chunks)
// Attempt citation insertion if embedder is available.

View File

@@ -114,6 +114,21 @@ func TestAskService_StreamingFlow(t *testing.T) {
}
}
func TestAskService_EmptyLLMStreamReturnsError(t *testing.T) {
ret := &fakeRetriever{result: &RetrievalTestResponse{
Chunks: []map[string]interface{}{
{"id": "c1", "content_with_weight": "test chunk", "docnm_kwd": "Doc", "kb_id": "kb1", "doc_id": "d1"},
},
}}
llm := &fakeStreamLLM{}
svc := NewAskService(ret, nil, 0, 0)
deltas := collect(svc.Stream(context.Background(), llm, "user1", "test", []string{"kb1"}))
if len(deltas) != 1 || deltas[0].Kind != AskDeltaError || !strings.Contains(deltas[0].Value, "LLM call failed") {
t.Fatalf("expected LLM error delta, got %+v", deltas)
}
}
func TestAskService_ThinkTags(t *testing.T) {
ret := &fakeRetriever{result: &RetrievalTestResponse{
Chunks: []map[string]interface{}{