AFischer1985 commited on
Commit
c58e706
1 Parent(s): 93a294f

update extend_prompt

Browse files
Files changed (1) hide show
  1. run.py +19 -5
run.py CHANGED
@@ -2,7 +2,7 @@
2
  # Title: German AI-Interface with advanced RAG
3
  # Author: Andreas Fischer
4
  # Date: January 31st, 2023
5
- # Last update: February 29th, 2024
6
  ##########################################################################################
7
 
8
  #https://github.com/abetlen/llama-cpp-python/issues/306
@@ -196,12 +196,22 @@ def extend_prompt(message="", history=None, system=None, RAGAddon=None, system2=
196
  template0=" [INST]{system}\n [/INST] </s>"
197
  template1=" [INST] {message} [/INST]"
198
  template2=" {response}</s>"
 
 
 
 
 
199
  if("Gemma-" in modelPath): # https://huggingface.co/mistralai/Mixtral-8x7B-Instruct-v0.1
200
  template0="<start_of_turn>user{system}</end_of_turn>"
201
  template1="<start_of_turn>user{message}</end_of_turn><start_of_turn>model"
202
- template2="{response}</end_of_turn>"
203
- if("Mixtral-8x7b-instruct" in modelPath): # https://huggingface.co/mistralai/Mixtral-8x7B-Instruct-v0.1
204
  startOfString="<s>"
 
 
 
 
 
205
  template0=" [INST]{system}\n [/INST] </s>"
206
  template1=" [INST] {message} [/INST]"
207
  template2=" {response}</s>"
@@ -217,7 +227,11 @@ def extend_prompt(message="", history=None, system=None, RAGAddon=None, system2=
217
  if(("Discolm_german_7b" in modelPath) or ("SauerkrautLM-7b-HerO" in modelPath)): #https://huggingface.co/VAGOsolutions/SauerkrautLM-7b-HerO
218
  template0="<|im_start|>system\n{system}<|im_end|>\n"
219
  template1="<|im_start|>user\n{message}<|im_end|>\n<|im_start|>assistant\n"
220
- template2="{response}<|im_end|>\n"
 
 
 
 
221
  if("WizardLM-13B-V1.2" in modelPath): #https://huggingface.co/WizardLM/WizardLM-13B-V1.2
222
  template0="{system} " #<s>
223
  template1="USER: {message} ASSISTANT: "
@@ -235,7 +249,7 @@ def extend_prompt(message="", history=None, system=None, RAGAddon=None, system2=
235
  for user_message, bot_response in history[-historylimit:]:
236
  if user_message is None: user_message = ""
237
  if bot_response is None: bot_response = ""
238
- bot_response = re.sub("\n\n<details>((.|\n)*?)</details>","", bot_response) # remove RAG-compontents
239
  if removeHTML==True: bot_response = re.sub("<(.*?)>","\n", bot_response) # remove HTML-components in general (may cause bugs with markdown-rendering)
240
  if user_message is not None: prompt += template1.format(message=user_message[:zeichenlimit])
241
  if bot_response is not None: prompt += template2.format(response=bot_response[:zeichenlimit])
 
2
  # Title: German AI-Interface with advanced RAG
3
  # Author: Andreas Fischer
4
  # Date: January 31st, 2023
5
+ # Last update: May 27th, 2024
6
  ##########################################################################################
7
 
8
  #https://github.com/abetlen/llama-cpp-python/issues/306
 
196
  template0=" [INST]{system}\n [/INST] </s>"
197
  template1=" [INST] {message} [/INST]"
198
  template2=" {response}</s>"
199
+ if("command-r" in modelPath): #https://huggingface.co/CohereForAI/c4ai-command-r-v01
200
+ ## <BOS_TOKEN><|START_OF_TURN_TOKEN|><|USER_TOKEN|>Hello, how are you?<|END_OF_TURN_TOKEN|><|START_OF_TURN_TOKEN|><|CHATBOT_TOKEN|>
201
+ template0="<BOS_TOKEN><|START_OF_TURN_TOKEN|><|SYSTEM_TOKEN|> {system}<|END_OF_TURN_TOKEN|>"
202
+ template1="<|START_OF_TURN_TOKEN|><|USER_TOKEN|>{message}<|END_OF_TURN_TOKEN|><|START_OF_TURN_TOKEN|><|CHATBOT_TOKEN|>"
203
+ template2="{response}<|END_OF_TURN_TOKEN|>"
204
  if("Gemma-" in modelPath): # https://huggingface.co/mistralai/Mixtral-8x7B-Instruct-v0.1
205
  template0="<start_of_turn>user{system}</end_of_turn>"
206
  template1="<start_of_turn>user{message}</end_of_turn><start_of_turn>model"
207
+ template2="{response}</end_of_turn>"
208
+ if("Mixtral-8x22B-Instruct" in modelPath): # AutoTokenizer: <s>[INST] U1[/INST] A1</s>[INST] U2[/INST] A2</s>
209
  startOfString="<s>"
210
+ template0="[INST]{system}\n [/INST] </s>"
211
+ template1="[INST] {message}[/INST]"
212
+ template2=" {response}</s>"
213
+ if("Mixtral-8x7b-instruct" in modelPath): # https://huggingface.co/mistralai/Mixtral-8x7B-Instruct-v0.1
214
+ startOfString="<s>" # AutoTokenzizer: <s> [INST] U1 [/INST]A1</s> [INST] U2 [/INST]A2</s>
215
  template0=" [INST]{system}\n [/INST] </s>"
216
  template1=" [INST] {message} [/INST]"
217
  template2=" {response}</s>"
 
227
  if(("Discolm_german_7b" in modelPath) or ("SauerkrautLM-7b-HerO" in modelPath)): #https://huggingface.co/VAGOsolutions/SauerkrautLM-7b-HerO
228
  template0="<|im_start|>system\n{system}<|im_end|>\n"
229
  template1="<|im_start|>user\n{message}<|im_end|>\n<|im_start|>assistant\n"
230
+ template2="{response}<|im_end|>\n"
231
+ if("Llama-3-SauerkrautLM-8b-Instruct" in modelPath): #https://huggingface.co/VAGOsolutions/SauerkrautLM-7b-HerO
232
+ template0="<|begin_of_text|><|start_header_id|>system<|end_header_id|>\n\n{system}<|eot_id|>"
233
+ template1="<|start_header_id|>user<|end_header_id|>\n\n{message}<|eot_id|><|start_header_id|>assistant<|end_header_id|>\n\n"
234
+ template2="{response}<|eot_id|>\n"
235
  if("WizardLM-13B-V1.2" in modelPath): #https://huggingface.co/WizardLM/WizardLM-13B-V1.2
236
  template0="{system} " #<s>
237
  template1="USER: {message} ASSISTANT: "
 
249
  for user_message, bot_response in history[-historylimit:]:
250
  if user_message is None: user_message = ""
251
  if bot_response is None: bot_response = ""
252
+ bot_response = re.sub("\n\n<details>.*?</details>","", bot_response, flags=re.DOTALL) # remove RAG-compontents
253
  if removeHTML==True: bot_response = re.sub("<(.*?)>","\n", bot_response) # remove HTML-components in general (may cause bugs with markdown-rendering)
254
  if user_message is not None: prompt += template1.format(message=user_message[:zeichenlimit])
255
  if bot_response is not None: prompt += template2.format(response=bot_response[:zeichenlimit])