Update main.py
Browse files
main.py
CHANGED
@@ -51,7 +51,13 @@ def generate(prompt, history, temperature=0.9, max_new_tokens=512, top_p=0.95, r
|
|
51 |
output = ""
|
52 |
|
53 |
for response in stream:
|
54 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
55 |
|
56 |
return output
|
57 |
|
@@ -66,6 +72,7 @@ def generate(prompt, history, temperature=0.9, max_new_tokens=512, top_p=0.95, r
|
|
66 |
|
67 |
|
68 |
|
|
|
69 |
@app.post("/generate/")
|
70 |
async def generate_chat(request: Request, prompt: str = Form(...), history: str = Form(...), temperature: float = Form(0.9), max_new_tokens: int = Form(512), top_p: float = Form(0.95), repetition_penalty: float = Form(1.0)):
|
71 |
history = eval(history) # Convert history string back to list
|
|
|
51 |
output = ""
|
52 |
|
53 |
for response in stream:
|
54 |
+
token_text = response.token.text.strip()
|
55 |
+
if token_text != "":
|
56 |
+
# Decode the token text to handle encoded characters
|
57 |
+
decoded_text = token_text.encode("utf-8", "backslashreplace").decode("utf-8")
|
58 |
+
|
59 |
+
# Add the decoded token text to the output
|
60 |
+
output += decoded_text
|
61 |
|
62 |
return output
|
63 |
|
|
|
72 |
|
73 |
|
74 |
|
75 |
+
|
76 |
@app.post("/generate/")
|
77 |
async def generate_chat(request: Request, prompt: str = Form(...), history: str = Form(...), temperature: float = Form(0.9), max_new_tokens: int = Form(512), top_p: float = Form(0.95), repetition_penalty: float = Form(1.0)):
|
78 |
history = eval(history) # Convert history string back to list
|