Asish Karthikeya Gogineni commited on
Commit
9debe89
·
1 Parent(s): 1e94a5a

fix: Resolve IndentationError in rag.py and restore fallback logic

Browse files

- Fixed syntax error at line 366 (missing method body)
- Restored _linear_chat implementation for fallback scenarios
- Preserved _generate_file_tree_str logic

Files changed (1) hide show
  1. code_chatbot/rag.py +24 -0
code_chatbot/rag.py CHANGED
@@ -363,6 +363,30 @@ class ChatEngine:
363
  return f"Error: {str(e)}", []
364
 
365
  def _linear_chat(self, question: str) -> Tuple[str, List[dict]]:
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
366
  def _generate_file_tree_str(self):
367
  """Generate a string representation of the file tree."""
368
  if not self.repo_files:
 
363
  return f"Error: {str(e)}", []
364
 
365
  def _linear_chat(self, question: str) -> Tuple[str, List[dict]]:
366
+ """Linear RAG fallback."""
367
+ messages, sources, _ = self._prepare_chat_context(question)
368
+
369
+ if not messages:
370
+ return "I don't have any information about this codebase. Please make sure the codebase has been indexed properly.", []
371
+
372
+ # Get response from LLM
373
+ try:
374
+ response_msg = self.llm.invoke(messages)
375
+ answer = response_msg.content
376
+ except Exception as e:
377
+ logger.error(f"Error in linear chat invoke: {e}")
378
+ return f"Error consuming LLM: {e}", []
379
+
380
+ # Update chat history
381
+ self.chat_history.append(HumanMessage(content=question))
382
+ self.chat_history.append(AIMessage(content=answer))
383
+
384
+ # Keep history manageable (last 20 messages)
385
+ if len(self.chat_history) > 20:
386
+ self.chat_history = self.chat_history[-20:]
387
+
388
+ return answer, sources
389
+
390
  def _generate_file_tree_str(self):
391
  """Generate a string representation of the file tree."""
392
  if not self.repo_files: