overalSummary nil response

This commit is contained in:
Mazyar
2026-05-12 12:25:09 +03:30
parent 7c42b343ce
commit 0a7fdd1328
3 changed files with 77 additions and 64 deletions
+18 -14
View File
@@ -827,14 +827,14 @@ func (s *tenderService) CleanupOldData(ctx context.Context, olderThan time.Durat
}
// GetAISummary retrieves the AI-generated summary for a tender.
// It first tries to fetch from MinIO storage (async pipeline result).
// If not found or not ready, it returns an appropriate error.
// It loads from MinIO storage (async pipeline result). When no summary exists yet,
// the pipeline is still running, or storage is unavailable, it returns 200-compatible
// data with an empty overall_summary and a Source hint instead of an error.
func (s *tenderService) GetAISummary(ctx context.Context, id string) (*AISummaryResponse, error) {
if id == "" {
return nil, fmt.Errorf("tender ID cannot be empty")
}
// Get tender to find the notice_publication_id
t, err := s.repository.GetByID(ctx, id)
if err != nil {
s.logger.Error("Failed to get tender for AI summary", map[string]interface{}{
@@ -844,20 +844,24 @@ func (s *tenderService) GetAISummary(ctx context.Context, id string) (*AISummary
return nil, fmt.Errorf("failed to get tender: %w", err)
}
if t == nil {
return nil, fmt.Errorf("tender not found")
noticeID := strings.TrimSpace(t.NoticePublicationID)
emptyResp := func(source string) *AISummaryResponse {
return &AISummaryResponse{
NoticeID: noticeID,
OverallSummary: "",
Source: source,
}
}
noticeID := t.NoticePublicationID
if noticeID == "" {
return nil, fmt.Errorf("tender has no notice publication ID")
}
if t.ContractFolderID == "" {
return nil, fmt.Errorf("tender has no contract folder id")
if noticeID == "" || strings.TrimSpace(t.ContractFolderID) == "" {
return emptyResp("unavailable"), nil
}
if s.aiSummarizerStorage == nil {
return nil, fmt.Errorf("AI summarizer storage is not configured")
s.logger.Debug("AI summarizer storage not configured; returning empty AI summary", map[string]interface{}{
"tender_id": id,
})
return emptyResp("unavailable"), nil
}
summary, usedNotice, err := s.lookupSummaryForTender(ctx, t)
@@ -877,10 +881,10 @@ func (s *tenderService) GetAISummary(ctx context.Context, id string) (*AISummary
})
if errors.Is(err, ai_summarizer.ErrSummaryNotReady) {
return nil, fmt.Errorf("AI summary is not ready yet, the pipeline is still processing")
return emptyResp("pending"), nil
}
if errors.Is(err, ai_summarizer.ErrObjectNotFound) || errors.Is(err, ai_summarizer.ErrNoOverallSummary) {
return nil, fmt.Errorf("AI summary not found — this tender has not been processed by the AI pipeline yet")
return emptyResp("unavailable"), nil
}
return nil, fmt.Errorf("failed to get AI summary: %w", err)
}