Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -11,6 +11,9 @@ def respond(message, history, system_message, max_tokens, temperature, top_p):
|
|
| 11 |
|
| 12 |
prompt = system_message.strip() + "\n\n"
|
| 13 |
|
|
|
|
|
|
|
|
|
|
| 14 |
for user_msg, bot_msg in history:
|
| 15 |
prompt += f"User: {user_msg}\nAssistant: {bot_msg}\n"
|
| 16 |
|
|
@@ -18,13 +21,15 @@ def respond(message, history, system_message, max_tokens, temperature, top_p):
|
|
| 18 |
|
| 19 |
result = pipe(
|
| 20 |
prompt,
|
| 21 |
-
max_new_tokens=max_tokens,
|
| 22 |
temperature=temperature,
|
| 23 |
top_p=top_p,
|
| 24 |
-
do_sample=True
|
|
|
|
|
|
|
| 25 |
)
|
| 26 |
|
| 27 |
-
return result[0]["generated_text"]
|
| 28 |
|
| 29 |
|
| 30 |
chatbot = gr.ChatInterface(
|
|
|
|
| 11 |
|
| 12 |
prompt = system_message.strip() + "\n\n"
|
| 13 |
|
| 14 |
+
# Limit history (VERY important)
|
| 15 |
+
history = history[-4:]
|
| 16 |
+
|
| 17 |
for user_msg, bot_msg in history:
|
| 18 |
prompt += f"User: {user_msg}\nAssistant: {bot_msg}\n"
|
| 19 |
|
|
|
|
| 21 |
|
| 22 |
result = pipe(
|
| 23 |
prompt,
|
| 24 |
+
max_new_tokens=min(max_tokens, 4096), # prevent runaway generation
|
| 25 |
temperature=temperature,
|
| 26 |
top_p=top_p,
|
| 27 |
+
do_sample=True,
|
| 28 |
+
return_full_text=False,
|
| 29 |
+
eos_token_id=pipe.tokenizer.eos_token_id, # important stop signal
|
| 30 |
)
|
| 31 |
|
| 32 |
+
return result[0]["generated_text"]
|
| 33 |
|
| 34 |
|
| 35 |
chatbot = gr.ChatInterface(
|