Update app.py
Browse files
app.py
CHANGED
@@ -33,18 +33,21 @@ def respond(
|
|
33 |
|
34 |
messages.append({"role": "user", "content": message})
|
35 |
|
|
|
36 |
response = ""
|
37 |
|
38 |
try:
|
39 |
-
for
|
40 |
-
prompt
|
41 |
max_new_tokens=max_tokens,
|
42 |
stream=True,
|
43 |
temperature=temperature,
|
44 |
top_p=top_p,
|
45 |
):
|
46 |
-
|
47 |
-
|
|
|
|
|
48 |
yield [(message, response)]
|
49 |
except Exception as e:
|
50 |
yield [(message, f"An error occurred: {str(e)}")]
|
|
|
33 |
|
34 |
messages.append({"role": "user", "content": message})
|
35 |
|
36 |
+
prompt = "\n".join([m["content"] for m in messages])
|
37 |
response = ""
|
38 |
|
39 |
try:
|
40 |
+
for chunk in client.text_generation(
|
41 |
+
prompt,
|
42 |
max_new_tokens=max_tokens,
|
43 |
stream=True,
|
44 |
temperature=temperature,
|
45 |
top_p=top_p,
|
46 |
):
|
47 |
+
if isinstance(chunk, str):
|
48 |
+
response += chunk
|
49 |
+
else:
|
50 |
+
response += chunk.token.text if hasattr(chunk, 'token') else chunk.generated_text
|
51 |
yield [(message, response)]
|
52 |
except Exception as e:
|
53 |
yield [(message, f"An error occurred: {str(e)}")]
|