Skip to content

Commit 88a008b

Browse files
committed
enh: Try to enhance prompt
Signed-off-by: Marcel Klehr <mklehr@gmx.net>
1 parent c3cc44b commit 88a008b

2 files changed

Lines changed: 25 additions & 4 deletions

File tree

context_chat_backend/chain/context.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,10 @@ def get_context_docs(
2929
def get_context_chunks(context_docs: list[Document]) -> list[str]:
3030
context_chunks = []
3131
for doc in context_docs:
32+
chunk = 'Start of document'
3233
if title := doc.metadata.get('title'):
33-
context_chunks.append(title)
34-
context_chunks.append(doc.page_content)
34+
chunk += '\nDocument: ' + title
35+
chunk += "\n\n" + doc.page_content + "\n\nEnd of document"
36+
context_chunks.append(chunk)
3537

3638
return context_chunks

context_chat_backend/chain/one_shot.py

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,29 @@
1010
from .query_proc import get_pruned_query
1111
from .types import ContextException, LLMOutput, ScopeType
1212

13-
_LLM_TEMPLATE = '''Answer based only on this context and do not add any imaginative details. Make sure to use the same language as the question in your answer.
14-
{context}
13+
_LLM_TEMPLATE = '''
14+
You're an AI assistant named Nextcloud Assistant, good at finding relevant context from documents to answer questions provided by the user.
15+
Use the following documents as context to answer the question at the end. REMEMBER to exercise source criticism as the documents are returned by a search provider that can return unrelated documents.
16+
If you don't know the answer or are unsure, just say that you don't know, don't try to make up an answer. Don't mention the context in your answer but rather just answer the question directly. Detect the language of the question and make sure to use the same language that was used in the question to answer the question.
17+
Don't mention which language was used, but just answer the question directly in the same langauge.
18+
19+
QUESTION:
20+
-----------------
1521
1622
{question}
23+
24+
-----------------
25+
END OF QUESTION
26+
27+
CONTEXT:
28+
-----------------
29+
30+
{context}
31+
32+
-----------------
33+
END OF CONTEXT
34+
35+
Let's think this step-by-step. Answer the question:
1736
''' # noqa: E501
1837

1938

0 commit comments

Comments
 (0)