Ashrafb commited on
Commit
7b170b4
1 Parent(s): f6eeeb2

Update main.py

Browse files
Files changed (1) hide show
  1. main.py +4 -21
main.py CHANGED
@@ -47,31 +47,14 @@ def generate(prompt, history, temperature=0.9, max_new_tokens=512, top_p=0.95, r
47
 
48
  formatted_prompt = format_prompt(prompt, history)
49
 
50
- bot_response = client.text_generation(formatted_prompt, **generate_kwargs, stream=True, details=True, return_full_text=False)
51
  output = ""
52
- current_word = ""
53
 
54
- for response in bot_response:
55
- token_text = response.token.text.strip()
56
- if token_text != "":
57
- # Decode the token text to handle encoded characters
58
- decoded_text = token_text.encode("utf-8", "backslashreplace").decode("utf-8")
59
 
60
- # Add the decoded token text to the current word
61
- current_word += decoded_text
62
 
63
- # Check if the decoded token text ends with a space or punctuation mark
64
- if decoded_text[-1] in " .,?!":
65
- # Add the current word to the output with a space delimiter
66
- output += current_word
67
- output += " "
68
- current_word = ""
69
-
70
- # Add the last word to the output if it exists
71
- if current_word:
72
- output += current_word
73
-
74
- return output.strip()
75
 
76
 
77
 
 
47
 
48
  formatted_prompt = format_prompt(prompt, history)
49
 
50
+ stream = client.text_generation(formatted_prompt, **generate_kwargs, stream=True, details=True, return_full_text=False)
51
  output = ""
 
52
 
53
+ for response in stream:
54
+ output += response.token.text
 
 
 
55
 
56
+ return output
 
57
 
 
 
 
 
 
 
 
 
 
 
 
 
58
 
59
 
60