Arturo Jiménez de los Galanes Reguillos commited on
Commit
cc63cd7
·
1 Parent(s): 7a4427a

Apply a found chat template

Browse files
Files changed (1) hide show
  1. app.py +10 -8
app.py CHANGED
@@ -10,7 +10,7 @@ system_message = "You are a computer programmer that can translate python code t
10
 
11
  def user_prompt_for(python):
12
  return f"Rewrite this python code to C++. You must search for the maximum performance. \
13
- Format your response in Markdown. This is the python Code, between triple bacticks: \
14
  \n\n\
15
  ```{python}```"
16
 
@@ -21,15 +21,17 @@ def messages_for(python):
21
  ]
22
 
23
  def apply_chat_template(messages):
24
- bos_token = "<|begin_of_sentence|>"
25
- result = bos_token
 
26
  for message in messages:
27
- if message['role'] == 'user':
28
- result += f"<|start_header_id|>user<|end_header_id|>\n\n{message['content']}<|eot_id|>"
29
- elif message['role'] == 'assistant':
30
- result += f"<|start_header_id|>assistant<|end_header_id|>\n\n{message['content']}<|eot_id|>"
31
  else:
32
- result += f"<|start_header_id|>{message['role']}<|end_header_id|>\n\n{message['content']}<|eot_id|>"
 
33
  return result
34
 
35
 
 
10
 
11
  def user_prompt_for(python):
12
  return f"Rewrite this python code to C++. You must search for the maximum performance. \
13
+ Format your response in Markdown. This is the python Code, between triple backticks: \
14
  \n\n\
15
  ```{python}```"
16
 
 
21
  ]
22
 
23
  def apply_chat_template(messages):
24
+ bos_token = "<|begin▁of▁sentence|>"
25
+
26
+ result = ""
27
  for message in messages:
28
+ if message['role'] == 'system':
29
+ result += f"{message['content']}\n"
30
+ elif message['role'] == 'user':
31
+ result += f"### Instruction:\n{message['content']}\n"
32
  else:
33
+ result += f"### Response:\n{message['content']}\n<|EOT|>\n"
34
+
35
  return result
36
 
37