cleaned_prod
This commit is contained in:
parent
61126a546a
commit
c298b557c6
@ -12,9 +12,9 @@ export interface CitationItem {
|
|||||||
|
|
||||||
export class ChatService {
|
export class ChatService {
|
||||||
private extractionService = new ExtractionService();
|
private extractionService = new ExtractionService();
|
||||||
private gatewayUrl = process.env.LLM_GATEWAY_URL || 'https://llm-devs.tech4biz.org/v1';
|
private gatewayUrl = process.env.LLM_GATEWAY_URL;
|
||||||
private apiKey = process.env.LLM_API_KEY || 'sk-TM-gxAudDVRTY-kq7_enEA';
|
private apiKey = process.env.LLM_API_KEY;
|
||||||
private modelId = process.env.LLM_MODEL_ID || 'deepseek-chat';
|
private modelId = process.env.LLM_MODEL_ID;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Process a user chat prompt with RBAC-scoped, unified RAG retrieval across Assets, Showcase Reels, Ecosystem Offerings, and Legal Documents.
|
* Process a user chat prompt with RBAC-scoped, unified RAG retrieval across Assets, Showcase Reels, Ecosystem Offerings, and Legal Documents.
|
||||||
@ -358,14 +358,14 @@ export class ChatService {
|
|||||||
if (keyTerms.length > 0) {
|
if (keyTerms.length > 0) {
|
||||||
catalogAssets.forEach(a => {
|
catalogAssets.forEach(a => {
|
||||||
const fullText = (a.title + ' ' + (a.description || '') + ' ' + (a.tags || []).join(' ') + ' ' + (a.verticals || []).map(v => v.name).join(' ') + ' ' + (a.techStacks || []).map(t => t.name).join(' ')).toLowerCase();
|
const fullText = (a.title + ' ' + (a.description || '') + ' ' + (a.tags || []).join(' ') + ' ' + (a.verticals || []).map(v => v.name).join(' ') + ' ' + (a.techStacks || []).map(t => t.name).join(' ')).toLowerCase();
|
||||||
|
|
||||||
let matchCount = 0;
|
let matchCount = 0;
|
||||||
keyTerms.forEach(kt => {
|
keyTerms.forEach(kt => {
|
||||||
if (fullText.includes(kt)) matchCount++;
|
if (fullText.includes(kt)) matchCount++;
|
||||||
});
|
});
|
||||||
|
|
||||||
if (matchCount >= 1) {
|
if (matchCount >= 1) {
|
||||||
const isRecommended = partnerGroup
|
const isRecommended = partnerGroup
|
||||||
? a.assetGroups.some(g => g.name.trim().toLowerCase() === partnerGroup)
|
? a.assetGroups.some(g => g.name.trim().toLowerCase() === partnerGroup)
|
||||||
: false;
|
: false;
|
||||||
|
|
||||||
@ -419,7 +419,7 @@ export class ChatService {
|
|||||||
location: `Segment ${chunk.chunkIndex + 1}`,
|
location: `Segment ${chunk.chunkIndex + 1}`,
|
||||||
};
|
};
|
||||||
|
|
||||||
const isRecommended = partnerGroup
|
const isRecommended = partnerGroup
|
||||||
? chunk.asset.assetGroups.some(g => g.name.trim().toLowerCase() === partnerGroup)
|
? chunk.asset.assetGroups.some(g => g.name.trim().toLowerCase() === partnerGroup)
|
||||||
: false;
|
: false;
|
||||||
|
|
||||||
@ -450,8 +450,8 @@ export class ChatService {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
const contextBlock = contextLines.length > 0
|
const contextBlock = contextLines.length > 0
|
||||||
? contextLines.join('\n---\n')
|
? contextLines.join('\n---\n')
|
||||||
: 'No specific catalog or showcase snippets needed for this query.';
|
: 'No specific catalog or showcase snippets needed for this query.';
|
||||||
|
|
||||||
const portalGuideContext = isClient ? `
|
const portalGuideContext = isClient ? `
|
||||||
@ -612,35 +612,35 @@ Portal Navigation Guidelines:
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Strict Citation Filtering: Only include Verified Knowledge Source citations if user explicitly attached entities or asked for asset/resource recommendations
|
// Strict Citation Filtering: Only include Verified Knowledge Source citations if user explicitly attached entities or asked for asset/resource recommendations
|
||||||
const isGeneralHelpQuery = promptLower.includes('password') ||
|
const isGeneralHelpQuery = promptLower.includes('password') ||
|
||||||
promptLower.includes('theme') ||
|
promptLower.includes('theme') ||
|
||||||
promptLower.includes('appearance') ||
|
promptLower.includes('appearance') ||
|
||||||
promptLower.includes('profile') ||
|
promptLower.includes('profile') ||
|
||||||
promptLower.includes('how to log') ||
|
promptLower.includes('how to log') ||
|
||||||
promptLower.includes('how to sign') ||
|
promptLower.includes('how to sign') ||
|
||||||
promptLower.includes('help');
|
promptLower.includes('help');
|
||||||
|
|
||||||
const hasAssetKeywords = promptLower.includes('asset') ||
|
const hasAssetKeywords = promptLower.includes('asset') ||
|
||||||
promptLower.includes('recommend') ||
|
promptLower.includes('recommend') ||
|
||||||
promptLower.includes('find') ||
|
promptLower.includes('find') ||
|
||||||
promptLower.includes('search') ||
|
promptLower.includes('search') ||
|
||||||
promptLower.includes('show') ||
|
promptLower.includes('show') ||
|
||||||
promptLower.includes('list') ||
|
promptLower.includes('list') ||
|
||||||
promptLower.includes('what are') ||
|
promptLower.includes('what are') ||
|
||||||
promptLower.includes('is there') ||
|
promptLower.includes('is there') ||
|
||||||
promptLower.includes('are there') ||
|
promptLower.includes('are there') ||
|
||||||
promptLower.includes('showcase') ||
|
promptLower.includes('showcase') ||
|
||||||
promptLower.includes('agreement') ||
|
promptLower.includes('agreement') ||
|
||||||
promptLower.includes('legal') ||
|
promptLower.includes('legal') ||
|
||||||
promptLower.includes('document') ||
|
promptLower.includes('document') ||
|
||||||
promptLower.includes('video') ||
|
promptLower.includes('video') ||
|
||||||
promptLower.includes('reel') ||
|
promptLower.includes('reel') ||
|
||||||
promptLower.includes('offering') ||
|
promptLower.includes('offering') ||
|
||||||
promptLower.includes('which are') ||
|
promptLower.includes('which are') ||
|
||||||
promptLower.includes('tell me more');
|
promptLower.includes('tell me more');
|
||||||
|
|
||||||
const finalCitations = (hasAttachedEntities || (hasAssetKeywords && !isGeneralHelpQuery))
|
const finalCitations = (hasAttachedEntities || (hasAssetKeywords && !isGeneralHelpQuery))
|
||||||
? Array.from(citationsMap.values())
|
? Array.from(citationsMap.values())
|
||||||
: [];
|
: [];
|
||||||
|
|
||||||
const botMessage = await prisma.chatMessage.create({
|
const botMessage = await prisma.chatMessage.create({
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user