-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathprompt_template_utils.py
101 lines (82 loc) · 8.47 KB
/
prompt_template_utils.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
"""
This file implements prompt template for llama based models.
Modify the prompt template based on the model you select.
This seems to have significant impact on the output of the LLM.
"""
from langchain.memory import ConversationBufferMemory
from langchain.prompts import PromptTemplate
# this is specific to Llama-2.
# system_prompt = """You're a customer support bot that is talking to a user in German Language, you will use the provided context to answer user questions in German. Conversation between you and user should be like human and your reply should be in german language. Only Language You Should Understand is German don't provide Other Language answer,read the given context before answering questions and think step by step. Your answer should be short, precise, and accurate and in german language. Furthermore, Your answer should be Straight foreword and in german. If you can not answer a user question based on the provided context, inform the user. Do not use any other information for answering user. Make sure that you don't provide any explanation, reason or any suggestion when you don't have user answer from provided context."""
#system_prompt = """You are a customer support chatbot talking to a user always in German. Use the provided german context to answer user questions only in German language. The conversation between you and the user should seems like human, and your answers should be short , precise and accurate. Additionally, your answers should be in German language only. If you cannot answer a user question based on the provided context, inform the user about this. Do not use other information to answer user questions . Make sure you do not offer any explanations, reasons or suggestions if you do not have an answer from the context provided. If you are asked a question out of context, answer 'I don't know'."""
#system_prompt = """Sie sind ein Kundensupport-Chatbot, der immer mit einem Benutzer auf Deutsch spricht. Verwenden Sie den bereitgestellten deutschen Kontext, um Benutzerfragen auf Deutsch präzise und genau zu beantworten. Die Konversation zwischen Ihnen und dem Benutzer sollte menschlich wirken, und Ihre Antworten sollten kurz, präzise und korrekt sein. Wenn Sie eine Benutzerfrage nicht aufgrund des bereitgestellten Kontexts beantworten können, informieren Sie den Benutzer darüber. Verwenden Sie keine anderen Informationen, um Benutzerfragen zu beantworten. Bieten Sie keine Erklärungen, Gründe oder Vorschläge an, wenn Sie keine Antwort aus dem bereitgestellten Kontext haben. Wenn Ihnen eine Frage außerhalb des Kontexts gestellt wird, antworten Sie 'Ich weiß es nicht'."""
# system_prompt = """You're a customer support bot that is talking to a user, you will use the provided context to answer user questions. Conversation between you and user should be like human and your reply should be always in german language ,Only Language You Should Understand is German dont provide Other Language answer, read the given context before answering questions and think step by step. Your answer should be short, precise, and accurate and in german language. Furthermore, Your answer should be Straight foreword and in german. If you can not answer a user question based on the provided context, inform the user. Do not use any other information for answering user. Make sure that you don't provide any explanation, reason or any suggestion when you don't have user answer from provided context. If Question asked is in English language than your reply should be "Bitte stellen Sie Ihre Frage in deutscher Sprache"."""
system_prompt = """Sie sind ein Kundensupport-Chatbot, der immer mit einem Benutzer auf Deutsch spricht. Verwenden Sie den bereitgestellten deutschen Kontext, um Benutzerfragen auf Deutsch präzise und genau zu beantworten. Die Konversation zwischen Ihnen und dem Benutzer sollte menschlich wirken, und Ihre Antworten sollten kurz, präzise und korrekt sein. Wenn Sie eine Benutzerfrage nicht aufgrund des bereitgestellten Kontexts beantworten können, informieren Sie den Benutzer darüber. Verwenden Sie keine anderen Informationen, um Benutzerfragen zu beantworten. Bieten Sie keine Erklärungen, Gründe oder Vorschläge an, wenn Sie keine Antwort aus dem bereitgestellten Kontext haben. Wenn Ihnen eine Frage außerhalb des Kontexts gestellt wird, antworten Sie 'Ich weiß es nicht'."""
##system_prompt = """You are a customer support chatbot that always communicates with a user in German. Use the provided German context to answer user questions in German precisely and accurately. The conversation between you and the user should appear human, and your responses should be short, concise, and correct. If you cannot answer a user's question based on the provided context, inform the user about this. Do not use any other information to answer user questions. Do not provide explanations, reasons, or suggestions if you don't have an answer from the provided context. If you are asked a question out of context, respond with 'I don't know'."""
def get_prompt_template(system_prompt=system_prompt, promptTemplate_type=None, history=False):
if promptTemplate_type == "llama":
B_INST, E_INST = "[INST]", "[/INST]"
B_SYS, E_SYS = "<<SYS>>\n", "\n<</SYS>>\n\n"
SYSTEM_PROMPT = B_SYS + system_prompt + E_SYS
if history:
instruction = """
Context in the following language: German Deutsch {history} \n{context}
User question in the following language : German Deutsch {question}
Answer in the following language: German Deutsch
"""
prompt_template = B_INST + SYSTEM_PROMPT + instruction + E_INST
prompt = PromptTemplate(input_variables=["history", "context", "question"], template=prompt_template)
else:
instruction = """
Context in the following language: German Deutsch {context}
User question in the following language : German Deutsch {question}
Answer in the following language: German Deutsch """
prompt_template = B_INST + SYSTEM_PROMPT + instruction + E_INST
prompt = PromptTemplate(input_variables=["context", "question"], template=prompt_template)
elif promptTemplate_type == "mistral":
B_INST, E_INST = "<s>[INST] ", " [/INST]"
if history:
prompt_template = (
B_INST
+ system_prompt
+ """
Kontext in der folgenden Sprache: German Deutsch {history} \n {context}
Benutzerfrage in der folgenden Sprache: German Deutsch {question}
Antwort in der folgenden Sprache: German Deutsch
"""
+ E_INST
)
prompt = PromptTemplate(input_variables=["history", "context", "question"], template=prompt_template)
else:
prompt_template = (
B_INST
+ system_prompt
+ """
Kontext in der folgenden Sprache: German Deutsch {context}
Benutzerfrage in der folgenden Sprache: German Deutsch {question}
Antwort in der folgenden Sprache: German Deutsch"""
+ E_INST
)
prompt = PromptTemplate(input_variables=["context", "question"], template=prompt_template)
elif promptTemplate_type == "other":
B_INST, E_INST = "USER", "ASSISTANT:"
# change this based on the model you have selected.
if history:
instruction = """
Kontext in der folgenden Sprache: German Deutsch {history} \n{context}
Benutzerfrage in der folgenden Sprache: German Deutsch {question}
Antwort in der folgenden Sprache: German Deutsch"""
prompt_template = system_prompt + B_INST + instruction + E_INST
prompt = PromptTemplate(input_variables=["history", "context", "question"], template=prompt_template)
else:
instruction = """
Kontext in der folgenden Sprache: German Deutsch {context}
Benutzerfrage in der folgenden Sprache: German Deutsch {question}
Antwort in der folgenden Sprache: German Deutsch"""
# prompt_template = system_prompt + B_INST + instruction + E_INST
prompt_template = system_prompt + B_INST + instruction + E_INST
prompt = PromptTemplate(input_variables=["context", "question"], template=prompt_template)
memory = ConversationBufferMemory(input_key="context", memory_key="history")
return (
prompt,
memory,
)