mirror of
https://github.com/paperless-ngx/paperless-ngx.git
synced 2025-12-19 13:06:46 +01:00
Super basic doc chat
[ci skip]
This commit is contained in:
parent
e2eec6dc71
commit
d1bd2af49c
4 changed files with 47 additions and 8 deletions
24
src/paperless/ai/chat.py
Normal file
24
src/paperless/ai/chat.py
Normal file
|
|
@ -0,0 +1,24 @@
|
|||
import logging
|
||||
|
||||
from django.contrib.auth.models import User
|
||||
from llama_index.core.query_engine import RetrieverQueryEngine
|
||||
|
||||
from paperless.ai.client import AIClient
|
||||
from paperless.ai.indexing import get_document_retriever
|
||||
|
||||
logger = logging.getLogger("paperless.ai.chat")
|
||||
|
||||
|
||||
def chat_with_documents(prompt: str, user: User) -> str:
|
||||
retriever = get_document_retriever(top_k=5)
|
||||
client = AIClient()
|
||||
|
||||
query_engine = RetrieverQueryEngine.from_args(
|
||||
retriever=retriever,
|
||||
llm=client.llm,
|
||||
)
|
||||
|
||||
logger.debug("Document chat prompt: %s", prompt)
|
||||
response = query_engine.query(prompt)
|
||||
logger.debug("Document chat response: %s", response)
|
||||
return str(response)
|
||||
Loading…
Add table
Add a link
Reference in a new issue