Update app.py
Browse files
app.py
CHANGED
|
@@ -29,13 +29,7 @@ def chat_with_model(prompt, system_prompt, chatbot_display, internal_history):
|
|
| 29 |
# internal_history là [{"role": "user", ...}, {"role": "assistant", ...}]
|
| 30 |
if internal_history is None:
|
| 31 |
internal_history = []
|
| 32 |
-
|
| 33 |
-
expected_key = os.environ.get("hf_key")
|
| 34 |
-
if expected_key not in prompt:
|
| 35 |
-
print("❌ Invalid key.")
|
| 36 |
-
return None
|
| 37 |
-
prompt = prompt.replace(expected_key, "")
|
| 38 |
-
|
| 39 |
# 2. Xây dựng toàn bộ lịch sử để đưa cho model
|
| 40 |
# Bắt đầu với System Prompt (luôn lấy cái mới nhất từ Textbox)
|
| 41 |
messages_for_model = [{"role": "system", "content": system_prompt}]
|
|
@@ -57,7 +51,7 @@ def chat_with_model(prompt, system_prompt, chatbot_display, internal_history):
|
|
| 57 |
# 4. Generate
|
| 58 |
output_tokens = model.generate(
|
| 59 |
inputs,
|
| 60 |
-
max_new_tokens=
|
| 61 |
do_sample=True,
|
| 62 |
temperature=0.7,
|
| 63 |
top_p=0.9
|
|
@@ -86,6 +80,7 @@ with gr.Blocks(theme=gr.themes.Monochrome()) as demo:
|
|
| 86 |
# "Bộ nhớ" ẩn để lưu lịch sử ChatML (list of dicts)
|
| 87 |
internal_history = gr.State()
|
| 88 |
|
|
|
|
| 89 |
|
| 90 |
with gr.Row():
|
| 91 |
with gr.Column(scale=3):
|
|
@@ -112,7 +107,7 @@ with gr.Blocks(theme=gr.themes.Monochrome()) as demo:
|
|
| 112 |
# Ô System Prompt
|
| 113 |
system_prompt_box = gr.Textbox(
|
| 114 |
label="System Prompt (AI's Role & Rules)",
|
| 115 |
-
value=
|
| 116 |
lines=30
|
| 117 |
)
|
| 118 |
|
|
|
|
| 29 |
# internal_history là [{"role": "user", ...}, {"role": "assistant", ...}]
|
| 30 |
if internal_history is None:
|
| 31 |
internal_history = []
|
| 32 |
+
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 33 |
# 2. Xây dựng toàn bộ lịch sử để đưa cho model
|
| 34 |
# Bắt đầu với System Prompt (luôn lấy cái mới nhất từ Textbox)
|
| 35 |
messages_for_model = [{"role": "system", "content": system_prompt}]
|
|
|
|
| 51 |
# 4. Generate
|
| 52 |
output_tokens = model.generate(
|
| 53 |
inputs,
|
| 54 |
+
max_new_tokens=512, # Tăng số token tối đa lên một chút
|
| 55 |
do_sample=True,
|
| 56 |
temperature=0.7,
|
| 57 |
top_p=0.9
|
|
|
|
| 80 |
# "Bộ nhớ" ẩn để lưu lịch sử ChatML (list of dicts)
|
| 81 |
internal_history = gr.State()
|
| 82 |
|
| 83 |
+
gr.Markdown("# 💬 Xyntrai-Mistral 2.5 7B (Có trí nhớ)")
|
| 84 |
|
| 85 |
with gr.Row():
|
| 86 |
with gr.Column(scale=3):
|
|
|
|
| 107 |
# Ô System Prompt
|
| 108 |
system_prompt_box = gr.Textbox(
|
| 109 |
label="System Prompt (AI's Role & Rules)",
|
| 110 |
+
value=SYSTEM_PROMPT_DEFAULT,
|
| 111 |
lines=30
|
| 112 |
)
|
| 113 |
|