salomonsky commited on
Commit
b5f7ced
·
verified ·
1 Parent(s): 12e5ecd

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +8 -8
app.py CHANGED
@@ -13,14 +13,13 @@ def format_prompt(message, history):
13
  global system_prompt_sent
14
  prompt = "<s>"
15
 
16
- if history is not None and isinstance(history, list):
17
- if not any(f"[INST] {system_prompt} [/INST]" in user_prompt for user_prompt, _ in history):
18
- prompt += f"[INST] {system_prompt} [/INST]"
19
- system_prompt_sent = True
20
 
21
- for user_prompt, bot_response in history:
22
- prompt += f"[INST] {user_prompt} [/INST]"
23
- prompt += f" {bot_response}</s> "
24
 
25
  prompt += f"[INST] {message} [/INST]"
26
  return prompt
@@ -37,6 +36,7 @@ def text_to_speech(text, speed=1.3):
37
  return audio_file_path
38
 
39
  def generate(user_input, history, temperature=None, max_new_tokens=1024, top_p=0.95, repetition_penalty=1.0):
 
40
  global system_prompt_sent
41
  temperature = float(temperature) if temperature is not None else 0.9
42
  if temperature < 1e-2:
@@ -54,8 +54,8 @@ def generate(user_input, history, temperature=None, max_new_tokens=1024, top_p=0
54
 
55
  formatted_prompt = format_prompt(user_input, history)
56
  stream = client.text_generation(formatted_prompt, **generate_kwargs, stream=True, details=True, return_full_text=True)
57
-
58
  response = ""
 
59
  for response_token in stream:
60
  response += response_token.token.text
61
 
 
13
  global system_prompt_sent
14
  prompt = "<s>"
15
 
16
+ if not any(f"[INST] {system_prompt} [/INST]" in user_prompt for user_prompt, _ in history):
17
+ prompt += f"[INST] {system_prompt} [/INST]"
18
+ system_prompt_sent = True
 
19
 
20
+ for user_prompt, bot_response in history:
21
+ prompt += f"[INST] {user_prompt} [/INST]"
22
+ prompt += f" {bot_response}</s> "
23
 
24
  prompt += f"[INST] {message} [/INST]"
25
  return prompt
 
36
  return audio_file_path
37
 
38
  def generate(user_input, history, temperature=None, max_new_tokens=1024, top_p=0.95, repetition_penalty=1.0):
39
+
40
  global system_prompt_sent
41
  temperature = float(temperature) if temperature is not None else 0.9
42
  if temperature < 1e-2:
 
54
 
55
  formatted_prompt = format_prompt(user_input, history)
56
  stream = client.text_generation(formatted_prompt, **generate_kwargs, stream=True, details=True, return_full_text=True)
 
57
  response = ""
58
+
59
  for response_token in stream:
60
  response += response_token.token.text
61