jdesiree commited on
Commit
bb3a918
·
verified ·
1 Parent(s): 067dac2

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +10 -4
app.py CHANGED
@@ -91,14 +91,20 @@ def respond_with_langchain(
91
 
92
  response = llm.invoke(prompt_text)
93
 
94
- if len(response) > 3000:
95
- response = response[:3000] + "... [Response truncated for length]"
 
 
 
 
96
 
97
  full_response = f"*{mode}*\n\n{response}"
98
- yield full_response
 
 
99
 
100
  except Exception as e:
101
- yield f"Sorry, I encountered an error: {str(e)[:200]}"
102
 
103
  # Create the Gradio interface
104
  demo = gr.ChatInterface(
 
91
 
92
  response = llm.invoke(prompt_text)
93
 
94
+ # Ensure response is clean and properly limited
95
+ if isinstance(response, str):
96
+ response = response.strip()
97
+ # Conservative limit to prevent content-length issues
98
+ if len(response) > 2500:
99
+ response = response[:2500] + "... [Response truncated - ask for continuation]"
100
 
101
  full_response = f"*{mode}*\n\n{response}"
102
+
103
+ # Return directly instead of yielding (no streaming)
104
+ return full_response
105
 
106
  except Exception as e:
107
+ return f"Sorry, I encountered an error: {str(e)[:150]}"
108
 
109
  # Create the Gradio interface
110
  demo = gr.ChatInterface(