Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -88,17 +88,19 @@ def normalize_history(history):
|
|
| 88 |
continue
|
| 89 |
return normalized
|
| 90 |
|
| 91 |
-
# 在构建 tokens 之前调用
|
| 92 |
-
history = normalize_history(history)
|
| 93 |
|
| 94 |
# ---------------------------------------------------------------------------
|
| 95 |
# Chat function (streaming)
|
| 96 |
# ---------------------------------------------------------------------------
|
| 97 |
def chat(message, history, temperature, max_tokens, top_k):
|
| 98 |
"""Generate a streaming response for the chat interface."""
|
|
|
|
|
|
|
| 99 |
# Build the full token sequence from conversation history
|
| 100 |
# history is a list of [user_msg, assistant_msg] tuples
|
| 101 |
tokens = [bos_id]
|
|
|
|
|
|
|
| 102 |
for user_msg, assistant_msg in history:
|
| 103 |
tokens.append(user_start)
|
| 104 |
tokens.extend(tokenizer.encode(user_msg))
|
|
|
|
| 88 |
continue
|
| 89 |
return normalized
|
| 90 |
|
|
|
|
|
|
|
| 91 |
|
| 92 |
# ---------------------------------------------------------------------------
|
| 93 |
# Chat function (streaming)
|
| 94 |
# ---------------------------------------------------------------------------
|
| 95 |
def chat(message, history, temperature, max_tokens, top_k):
|
| 96 |
"""Generate a streaming response for the chat interface."""
|
| 97 |
+
# 在构建 tokens 之前调用
|
| 98 |
+
history = normalize_history(history)
|
| 99 |
# Build the full token sequence from conversation history
|
| 100 |
# history is a list of [user_msg, assistant_msg] tuples
|
| 101 |
tokens = [bos_id]
|
| 102 |
+
|
| 103 |
+
|
| 104 |
for user_msg, assistant_msg in history:
|
| 105 |
tokens.append(user_start)
|
| 106 |
tokens.extend(tokenizer.encode(user_msg))
|