Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
|
@@ -185,23 +185,28 @@ def chat_stream(message, history, model, temperature, max_tokens):
|
|
| 185 |
|
| 186 |
history = history or []
|
| 187 |
|
| 188 |
-
# Build conversation context
|
| 189 |
system = "You are Axon, an expert AI coding assistant. Be helpful, concise, and provide working code examples when appropriate."
|
| 190 |
conversation = ""
|
| 191 |
-
for
|
| 192 |
-
|
|
|
|
|
|
|
|
|
|
| 193 |
|
| 194 |
prompt = f"<|im_start|>system\n{system}<|im_end|>\n{conversation}<|im_start|>user\n{message}<|im_end|>\n<|im_start|>assistant\n"
|
| 195 |
|
| 196 |
-
|
| 197 |
-
history
|
| 198 |
|
|
|
|
| 199 |
for chunk in generate_stream(prompt, model, max_tokens, temperature):
|
| 200 |
response += chunk
|
| 201 |
-
history
|
| 202 |
-
yield history
|
| 203 |
|
| 204 |
-
yield
|
|
|
|
| 205 |
|
| 206 |
def generate_code(description, language, model, max_tokens):
|
| 207 |
if not description.strip():
|
|
@@ -747,7 +752,7 @@ def create_ui():
|
|
| 747 |
|
| 748 |
msg.submit(respond, [msg, chatbot, model_dropdown, temperature, max_tokens], [chatbot, msg])
|
| 749 |
send_btn.click(respond, [msg, chatbot, model_dropdown, temperature, max_tokens], [chatbot, msg])
|
| 750 |
-
clear_btn.click(lambda: [], None, chatbot)
|
| 751 |
transcribe_btn.click(transcribe_audio, audio_input, msg)
|
| 752 |
|
| 753 |
# Core tools
|
|
|
|
| 185 |
|
| 186 |
history = history or []
|
| 187 |
|
| 188 |
+
# Build conversation context from history
|
| 189 |
system = "You are Axon, an expert AI coding assistant. Be helpful, concise, and provide working code examples when appropriate."
|
| 190 |
conversation = ""
|
| 191 |
+
for msg in history[-10:]: # Last 10 messages
|
| 192 |
+
if msg["role"] == "user":
|
| 193 |
+
conversation += f"<|im_start|>user\n{msg['content']}<|im_end|>\n"
|
| 194 |
+
elif msg["role"] == "assistant":
|
| 195 |
+
conversation += f"<|im_start|>assistant\n{msg['content']}<|im_end|>\n"
|
| 196 |
|
| 197 |
prompt = f"<|im_start|>system\n{system}<|im_end|>\n{conversation}<|im_start|>user\n{message}<|im_end|>\n<|im_start|>assistant\n"
|
| 198 |
|
| 199 |
+
# Add user message to history
|
| 200 |
+
history = history + [{"role": "user", "content": message}]
|
| 201 |
|
| 202 |
+
response = ""
|
| 203 |
for chunk in generate_stream(prompt, model, max_tokens, temperature):
|
| 204 |
response += chunk
|
| 205 |
+
# Yield history with partial assistant response
|
| 206 |
+
yield history + [{"role": "assistant", "content": response}]
|
| 207 |
|
| 208 |
+
# Final yield with complete response
|
| 209 |
+
yield history + [{"role": "assistant", "content": response}]
|
| 210 |
|
| 211 |
def generate_code(description, language, model, max_tokens):
|
| 212 |
if not description.strip():
|
|
|
|
| 752 |
|
| 753 |
msg.submit(respond, [msg, chatbot, model_dropdown, temperature, max_tokens], [chatbot, msg])
|
| 754 |
send_btn.click(respond, [msg, chatbot, model_dropdown, temperature, max_tokens], [chatbot, msg])
|
| 755 |
+
clear_btn.click(lambda: ([], ""), None, [chatbot, msg])
|
| 756 |
transcribe_btn.click(transcribe_audio, audio_input, msg)
|
| 757 |
|
| 758 |
# Core tools
|