Spaces:
Build error
Build error
Update app.py
Browse files
app.py
CHANGED
|
@@ -14,35 +14,38 @@ def respond(
|
|
| 14 |
temperature,
|
| 15 |
top_p,
|
| 16 |
):
|
| 17 |
-
|
| 18 |
system_prefix = """
|
| 19 |
If the input language is Korean, respond in Korean. If it's English, respond in English.
|
| 20 |
-
|
| 21 |
"""
|
| 22 |
|
| 23 |
-
messages = [{"role": "system", "content": f"{system_prefix} {system_message}"}]
|
| 24 |
|
| 25 |
-
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
if
|
| 29 |
-
messages.append({"role": "assistant", "content":
|
| 30 |
|
|
|
|
| 31 |
messages.append({"role": "user", "content": message})
|
| 32 |
|
| 33 |
response = ""
|
| 34 |
|
| 35 |
-
|
| 36 |
-
|
| 37 |
-
|
| 38 |
-
|
| 39 |
-
|
| 40 |
-
|
| 41 |
-
|
| 42 |
-
|
| 43 |
-
|
| 44 |
-
|
| 45 |
-
|
|
|
|
|
|
|
|
|
|
| 46 |
|
| 47 |
|
| 48 |
theme = "Nymbo/Nymbo_Theme"
|
|
|
|
| 14 |
temperature,
|
| 15 |
top_p,
|
| 16 |
):
|
|
|
|
| 17 |
system_prefix = """
|
| 18 |
If the input language is Korean, respond in Korean. If it's English, respond in English.
|
| 19 |
+
Do not output in both languages simultaneously. Always respond in Korean to Korean questions and in English to English questions.
|
| 20 |
"""
|
| 21 |
|
| 22 |
+
messages = [{"role": "system", "content": f"{system_prefix} {system_message}"}]
|
| 23 |
|
| 24 |
+
# Ensure alternating user/assistant messages
|
| 25 |
+
for user_msg, assistant_msg in history:
|
| 26 |
+
messages.append({"role": "user", "content": user_msg})
|
| 27 |
+
if assistant_msg: # Only add assistant message if it exists
|
| 28 |
+
messages.append({"role": "assistant", "content": assistant_msg})
|
| 29 |
|
| 30 |
+
# Add the current user message
|
| 31 |
messages.append({"role": "user", "content": message})
|
| 32 |
|
| 33 |
response = ""
|
| 34 |
|
| 35 |
+
try:
|
| 36 |
+
for message in hf_client.chat_completion(
|
| 37 |
+
messages,
|
| 38 |
+
max_tokens=max_tokens,
|
| 39 |
+
stream=True,
|
| 40 |
+
temperature=temperature,
|
| 41 |
+
top_p=top_p,
|
| 42 |
+
):
|
| 43 |
+
token = message.choices[0].delta.content
|
| 44 |
+
if token is not None:
|
| 45 |
+
response += token.strip("")
|
| 46 |
+
yield response
|
| 47 |
+
except Exception as e:
|
| 48 |
+
yield f"An error occurred: {str(e)}"
|
| 49 |
|
| 50 |
|
| 51 |
theme = "Nymbo/Nymbo_Theme"
|