Update main.py
Browse files
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 |
-
|
51 |
output = ""
|
52 |
-
current_word = ""
|
53 |
|
54 |
-
for response in
|
55 |
-
|
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 |
-
|
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 |
|