Skip to content

Commit

Permalink
enh: Try to enhance prompt
Browse files Browse the repository at this point in the history
Signed-off-by: Marcel Klehr <[email protected]>
  • Loading branch information
marcelklehr committed Dec 19, 2024
1 parent c3cc44b commit 88a008b
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 4 deletions.
6 changes: 4 additions & 2 deletions context_chat_backend/chain/context.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,10 @@ def get_context_docs(
def get_context_chunks(context_docs: list[Document]) -> list[str]:
context_chunks = []
for doc in context_docs:
chunk = 'Start of document'
if title := doc.metadata.get('title'):
context_chunks.append(title)
context_chunks.append(doc.page_content)
chunk += '\nDocument: ' + title
chunk += "\n\n" + doc.page_content + "\n\nEnd of document"
context_chunks.append(chunk)

return context_chunks
23 changes: 21 additions & 2 deletions context_chat_backend/chain/one_shot.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,29 @@
from .query_proc import get_pruned_query
from .types import ContextException, LLMOutput, ScopeType

_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.
{context}
_LLM_TEMPLATE = '''
You're an AI assistant named Nextcloud Assistant, good at finding relevant context from documents to answer questions provided by the user.
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.
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.
Don't mention which language was used, but just answer the question directly in the same langauge.
QUESTION:
-----------------
{question}
-----------------
END OF QUESTION
CONTEXT:
-----------------
{context}
-----------------
END OF CONTEXT
Let's think this step-by-step. Answer the question:
''' # noqa: E501


Expand Down

0 comments on commit 88a008b

Please sign in to comment.