Skip to content

Commit 3cd5f14

Browse files
committed
enh: Try to enhance prompt
Signed-off-by: Marcel Klehr <[email protected]>
1 parent c3cc44b commit 3cd5f14

File tree

4 files changed

+29
-8
lines changed

4 files changed

+29
-8
lines changed

config.cpu.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,13 +46,13 @@ llm:
4646
n_batch: 512
4747
n_ctx: 8192
4848
max_tokens: 4096
49-
template: "<|im_start|> system \nYou're an AI assistant named Nextcloud Assistant, good at finding relevant context from documents to answer questions provided by the user. <|im_end|>\n<|im_start|> user\nUse the following documents as context to answer the question at the end. REMEMBER to excersice source critisicm as the documents are returned by a search provider that can return unrelated documents.\n\nSTART OF CONTEXT: \n{context} \n\nEND OF CONTEXT!\n\nIf 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. \nQuestion: {question} Let's think this step-by-step. \n<|im_end|>\n<|im_start|> assistant\n"
49+
template: "<|im_start|> system \nYou're an AI assistant named Nextcloud Assistant, good at finding relevant context from documents to answer questions provided by the user. <|im_end|>\n<|im_start|> user\nUse 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.\n\nIf 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.\n\nSTART OF QUESTION:\n----------\n{question}\n----------\nEND OF QUESTION\n\n\n\nSTART OF CONTEXT: \n{context} \n\nEND OF CONTEXT\n\nLet's think this step-by-step. Answer the question: \n<|im_end|>\n<|im_start|> assistant\n"
5050
no_ctx_template: "<|im_start|> system \nYou're an AI assistant named Nextcloud Assistant.<|im_end|>\n<|im_start|> user\n{question}<|im_end|>\n<|im_start|> assistant\n"
5151
end_separator: "<|im_end|>"
5252

5353
ctransformer:
5454
model: dolphin-2.2.1-mistral-7b.Q5_K_M.gguf
55-
template: "<|im_start|> system \nYou're an AI assistant named Nextcloud Assistant, good at finding relevant context from documents to answer questions provided by the user. <|im_end|>\n<|im_start|> user\nUse the following documents as context to answer the question at the end. REMEMBER to excersice source critisicm as the documents are returned by a search provider that can return unrelated documents.\n\nSTART OF CONTEXT: \n{context} \n\nEND OF CONTEXT!\n\nIf 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. \nQuestion: {question} Let's think this step-by-step. \n<|im_end|>\n<|im_start|> assistant\n"
55+
template: "<|im_start|> system \nYou're an AI assistant named Nextcloud Assistant, good at finding relevant context from documents to answer questions provided by the user. <|im_end|>\n<|im_start|> user\nUse 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.\n\nIf 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.\n\nSTART OF QUESTION:\n----------\n{question}\n----------\nEND OF QUESTION\n\n\n\nSTART OF CONTEXT: \n{context} \n\nEND OF CONTEXT\n\nLet's think this step-by-step. Answer the question: \n<|im_end|>\n<|im_start|> assistant\n"
5656
no_ctx_template: "<|im_start|> system \nYou're an AI assistant named Nextcloud Assistant.<|im_end|>\n<|im_start|> user\n{question}<|im_end|>\n<|im_start|> assistant\n"
5757
end_separator: "<|im_end|>"
5858
config:

config.gpu.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ llm:
4747
n_batch: 512
4848
n_ctx: 8192
4949
max_tokens: 4096
50-
template: "<|im_start|> system \nYou're an AI assistant named Nextcloud Assistant, good at finding relevant context from documents to answer questions provided by the user. <|im_end|>\n<|im_start|> user\nUse the following documents as context to answer the question at the end. REMEMBER to excersice source critisicm as the documents are returned by a search provider that can return unrelated documents.\n\nSTART OF CONTEXT: \n{context} \n\nEND OF CONTEXT!\n\nIf 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. \nQuestion: {question} Let's think this step-by-step. \n<|im_end|>\n<|im_start|> assistant\n"
50+
template: "<|im_start|> system \nYou're an AI assistant named Nextcloud Assistant, good at finding relevant context from documents to answer questions provided by the user. <|im_end|>\n<|im_start|> user\nUse 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.\n\nIf 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.\n\nSTART OF QUESTION:\n----------\n{question}\n----------\nEND OF QUESTION\n\n\n\nSTART OF CONTEXT: \n{context} \n\nEND OF CONTEXT\n\nLet's think this step-by-step. Answer the question: \n<|im_end|>\n<|im_start|> assistant\n"
5151
no_ctx_template: "<|im_start|> system \nYou're an AI assistant named Nextcloud Assistant.<|im_end|>\n<|im_start|> user\n{question}<|im_end|>\n<|im_start|> assistant\n"
5252
end_separator: "<|im_end|>"
5353
n_gpu_layers: -1
@@ -56,7 +56,7 @@ llm:
5656

5757
ctransformer:
5858
model: dolphin-2.2.1-mistral-7b.Q5_K_M.gguf
59-
template: "<|im_start|> system \nYou're an AI assistant named Nextcloud Assistant, good at finding relevant context from documents to answer questions provided by the user. <|im_end|>\n<|im_start|> user\nUse the following documents as context to answer the question at the end. REMEMBER to excersice source critisicm as the documents are returned by a search provider that can return unrelated documents.\n\nSTART OF CONTEXT: \n{context} \n\nEND OF CONTEXT!\n\nIf 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. \nQuestion: {question} Let's think this step-by-step. \n<|im_end|>\n<|im_start|> assistant\n"
59+
template: "<|im_start|> system \nYou're an AI assistant named Nextcloud Assistant, good at finding relevant context from documents to answer questions provided by the user. <|im_end|>\n<|im_start|> user\nUse 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.\n\nIf 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.\n\nSTART OF QUESTION:\n----------\n{question}\n----------\nEND OF QUESTION\n\n\n\nSTART OF CONTEXT: \n{context} \n\nEND OF CONTEXT\n\nLet's think this step-by-step. Answer the question: \n<|im_end|>\n<|im_start|> assistant\n"
6060
no_ctx_template: "<|im_start|> system \nYou're an AI assistant named Nextcloud Assistant.<|im_end|>\n<|im_start|> user\n{question}<|im_end|>\n<|im_start|> assistant\n"
6161
end_separator: "<|im_end|>"
6262
config:

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)