M3: console.log -> Logger + UI redesign (QuestionBank) + S7/A9/A10/A11/U11 bug fixes + #1/#2/#3/#4 enhancements + i18n for QuestionBank pages

This commit is contained in:
Developer
2026-05-19 16:57:45 +08:00
parent 5b5f14674d
commit 29bac74b58
20 changed files with 1081 additions and 501 deletions
+25 -22
View File
@@ -1,6 +1,7 @@
import {
Body,
Controller,
Logger,
Post,
Request,
Res,
@@ -36,6 +37,8 @@ class StreamChatDto {
@Controller('chat')
@UseGuards(CombinedAuthGuard)
export class ChatController {
private readonly logger = new Logger(ChatController.name);
constructor(
private chatService: ChatService,
private modelConfigService: ModelConfigService,
@@ -49,7 +52,7 @@ export class ChatController {
@Res() res: Response,
) {
try {
console.log('Full Request Body:', JSON.stringify(body, null, 2));
this.logger.log('Full Request Body:', JSON.stringify(body, null, 2));
const {
message,
history = [],
@@ -71,22 +74,22 @@ export class ChatController {
} = body;
const userId = req.user.id;
console.log('=== Chat Debug Info ===');
console.log('User ID:', userId);
console.log('Message:', message);
console.log('User Language:', userLanguage);
console.log('Selected Embedding ID:', selectedEmbeddingId);
console.log('Selected LLM ID:', selectedLLMId);
console.log('Selected Groups:', selectedGroups);
console.log('Selected Files:', selectedFiles);
console.log('History ID:', historyId);
console.log('Temperature:', temperature);
console.log('Max Tokens:', maxTokens);
console.log('Top K:', topK);
console.log('Similarity Threshold:', similarityThreshold);
console.log('Rerank Similarity Threshold:', rerankSimilarityThreshold);
console.log('Query Expansion:', enableQueryExpansion);
console.log('HyDE:', enableHyDE);
this.logger.log('=== Chat Debug Info ===');
this.logger.log('User ID:', userId);
this.logger.log('Message:', message);
this.logger.log('User Language:', userLanguage);
this.logger.log('Selected Embedding ID:', selectedEmbeddingId);
this.logger.log('Selected LLM ID:', selectedLLMId);
this.logger.log('Selected Groups:', selectedGroups);
this.logger.log('Selected Files:', selectedFiles);
this.logger.log('History ID:', historyId);
this.logger.log('Temperature:', temperature);
this.logger.log('Max Tokens:', maxTokens);
this.logger.log('Top K:', topK);
this.logger.log('Similarity Threshold:', similarityThreshold);
this.logger.log('Rerank Similarity Threshold:', rerankSimilarityThreshold);
this.logger.log('Query Expansion:', enableQueryExpansion);
this.logger.log('HyDE:', enableHyDE);
const role = req.user.role;
const tenantId = req.user.tenantId;
@@ -105,14 +108,14 @@ export class ChatController {
if (selectedLLMId) {
// Find specifically selected model
llmModel = await this.modelConfigService.findOne(selectedLLMId);
console.log('使用选中的LLM模型:', llmModel.name);
this.logger.log('使用选中的LLM模型:', llmModel.name);
} else {
// Use organization's default LLM from Index Chat Config (strict)
llmModel = await this.modelConfigService.findDefaultByType(
tenantId,
ModelType.LLM,
);
console.log(
this.logger.log(
'最终使用的LLM模型 (默认):',
llmModel ? llmModel.name : '无',
);
@@ -162,7 +165,7 @@ export class ChatController {
res.write('data: [DONE]\n\n');
res.end();
} catch (error) {
console.error('Stream chat error:', error);
this.logger.error('Stream chat error:', error);
try {
res.write(
`data: ${JSON.stringify({ type: 'error', data: error.message || 'Server Error' })}\n\n`,
@@ -170,7 +173,7 @@ export class ChatController {
res.write('data: [DONE]\n\n');
res.end();
} catch (writeError) {
console.error('Failed to write error response:', writeError);
this.logger.error('Failed to write error response:', writeError);
}
}
}
@@ -220,7 +223,7 @@ export class ChatController {
res.write('data: [DONE]\n\n');
res.end();
} catch (error) {
console.error('Stream assist error:', error);
this.logger.error('Stream assist error:', error);
res.write(
`data: ${JSON.stringify({ type: 'error', data: error.message || 'Server Error' })}\n\n`,
);
+29 -29
View File
@@ -71,30 +71,30 @@ export class ChatService {
enableHyDE?: boolean, // New
tenantId?: string, // New: tenant isolation
): AsyncGenerator<{ type: 'content' | 'sources' | 'historyId'; data: any }> {
console.log('=== ChatService.streamChat ===');
console.log('User ID:', userId);
console.log('User language:', userLanguage);
console.log('Selected embedding model ID:', selectedEmbeddingId);
console.log('Selected groups:', selectedGroups);
console.log('Selected files:', selectedFiles);
console.log('History ID:', historyId);
console.log('Temperature:', temperature);
console.log('Max Tokens:', maxTokens);
console.log('Top K:', topK);
console.log('Similarity threshold:', similarityThreshold);
console.log('Rerank threshold:', rerankSimilarityThreshold);
console.log('Query expansion:', enableQueryExpansion);
console.log('HyDE:', enableHyDE);
console.log('Model configuration:', {
this.logger.log('=== ChatService.streamChat ===');
this.logger.log('User ID:', userId);
this.logger.log('User language:', userLanguage);
this.logger.log('Selected embedding model ID:', selectedEmbeddingId);
this.logger.log('Selected groups:', selectedGroups);
this.logger.log('Selected files:', selectedFiles);
this.logger.log('History ID:', historyId);
this.logger.log('Temperature:', temperature);
this.logger.log('Max Tokens:', maxTokens);
this.logger.log('Top K:', topK);
this.logger.log('Similarity threshold:', similarityThreshold);
this.logger.log('Rerank threshold:', rerankSimilarityThreshold);
this.logger.log('Query expansion:', enableQueryExpansion);
this.logger.log('HyDE:', enableHyDE);
this.logger.log('Model configuration:', {
name: modelConfig.name,
modelId: modelConfig.modelId,
baseUrl: modelConfig.baseUrl,
});
console.log(
this.logger.log(
'API Key prefix:',
modelConfig.apiKey?.substring(0, 10) + '...',
);
console.log('API Key length:', modelConfig.apiKey?.length);
this.logger.log('API Key length:', modelConfig.apiKey?.length);
// Get current language setting (keeping LANGUAGE_CONFIG for backward compatibility, now uses i18n service)
// Use actual language based on user settings
@@ -113,7 +113,7 @@ export class ChatService {
selectedGroups,
);
currentHistoryId = searchHistory.id;
console.log(
this.logger.log(
this.i18nService.getMessage(
'creatingHistory',
effectiveUserLanguage,
@@ -143,7 +143,7 @@ export class ChatService {
);
}
console.log(
this.logger.log(
this.i18nService.getMessage(
'usingEmbeddingModel',
effectiveUserLanguage,
@@ -156,7 +156,7 @@ export class ChatService {
);
// 2. Search using user's query directly
console.log(
this.logger.log(
this.i18nService.getMessage('startingSearch', effectiveUserLanguage),
);
yield {
@@ -204,7 +204,7 @@ export class ChatService {
// HybridSearch returns ES hit structure, but RagSearchResult is normalized
// BuildContext expects {fileName, content}. RagSearchResult has these
searchResults = ragResults;
console.log(
this.logger.log(
this.i18nService.getMessage(
'searchResultsCount',
effectiveUserLanguage,
@@ -274,7 +274,7 @@ export class ChatService {
};
}
} catch (searchError) {
console.error(
this.logger.error(
this.i18nService.getMessage(
'searchFailedLog',
effectiveUserLanguage,
@@ -461,14 +461,14 @@ ${instruction}`;
try {
// Join keywords into search string
const combinedQuery = keywords.join(' ');
console.log(
this.logger.log(
this.i18nService.getMessage('searchString', userLanguage) +
combinedQuery,
);
// Check if embedding model ID is provided
if (!embeddingModelId) {
console.log(
this.logger.log(
this.i18nService.getMessage(
'embeddingModelIdNotProvided',
userLanguage,
@@ -478,7 +478,7 @@ ${instruction}`;
}
// Use actual embedding vector
console.log(
this.logger.log(
this.i18nService.getMessage('generatingEmbeddings', userLanguage),
);
const queryEmbedding = await this.embeddingService.getEmbeddings(
@@ -486,7 +486,7 @@ ${instruction}`;
embeddingModelId,
);
const queryVector = queryEmbedding[0];
console.log(
this.logger.log(
this.i18nService.getMessage('embeddingsGenerated', userLanguage) +
this.i18nService.getMessage('dimensions', userLanguage) +
':',
@@ -494,7 +494,7 @@ ${instruction}`;
);
// Hybrid search
console.log(
this.logger.log(
this.i18nService.getMessage('performingHybridSearch', userLanguage),
);
const results = await this.elasticsearchService.hybridSearch(
@@ -507,7 +507,7 @@ ${instruction}`;
explicitFileIds, // Pass explicit file IDs
tenantId, // Pass tenant ID
);
console.log(
this.logger.log(
this.i18nService.getMessage('esSearchCompleted', userLanguage) +
this.i18nService.getMessage('resultsCount', userLanguage) +
':',
@@ -516,7 +516,7 @@ ${instruction}`;
return results.slice(0, 10);
} catch (error) {
console.error(
this.logger.error(
this.i18nService.getMessage('hybridSearchFailed', userLanguage) + ':',
error,
);