DavidFernandes commited on
Commit
47bb8d4
·
verified ·
1 Parent(s): 1478f8e

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +7 -2
app.py CHANGED
@@ -21,16 +21,17 @@ def format_prompt(message, history):
21
  return prompt
22
 
23
  def generate(
24
- prompt, history, system_prompt="You are Ultron from the Marvel Cinematic Universe and you have all his characteristics", temperature=0.9, max_new_tokens=256, top_p=0.95, repetition_penalty=1.5,
25
  ):
26
  temperature = float(temperature)
27
  if temperature < 1e-2:
28
  temperature = 1e-2
29
  top_p = float(top_p)
30
 
 
31
  generate_kwargs = dict(
32
  temperature=temperature,
33
- max_new_tokens=max_new_tokens,
34
  top_p=top_p,
35
  repetition_penalty=repetition_penalty,
36
  do_sample=True,
@@ -43,6 +44,10 @@ def generate(
43
 
44
  for response in stream:
45
  output += response.token.text
 
 
 
 
46
  yield output
47
  return output
48
 
 
21
  return prompt
22
 
23
  def generate(
24
+ prompt, history, system_prompt="You are Ultron from the Marvel Cinematic Universe and you have all his characteristics", temperature=0.9, max_length=50, top_p=0.95, repetition_penalty=1.5,
25
  ):
26
  temperature = float(temperature)
27
  if temperature < 1e-2:
28
  temperature = 1e-2
29
  top_p = float(top_p)
30
 
31
+ # Generate a longer response initially
32
  generate_kwargs = dict(
33
  temperature=temperature,
34
+ max_new_tokens=max_length * 2, # Double the max_length to generate a longer response
35
  top_p=top_p,
36
  repetition_penalty=repetition_penalty,
37
  do_sample=True,
 
44
 
45
  for response in stream:
46
  output += response.token.text
47
+ # Truncate the output to the desired max_length
48
+ if len(output) > max_length:
49
+ output = output[:max_length].rsplit(' ', 1)[0] + '...'
50
+ break
51
  yield output
52
  return output
53