Asish Karthikeya Gogineni commited on
Commit
039d022
Β·
1 Parent(s): 8755993

chore: Remove unnecessary helper scripts

Browse files
app_multimode_integration.py DELETED
@@ -1,98 +0,0 @@
1
- """
2
- Enhanced app.py with multi-mode interface integration.
3
-
4
- This file adds the mode selector and conditional rendering.
5
- Add this code after line 520 in app.py (after the caption).
6
- """
7
-
8
- # Add this import at the top of app.py (around line 11)
9
- # from components.multi_mode import render_mode_selector, render_chat_mode, render_search_mode, render_refactor_mode, render_generate_mode
10
-
11
- # Replace lines 523-615 with this code:
12
-
13
- if not st.session_state.processed_files:
14
- st.info("πŸ‘ˆ Please upload and index a ZIP file to start.")
15
- else:
16
- # Get selected mode (defaults to chat)
17
- selected_mode = st.session_state.get("mode_selector", "πŸ’¬ Chat")
18
-
19
- # Only render chat interface in chat mode
20
- if selected_mode == "πŸ’¬ Chat":
21
- # Display History
22
- for msg in st.session_state.messages:
23
- with st.chat_message(msg["role"]):
24
- # Render Sources if available
25
- if "sources" in msg and msg["sources"]:
26
- unique_sources = {}
27
- for s in msg["sources"]:
28
- if isinstance(s, dict):
29
- fp = s.get('file_path', 'Unknown')
30
- else:
31
- fp = str(s)
32
- if fp not in unique_sources:
33
- unique_sources[fp] = s
34
-
35
- chips_html = '<div class="source-container" style="display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 10px;">'
36
- for fp in unique_sources:
37
- basename = os.path.basename(fp) if "/" in fp else fp
38
- chips_html += f"""
39
- <div class="source-chip" style="background: rgba(30, 41, 59, 0.4); border: 1px solid rgba(148, 163, 184, 0.2); border-radius: 6px; padding: 4px 10px; font-size: 0.85em; color: #cbd5e1; display: flex; align-items: center; gap: 6px;">
40
- <span class="source-icon">πŸ“„</span> {basename}
41
- </div>
42
- """
43
- chips_html += '</div>'
44
- st.markdown(chips_html, unsafe_allow_html=True)
45
-
46
- st.markdown(msg["content"], unsafe_allow_html=True)
47
-
48
- # Handle pending prompt from suggestions
49
- if "pending_prompt" in st.session_state and st.session_state.pending_prompt:
50
- prompt = st.session_state.pending_prompt
51
- st.session_state.pending_prompt = None
52
- else:
53
- prompt = st.chat_input("How does the authentication work?")
54
-
55
- if prompt:
56
- st.session_state.messages.append({"role": "user", "content": prompt})
57
- with st.chat_message("user"):
58
- st.markdown(prompt)
59
-
60
- with st.chat_message("assistant"):
61
- if st.session_state.chat_engine:
62
- with st.spinner("Analyzing (Graph+Vector)..."):
63
- answer_payload = st.session_state.chat_engine.chat(prompt)
64
-
65
- if isinstance(answer_payload, tuple):
66
- answer, sources = answer_payload
67
- else:
68
- answer = answer_payload
69
- sources = []
70
-
71
- if sources:
72
- unique_sources = {}
73
- for s in sources:
74
- fp = s.get('file_path', 'Unknown')
75
- if fp not in unique_sources:
76
- unique_sources[fp] = s
77
-
78
- chips_html = '<div class="source-container">'
79
- for fp in unique_sources:
80
- basename = os.path.basename(fp)
81
- chips_html += f"""
82
- <div class="source-chip">
83
- <span class="source-icon">πŸ“„</span> {basename}
84
- </div>
85
- """
86
- chips_html += '</div>'
87
- st.markdown(chips_html, unsafe_allow_html=True)
88
-
89
- st.markdown(answer)
90
-
91
- msg_data = {
92
- "role": "assistant",
93
- "content": answer,
94
- "sources": sources if sources else []
95
- }
96
- st.session_state.messages.append(msg_data)
97
- else:
98
- st.error("Chat engine not initialized. Please re-index.")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
demo_mcp_crewai.py DELETED
@@ -1,187 +0,0 @@
1
- """
2
- Demo script for MCP and CrewAI integration.
3
-
4
- Shows how to use the new refactoring and multi-agent capabilities.
5
- """
6
-
7
- import os
8
- import sys
9
- from pathlib import Path
10
-
11
- # Add project root to path
12
- sys.path.insert(0, str(Path(__file__).parent))
13
-
14
- from code_chatbot.mcp_client import MCPClient
15
- from code_chatbot.crews import RefactoringCrew, CodeReviewCrew
16
- from langchain_google_genai import ChatGoogleGenerativeAI
17
-
18
-
19
- def demo_mcp_search():
20
- """Demo: Search for code patterns using MCP"""
21
- print("\n" + "="*60)
22
- print("DEMO 1: MCP Code Search")
23
- print("="*60)
24
-
25
- # Create MCP client
26
- client = MCPClient(workspace_root=".")
27
-
28
- # Search for all class definitions
29
- print("\nπŸ” Searching for class definitions...")
30
- results = client.search_code(
31
- pattern=r"class\s+(\w+)",
32
- file_pattern="code_chatbot/*.py",
33
- context_lines=1
34
- )
35
-
36
- # Format and display results
37
- print(client.format_search_results(results, max_results=5))
38
-
39
-
40
- def demo_mcp_refactor():
41
- """Demo: Preview a refactoring using MCP"""
42
- print("\n" + "="*60)
43
- print("DEMO 2: MCP Code Refactoring (Dry Run)")
44
- print("="*60)
45
-
46
- # Create MCP client
47
- client = MCPClient(workspace_root=".")
48
-
49
- # Preview refactoring: print -> logger.info
50
- print("\nπŸ”§ Previewing refactoring: print() -> logger.info()...")
51
- result = client.refactor_code(
52
- search_pattern=r'print\((.*)\)',
53
- replace_pattern=r'logger.info(\1)',
54
- file_pattern="code_chatbot/mcp_*.py",
55
- dry_run=True # Preview only, don't apply
56
- )
57
-
58
- # Format and display result
59
- print(client.format_refactor_result(result))
60
-
61
-
62
- def demo_mcp_suggestions():
63
- """Demo: Get refactoring suggestions using MCP"""
64
- print("\n" + "="*60)
65
- print("DEMO 3: MCP Refactoring Suggestions")
66
- print("="*60)
67
-
68
- # Create MCP client
69
- client = MCPClient(workspace_root=".")
70
-
71
- # Get suggestions for a file
72
- print("\nπŸ’‘ Analyzing code_chatbot/mcp_server.py for refactoring opportunities...")
73
- suggestions = client.suggest_refactorings(
74
- file_path="code_chatbot/mcp_server.py",
75
- max_suggestions=3
76
- )
77
-
78
- # Format and display suggestions
79
- print(client.format_suggestions(suggestions))
80
-
81
-
82
- def demo_crewai_refactoring():
83
- """Demo: Use CrewAI multi-agent refactoring"""
84
- print("\n" + "="*60)
85
- print("DEMO 4: CrewAI Multi-Agent Refactoring")
86
- print("="*60)
87
-
88
- # Check for API key
89
- if not os.getenv("GOOGLE_API_KEY"):
90
- print("\n⚠️ Skipping CrewAI demo: GOOGLE_API_KEY not set")
91
- print(" Set your API key to run multi-agent workflows")
92
- return
93
-
94
- # Create LLM
95
- llm = ChatGoogleGenerativeAI(
96
- model="gemini-2.0-flash-exp",
97
- google_api_key=os.getenv("GOOGLE_API_KEY")
98
- )
99
-
100
- # Create refactoring crew
101
- print("\nπŸ€– Creating refactoring crew (Analyst + Refactor + Reviewer)...")
102
- crew = RefactoringCrew(llm=llm)
103
-
104
- # Run crew on a file
105
- print("\nπŸš€ Running crew on code_chatbot/mcp_client.py...")
106
- print(" (This may take 30-60 seconds...)\n")
107
-
108
- try:
109
- result = crew.run(file_path="code_chatbot/mcp_client.py")
110
-
111
- print("\nβœ… Crew execution complete!")
112
- print(f" Tasks completed: {result['tasks_completed']}")
113
- print(f"\nπŸ“‹ Result:\n{result['result']}")
114
-
115
- except Exception as e:
116
- print(f"\n❌ Crew execution failed: {e}")
117
-
118
-
119
- def demo_crewai_review():
120
- """Demo: Use CrewAI multi-agent code review"""
121
- print("\n" + "="*60)
122
- print("DEMO 5: CrewAI Multi-Agent Code Review")
123
- print("="*60)
124
-
125
- # Check for API key
126
- if not os.getenv("GOOGLE_API_KEY"):
127
- print("\n⚠️ Skipping CrewAI demo: GOOGLE_API_KEY not set")
128
- return
129
-
130
- # Create LLM
131
- llm = ChatGoogleGenerativeAI(
132
- model="gemini-2.0-flash-exp",
133
- google_api_key=os.getenv("GOOGLE_API_KEY")
134
- )
135
-
136
- # Create code review crew
137
- print("\nπŸ€– Creating code review crew (Analyst + Reviewer + Documentation)...")
138
- crew = CodeReviewCrew(llm=llm)
139
-
140
- # Run crew on a file
141
- print("\nπŸš€ Running crew on code_chatbot/mcp_server.py...")
142
- print(" (This may take 30-60 seconds...)\n")
143
-
144
- try:
145
- result = crew.run(file_path="code_chatbot/mcp_server.py")
146
-
147
- print("\nβœ… Crew execution complete!")
148
- print(f" Tasks completed: {result['tasks_completed']}")
149
- print(f"\nπŸ“‹ Result:\n{result['result']}")
150
-
151
- except Exception as e:
152
- print(f"\n❌ Crew execution failed: {e}")
153
-
154
-
155
- def main():
156
- """Run all demos"""
157
- print("\n" + "="*60)
158
- print("πŸš€ MCP + CrewAI Integration Demo")
159
- print("="*60)
160
- print("\nThis demo showcases:")
161
- print(" 1. MCP Code Search - Find patterns in your codebase")
162
- print(" 2. MCP Refactoring - Preview/apply code changes")
163
- print(" 3. MCP Suggestions - Get AI-powered refactoring ideas")
164
- print(" 4. CrewAI Refactoring - Multi-agent automated refactoring")
165
- print(" 5. CrewAI Code Review - Multi-agent code review")
166
-
167
- # Run MCP demos (no API key needed)
168
- demo_mcp_search()
169
- demo_mcp_refactor()
170
- demo_mcp_suggestions()
171
-
172
- # Run CrewAI demos (requires API key)
173
- demo_crewai_refactoring()
174
- demo_crewai_review()
175
-
176
- print("\n" + "="*60)
177
- print("βœ… Demo Complete!")
178
- print("="*60)
179
- print("\nNext steps:")
180
- print(" - Try the MCP tools in your own code")
181
- print(" - Customize agent roles and workflows")
182
- print(" - Integrate with Streamlit UI")
183
- print(" - Add more specialized agents")
184
-
185
-
186
- if __name__ == "__main__":
187
- main()
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
integrate_multimode.py DELETED
@@ -1,114 +0,0 @@
1
- #!/usr/bin/env python3
2
- """
3
- Quick integration script for multi-mode interface.
4
-
5
- This script will help you integrate the multi-mode interface into app.py.
6
- """
7
-
8
- import sys
9
-
10
- def show_integration_steps():
11
- """Display integration steps"""
12
-
13
- print("""
14
- ╔══════════════════════════════════════════════════════════════════════════╗
15
- β•‘ Multi-Mode Interface Integration β•‘
16
- β•šβ•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•
17
-
18
- βœ… Components Created:
19
- - components/multi_mode.py (Chat, Search, Refactor, Generate modes)
20
- - Verified imports work correctly
21
-
22
- πŸ“‹ Integration Steps:
23
-
24
- STEP 1: Add Import to app.py
25
- ────────────────────────────────────────────────────────────────────────────
26
- Add this import after line 11 in app.py:
27
-
28
- from components.multi_mode import (
29
- render_mode_selector,
30
- render_chat_mode,
31
- render_search_mode,
32
- render_refactor_mode,
33
- render_generate_mode
34
- )
35
-
36
-
37
- STEP 2: Add Mode Selector
38
- ────────────────────────────────────────────────────────────────────────────
39
- Replace lines 489-491 in app.py with:
40
-
41
- # Main Chat Interface
42
- st.title("πŸ•·οΈ Code Crawler")
43
-
44
- # Multi-Mode Interface
45
- if st.session_state.processed_files:
46
- selected_mode = render_mode_selector()
47
- st.divider()
48
-
49
- # Render appropriate interface based on mode
50
- if selected_mode == "search":
51
- render_search_mode()
52
- elif selected_mode == "refactor":
53
- render_refactor_mode()
54
- elif selected_mode == "generate":
55
- render_generate_mode(st.session_state.chat_engine)
56
- else: # chat mode
57
- render_chat_mode(st.session_state.chat_engine)
58
- st.caption(f"Ask questions about your uploaded project. (Using {provider}, Enhanced with AST)")
59
- else:
60
- st.caption(f"Configure and index your codebase to get started. (Using {provider}, Enhanced with AST)")
61
-
62
-
63
- STEP 3: Wrap Chat Interface
64
- ────────────────────────────────────────────────────────────────────────────
65
- Add this check before line 526 (before "# Display History"):
66
-
67
- # Only show chat history in chat mode
68
- selected_mode = st.session_state.get("mode_selector", "πŸ’¬ Chat")
69
- if selected_mode == "πŸ’¬ Chat":
70
-
71
-
72
- And indent all the chat code (lines 526-614) by 4 spaces.
73
-
74
-
75
- STEP 4: Test the Integration
76
- ────────────────────────────────────────────────────────────────────────────
77
- Run your Streamlit app:
78
-
79
- streamlit run app.py
80
-
81
- You should see:
82
- βœ… Mode selector with 4 buttons: πŸ’¬ Chat | πŸ” Search | πŸ”§ Refactor | ✨ Generate
83
- βœ… Chat mode works as before
84
- βœ… Search mode shows MCP code search interface
85
- βœ… Refactor mode shows MCP refactoring interface
86
- βœ… Generate mode shows CrewAI feature generation interface
87
-
88
-
89
- 🎯 Quick Test Commands:
90
- ────────────────────────────────────────────────────────────────────────────
91
- 1. Chat Mode: Ask "Explain how authentication works"
92
- 2. Search Mode: Pattern "class\\s+(\\w+)", File Pattern "**/*.py"
93
- 3. Refactor Mode: Search "print\\((.*)\)", Replace "logger.info(\\1)", Dry Run βœ“
94
- 4. Generate Mode: "Create a REST API endpoint for user management"
95
-
96
-
97
- πŸ“š Documentation:
98
- ────────────────────────────────────────────────────────────────────────────
99
- See the walkthrough for detailed usage:
100
- multimode_walkthrough.md
101
-
102
-
103
- πŸ’‘ Need Help?
104
- ────────────────────────────────────────────────────────────────────────────
105
- If you encounter issues:
106
- 1. Check that components/multi_mode.py exists
107
- 2. Verify imports work: python3 -c "from components.multi_mode import render_mode_selector"
108
- 3. Check Streamlit logs for errors
109
- 4. Ensure MCP and CrewAI dependencies are installed
110
-
111
- """)
112
-
113
- if __name__ == "__main__":
114
- show_integration_steps()