Spaces:
Sleeping
Sleeping
luigi12345
commited on
Commit
•
739c8e1
1
Parent(s):
790c3fa
Update app.py
Browse files
app.py
CHANGED
@@ -628,7 +628,7 @@ def handle_user_input(user_input: str):
|
|
628 |
# Enhanced streaming with chunking
|
629 |
for chunk in interpreter.chat(user_input, stream=True, display=False):
|
630 |
if isinstance(chunk, dict):
|
631 |
-
content = chunk.get('content', '')
|
632 |
chunk_type = chunk.get('type', 'message')
|
633 |
|
634 |
# Skip empty chunks
|
@@ -639,7 +639,7 @@ def handle_user_input(user_input: str):
|
|
639 |
if chunk_type == 'message':
|
640 |
# Flush code buffer if exists
|
641 |
if code_buffer:
|
642 |
-
code_text = ''.join(code_buffer)
|
643 |
if code_text.strip():
|
644 |
message_buffer.append(f"\n```{current_chunk['language'] or 'python'}\n{code_text.strip()}\n```\n")
|
645 |
code_buffer = []
|
@@ -652,7 +652,7 @@ def handle_user_input(user_input: str):
|
|
652 |
# Start new code block if needed
|
653 |
if current_chunk['type'] != 'code':
|
654 |
if code_buffer: # Flush previous code buffer
|
655 |
-
code_text = ''.join(code_buffer)
|
656 |
if code_text.strip():
|
657 |
message_buffer.append(f"\n```{current_chunk['language'] or 'python'}\n{code_text.strip()}\n```\n")
|
658 |
code_buffer = []
|
@@ -667,9 +667,9 @@ def handle_user_input(user_input: str):
|
|
667 |
|
668 |
# Update display with proper chunking
|
669 |
try:
|
670 |
-
display_content = ''.join(str(item) for item in message_buffer)
|
671 |
if code_buffer: # Add current code buffer if exists
|
672 |
-
code_text = ''.join(str(item) for item in code_buffer)
|
673 |
if code_text.strip():
|
674 |
display_content += f"\n```{current_chunk['language'] or 'python'}\n{code_text.strip()}\n```"
|
675 |
|
@@ -683,12 +683,12 @@ def handle_user_input(user_input: str):
|
|
683 |
try:
|
684 |
# Handle any remaining code buffer
|
685 |
if code_buffer:
|
686 |
-
code_text = ''.join(code_buffer)
|
687 |
if code_text.strip():
|
688 |
message_buffer.append(f"\n```{current_chunk['language'] or 'python'}\n{code_text.strip()}\n```\n")
|
689 |
|
690 |
# Prepare final response
|
691 |
-
final_response = ''.join(message_buffer)
|
692 |
|
693 |
# Create and store assistant message
|
694 |
assistant_message = ChatMessage(final_response, "text", "assistant")
|
|
|
628 |
# Enhanced streaming with chunking
|
629 |
for chunk in interpreter.chat(user_input, stream=True, display=False):
|
630 |
if isinstance(chunk, dict):
|
631 |
+
content = str(chunk.get('content', '')) # Convert content to string
|
632 |
chunk_type = chunk.get('type', 'message')
|
633 |
|
634 |
# Skip empty chunks
|
|
|
639 |
if chunk_type == 'message':
|
640 |
# Flush code buffer if exists
|
641 |
if code_buffer:
|
642 |
+
code_text = ''.join(str(item) for item in code_buffer) # Convert each item to string
|
643 |
if code_text.strip():
|
644 |
message_buffer.append(f"\n```{current_chunk['language'] or 'python'}\n{code_text.strip()}\n```\n")
|
645 |
code_buffer = []
|
|
|
652 |
# Start new code block if needed
|
653 |
if current_chunk['type'] != 'code':
|
654 |
if code_buffer: # Flush previous code buffer
|
655 |
+
code_text = ''.join(str(item) for item in code_buffer) # Convert each item to string
|
656 |
if code_text.strip():
|
657 |
message_buffer.append(f"\n```{current_chunk['language'] or 'python'}\n{code_text.strip()}\n```\n")
|
658 |
code_buffer = []
|
|
|
667 |
|
668 |
# Update display with proper chunking
|
669 |
try:
|
670 |
+
display_content = ''.join(str(item) for item in message_buffer) # Convert each item to string
|
671 |
if code_buffer: # Add current code buffer if exists
|
672 |
+
code_text = ''.join(str(item) for item in code_buffer) # Convert each item to string
|
673 |
if code_text.strip():
|
674 |
display_content += f"\n```{current_chunk['language'] or 'python'}\n{code_text.strip()}\n```"
|
675 |
|
|
|
683 |
try:
|
684 |
# Handle any remaining code buffer
|
685 |
if code_buffer:
|
686 |
+
code_text = ''.join(str(item) for item in code_buffer) # Convert each item to string
|
687 |
if code_text.strip():
|
688 |
message_buffer.append(f"\n```{current_chunk['language'] or 'python'}\n{code_text.strip()}\n```\n")
|
689 |
|
690 |
# Prepare final response
|
691 |
+
final_response = ''.join(str(item) for item in message_buffer) # Convert each item to string
|
692 |
|
693 |
# Create and store assistant message
|
694 |
assistant_message = ChatMessage(final_response, "text", "assistant")
|