Chat atelier : evenement SSE sources + affichage des pages utilisees
Le Brain emet un evenement sources (source_id, page, score des passages retenus) AVANT le premier token ; le Core le relaie tel quel (JSON brut) ; l UI affiche une ligne discrete sous la reponse (ex: 12, 47, 103), prefixee du nom de fichier si plusieurs sources. Transparence pour le MJ et diagnostic immediat quand le RAG repond a cote. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
@@ -91,6 +91,11 @@
|
||||
(created)="onActionCreated()">
|
||||
</app-notebook-action-card>
|
||||
}
|
||||
@if (sourcesLabel(m); as label) {
|
||||
<div class="nbd-msg-sources" title="Pages de la source utilisées pour ancrer cette réponse">
|
||||
📖 {{ label }}
|
||||
</div>
|
||||
}
|
||||
}
|
||||
} @else {
|
||||
<div class="nbd-msg-content">{{ m.content }}</div>
|
||||
|
||||
@@ -104,3 +104,10 @@
|
||||
display: inline-flex; align-items: center; gap: 0.35rem;
|
||||
font-size: 0.82rem; color: #c4a8ff; font-style: italic;
|
||||
}
|
||||
|
||||
// Pages de la source utilisées par le RAG (transparence de la réponse)
|
||||
.nbd-msg-sources {
|
||||
margin-top: 0.35rem;
|
||||
font-size: 0.75rem;
|
||||
opacity: 0.65;
|
||||
}
|
||||
|
||||
@@ -107,7 +107,29 @@ export class NotebookDetailComponent implements OnInit {
|
||||
return cache._parsed;
|
||||
}
|
||||
|
||||
/** trackBy stable pour les cartes d'action (évite toute recréation parasite). */
|
||||
/**
|
||||
* Libellé compact des pages utilisées par le RAG pour une réponse
|
||||
* (« p. 12, 47, 103 » — préfixé du nom du fichier si plusieurs sources).
|
||||
*/
|
||||
sourcesLabel(m: NotebookMessage): string {
|
||||
const src = m.sources ?? [];
|
||||
if (!src.length) return '';
|
||||
const bySource = new Map<string, number[]>();
|
||||
for (const s of src) {
|
||||
if (s.page == null) continue;
|
||||
const pages = bySource.get(s.sourceId) ?? [];
|
||||
if (!pages.includes(s.page)) pages.push(s.page);
|
||||
bySource.set(s.sourceId, pages);
|
||||
}
|
||||
if (bySource.size === 0) return '';
|
||||
const nameOf = (id: string) => this.sources.find(x => x.id === id)?.filename ?? '';
|
||||
return [...bySource.entries()]
|
||||
.map(([id, pages]) => {
|
||||
const label = `p. ${pages.sort((a, b) => a - b).join(', ')}`;
|
||||
return bySource.size > 1 && nameOf(id) ? `${nameOf(id)} — ${label}` : label;
|
||||
})
|
||||
.join(' · ');
|
||||
}
|
||||
|
||||
load(): void {
|
||||
this.service.get(this.notebookId).subscribe({
|
||||
@@ -162,6 +184,7 @@ export class NotebookDetailComponent implements OnInit {
|
||||
this.service.streamChat(this.notebookId, text, deep).subscribe({
|
||||
next: (ev) => {
|
||||
if (ev.type === 'token') { this.deepProgress = null; assistant.content += ev.value; }
|
||||
else if (ev.type === 'sources') assistant.sources = ev.sources;
|
||||
else if (ev.type === 'progress') this.deepProgress = { current: ev.current, total: ev.total };
|
||||
else if (ev.type === 'error') assistant.content += (assistant.content ? '\n\n' : '') + `⚠️ ${ev.message}`;
|
||||
},
|
||||
|
||||
@@ -16,12 +16,22 @@ export interface NotebookSource {
|
||||
pageCount: number;
|
||||
}
|
||||
|
||||
/** Passage source utilisé par le RAG pour ancrer une réponse (transparence). */
|
||||
export interface NotebookChatSource {
|
||||
sourceId: string;
|
||||
/** Numéro de page 1-based, null si inconnu. */
|
||||
page: number | null;
|
||||
score: number;
|
||||
}
|
||||
|
||||
export interface NotebookMessage {
|
||||
id?: string;
|
||||
notebookId?: string;
|
||||
/** "user" | "assistant" */
|
||||
role: string;
|
||||
content: string;
|
||||
/** Passages utilisés (réponses streamées uniquement — non persisté). */
|
||||
sources?: NotebookChatSource[];
|
||||
}
|
||||
|
||||
export interface NotebookDetail {
|
||||
@@ -35,6 +45,7 @@ export interface NotebookDetail {
|
||||
/** Évènements du chat ancré streamé. */
|
||||
export type NotebookChatEvent =
|
||||
| { type: 'token'; value: string }
|
||||
| { type: 'sources'; sources: NotebookChatSource[] }
|
||||
| { type: 'progress'; current: number; total: number }
|
||||
| { type: 'done' }
|
||||
| { type: 'error'; message: string };
|
||||
|
||||
@@ -78,6 +78,16 @@ export class NotebookService {
|
||||
if (name === 'token') {
|
||||
try { emit({ type: 'token', value: (JSON.parse(currentData) as { token?: string }).token ?? '' }); }
|
||||
catch { /* ignore */ }
|
||||
} else if (name === 'sources') {
|
||||
try {
|
||||
const o = JSON.parse(currentData) as { sources?: { source_id?: string; page?: number | null; score?: number }[] };
|
||||
emit({
|
||||
type: 'sources',
|
||||
sources: (o.sources ?? []).map(s => ({
|
||||
sourceId: s.source_id ?? '', page: s.page ?? null, score: s.score ?? 0
|
||||
}))
|
||||
});
|
||||
} catch { /* ignore */ }
|
||||
} else if (name === 'progress') {
|
||||
try {
|
||||
const o = JSON.parse(currentData) as { current?: number; total?: number };
|
||||
|
||||
Reference in New Issue
Block a user