mirror of
https://github.com/paperless-ngx/paperless-ngx.git
synced 2026-11-09 08:01:46 +00:00
Tweak: chat reference tweaks (#14723)
This commit is contained in:
1 parent
32bc5522e9
commit
e0c33b3d39
4 files changed
+37
-6
No files matched your search
@@ -42,11 +42,16 @@
|
||||
<span class="text-break">{{ message.content }}</span>
|
||||
}
|
||||
@if (message.role === 'assistant' && !message.isStreaming && message.references?.length) {
|
||||
<div class="chat-references list-group mt-3">
|
||||
<div class="list-group-item text-muted small py-1" i18n>Sources</div>
|
||||
@for (reference of message.references; track reference.id) {
|
||||
<a class="list-group-item list-group-item-action d-flex align-items-center text-primary" [routerLink]="['/documents', reference.id]" [title]="reference.title">
|
||||
<pngx-bs-icon width="0.9em" height="0.9em" name="file-text" class="me-2 flex-shrink-0"></pngx-bs-icon><span class="text-truncate">{{ reference.title }}</span>
|
||||
<div class="chat-references mt-2 pt-2 border-top">
|
||||
<div class="d-flex align-items-center text-muted mb-1">
|
||||
<span i18n>Sources</span>
|
||||
@if (hiddenReferenceCount(message) > 0 && !expandedReferences().has(message)) {
|
||||
<button type="button" class="badge rounded-pill bg-body-secondary text-body-secondary fw-normal border-0 ms-2" (click)="expandReferences(message)" i18n>+{{ hiddenReferenceCount(message) }} more</button>
|
||||
}
|
||||
</div>
|
||||
@for (reference of visibleReferences(message); track reference.id) {
|
||||
<a class="reference-link d-flex align-items-center lh-sm text-primary text-decoration-none py-1" [routerLink]="['/documents', reference.id]" [title]="reference.title">
|
||||
<pngx-bs-icon width="0.8em" height="0.8em" name="file-text" class="me-2 flex-shrink-0"></pngx-bs-icon><span class="text-truncate">{{ reference.title }}</span>
|
||||
</a>
|
||||
}
|
||||
</div>
|
||||
|
||||
@@ -12,6 +12,10 @@
|
||||
display: none;
|
||||
}
|
||||
|
||||
.message .flex-grow-1 {
|
||||
min-width: 0;
|
||||
}
|
||||
|
||||
.dropdown-item {
|
||||
white-space: initial;
|
||||
}
|
||||
|
||||
@@ -14,6 +14,7 @@ import { BootstrapIconComponent } from 'src/app/components/common/bootstrap-icon
|
||||
import { MarkdownPipe } from 'src/app/pipes/markdown.pipe'
|
||||
import {
|
||||
ChatMessage,
|
||||
ChatReference,
|
||||
ChatService,
|
||||
parseChatResponse,
|
||||
} from 'src/app/services/chat.service'
|
||||
@@ -40,8 +41,29 @@ export class ChatComponent implements OnInit {
|
||||
readonly input = signal('')
|
||||
readonly documentId = signal<number>(undefined)
|
||||
readonly slowResponse = signal(false)
|
||||
readonly expandedReferences = signal<Set<ChatMessage>>(new Set())
|
||||
public popperOptions = pngxPopperOptions
|
||||
|
||||
static readonly COLLAPSED_REFERENCE_COUNT = 2
|
||||
|
||||
public visibleReferences(message: ChatMessage): ChatReference[] {
|
||||
if (this.expandedReferences().has(message)) {
|
||||
return message.references
|
||||
}
|
||||
return message.references.slice(0, ChatComponent.COLLAPSED_REFERENCE_COUNT)
|
||||
}
|
||||
|
||||
public hiddenReferenceCount(message: ChatMessage): number {
|
||||
return Math.max(
|
||||
0,
|
||||
message.references.length - ChatComponent.COLLAPSED_REFERENCE_COUNT
|
||||
)
|
||||
}
|
||||
|
||||
public expandReferences(message: ChatMessage): void {
|
||||
this.expandedReferences.update((expanded) => new Set(expanded).add(message))
|
||||
}
|
||||
|
||||
private chatService: ChatService = inject(ChatService)
|
||||
private router: Router = inject(Router)
|
||||
|
||||
|
||||
@@ -22,8 +22,8 @@ logger = logging.getLogger("paperless_ai.chat")
|
||||
CHAT_METADATA_DELIMITER = "\n\n__PAPERLESS_CHAT_METADATA__"
|
||||
CHAT_ERROR_MESSAGE = "Sorry, something went wrong while generating a response."
|
||||
CHAT_NO_CONTENT_MESSAGE = "Sorry, I couldn't find any content to answer your question."
|
||||
MAX_CHAT_REFERENCES = 3
|
||||
CHAT_RETRIEVER_TOP_K = 5
|
||||
MAX_CHAT_REFERENCES = CHAT_RETRIEVER_TOP_K
|
||||
|
||||
|
||||
def _build_chat_prompt(output_language: str | None) -> str:
|
||||
|
||||
Reference in new issue
Block a user