Update app.py
Browse files
app.py
CHANGED
|
@@ -1,320 +1,49 @@
|
|
| 1 |
-
|
| 2 |
-
import
|
| 3 |
-
|
| 4 |
-
|
| 5 |
-
|
| 6 |
-
|
| 7 |
-
|
| 8 |
-
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
|
| 29 |
-
|
| 30 |
-
|
| 31 |
-
|
| 32 |
-
|
| 33 |
-
|
| 34 |
-
|
| 35 |
-
|
| 36 |
-
|
| 37 |
-
|
| 38 |
-
|
| 39 |
-
|
| 40 |
-
|
| 41 |
-
|
| 42 |
-
if not model_info:
|
| 43 |
-
error_message = "Error: Model information not provided."
|
| 44 |
-
logging.error(error_message)
|
| 45 |
-
self.llm_model = None
|
| 46 |
-
self.llm_tokenizer = None
|
| 47 |
-
return
|
| 48 |
-
|
| 49 |
-
model_id = model_info.get('model_id')
|
| 50 |
-
model_name = model_info.get('name')
|
| 51 |
-
if not model_id:
|
| 52 |
-
error_message = f"Error: 'model_id' not found for model: {model_name}"
|
| 53 |
-
logging.error(error_message)
|
| 54 |
-
self.llm_model = None
|
| 55 |
-
self.llm_tokenizer = None
|
| 56 |
-
return
|
| 57 |
-
|
| 58 |
-
print(f"Loading model: {model_name} ({model_id}) with 4-bit quantization...") # Indicate quantization
|
| 59 |
-
try:
|
| 60 |
-
bnb_config = BitsAndBytesConfig( # Configure 4-bit quantization
|
| 61 |
-
load_in_4bit=True,
|
| 62 |
-
bnb_4bit_quant_type="nf4", # "nf4" is recommended for Llama models
|
| 63 |
-
bnb_4bit_compute_dtype=torch.bfloat16, # Or torch.float16 if bfloat16 not supported
|
| 64 |
-
)
|
| 65 |
-
self.llm_tokenizer = AutoTokenizer.from_pretrained(model_id)
|
| 66 |
-
self.llm_model = AutoModelForCausalLM.from_pretrained(
|
| 67 |
-
model_id,
|
| 68 |
-
device_map="auto",
|
| 69 |
-
quantization_config=bnb_config # Apply quantization config
|
| 70 |
-
)
|
| 71 |
-
print(f"Model {model_name} loaded successfully with 4-bit quantization.") # Indicate quantization success
|
| 72 |
-
except Exception as e:
|
| 73 |
-
error_message = f"Error loading model {model_name} ({model_id}) with 4-bit quantization: {e}"
|
| 74 |
-
logging.exception(error_message)
|
| 75 |
-
self.llm_model = None
|
| 76 |
-
self.llm_tokenizer = None
|
| 77 |
-
self.active_model_info = model_info
|
| 78 |
-
|
| 79 |
-
def switch_llm_model(self, model_key):
|
| 80 |
-
"""Switches the active LLM model based on the provided model key."""
|
| 81 |
-
if model_key in self.available_models_config:
|
| 82 |
-
model_info = self.available_models_config[model_key]
|
| 83 |
-
print(f"Switching LLM model to: {model_info.get('name')}")
|
| 84 |
-
self.load_llm_model(model_info)
|
| 85 |
-
self.active_model_key = model_key
|
| 86 |
-
return f"Switched to model: {model_info.get('name')}"
|
| 87 |
-
else:
|
| 88 |
-
error_message = f"Error: Model key '{model_key}' not found in available models."
|
| 89 |
-
logging.error(error_message)
|
| 90 |
-
return error_message
|
| 91 |
-
|
| 92 |
-
def enter_update_mode(self):
|
| 93 |
-
"""Enters the chatbot's update mode."""
|
| 94 |
-
self.update_mode_active = True
|
| 95 |
-
return "Entering update mode. Please enter configuration commands (or 'sagor is python/help' for commands)."
|
| 96 |
-
|
| 97 |
-
def exit_update_mode(self):
|
| 98 |
-
"""Exits the chatbot's update mode and reloads configuration."""
|
| 99 |
-
self.update_mode_active = False
|
| 100 |
-
self.reload_config()
|
| 101 |
-
return "Exiting update mode. Configuration reloaded."
|
| 102 |
-
|
| 103 |
-
def reload_config(self):
|
| 104 |
-
"""Reloads configuration files."""
|
| 105 |
-
print("Reloading configuration...")
|
| 106 |
-
try:
|
| 107 |
-
self.config_data = load_yaml_file(self.config_file)
|
| 108 |
-
self.roadmap_data = load_yaml_file(self.roadmap_file)
|
| 109 |
-
self.rules_data = load_yaml_file(self.rules_file)
|
| 110 |
-
self.chatbot_config = self.config_data.get('chatbot', {}) if self.config_data else {}
|
| 111 |
-
self.model_config = self.config_data.get('model_selection', {}) if self.config_data else {}
|
| 112 |
-
self.response_config = self.config_data.get('response_generation', {}) if self.config_data else {}
|
| 113 |
-
self.available_models_config = self.config_data.get('available_models', {}) if self.config_data else {}
|
| 114 |
-
self.max_response_tokens = self.chatbot_config.get('max_response_tokens', 200)
|
| 115 |
-
self.phases = get_roadmap_phases(self.roadmap_data)
|
| 116 |
-
self.rules = get_project_rules(self.rules_data)
|
| 117 |
-
print("Configuration reloaded.")
|
| 118 |
-
except Exception as e:
|
| 119 |
-
error_message = f"Error reloading configuration files: {e}"
|
| 120 |
-
logging.exception(error_message)
|
| 121 |
-
print(error_message)
|
| 122 |
-
|
| 123 |
-
def get_chatbot_greeting(self):
|
| 124 |
-
current_model_name = self.active_model_info.get('name', 'Unknown Model') if self.active_model_info else 'Unknown Model'
|
| 125 |
-
return f"Hello! I am the {self.chatbot_config.get('name', 'Project Guidance Chatbot')}. Currently using **{current_model_name}** (4-bit quantized). Max response tokens: {self.max_response_tokens}. {self.chatbot_config.get('description', 'How can I help you with your project?')}" # Indicate quantization in greeting
|
| 126 |
-
|
| 127 |
-
def generate_llm_response(self, user_query):
|
| 128 |
-
"""Generates a response using the currently active LLM."""
|
| 129 |
-
if not self.llm_model or not self.llm_tokenizer:
|
| 130 |
-
return "LLM model not loaded. Please select a model."
|
| 131 |
-
try:
|
| 132 |
-
inputs = self.llm_tokenizer(user_query, return_tensors="pt").to(self.llm_model.device)
|
| 133 |
-
outputs = self.llm_model.generate(**inputs, max_length=self.max_response_tokens, num_beams=5, no_repeat_ngram_size=2, early_stopping=True)
|
| 134 |
-
response = self.llm_tokenizer.decode(outputs[0], skip_special_tokens=True)
|
| 135 |
-
return response
|
| 136 |
-
except Exception as e:
|
| 137 |
-
print(f"Error generating LLM response: {e}")
|
| 138 |
-
return f"Error generating response from LLM: {e}"
|
| 139 |
-
|
| 140 |
-
def process_query(self, user_query):
|
| 141 |
-
secret_command_prefix = "sagor is python/"
|
| 142 |
-
|
| 143 |
-
if user_query.startswith(secret_command_prefix):
|
| 144 |
-
command = user_query[len(secret_command_prefix):].strip()
|
| 145 |
-
if command == "start":
|
| 146 |
-
return self.enter_update_mode()
|
| 147 |
-
elif command == "exit":
|
| 148 |
-
return self.exit_update_mode()
|
| 149 |
-
elif command == "help":
|
| 150 |
-
return self.get_update_mode_help()
|
| 151 |
-
elif self.update_mode_active:
|
| 152 |
-
parts = command.split()
|
| 153 |
-
if parts and parts[0] == "modify_rule":
|
| 154 |
-
if len(parts) >= 4:
|
| 155 |
-
category = parts[1]
|
| 156 |
-
rule_key = parts[2]
|
| 157 |
-
new_rule_text_parts = parts[3:]
|
| 158 |
-
new_rule_text = " ".join(new_rule_text_parts)
|
| 159 |
-
return self.modify_rule_in_config(category, rule_key, new_rule_text)
|
| 160 |
-
else:
|
| 161 |
-
return "Invalid 'modify_rule' command format. Usage: modify_rule <category> <rule_key> <new rule text>"
|
| 162 |
-
elif parts and parts[0] == "add_phase":
|
| 163 |
-
return "Command 'add_phase' is not yet implemented in this example."
|
| 164 |
-
else:
|
| 165 |
-
return f"Unknown update command: {command}. Type 'sagor is python/help' for commands."
|
| 166 |
-
else:
|
| 167 |
-
return f"Unknown command (not in update mode): {command}. To enter update mode, type 'sagor is python/start'."
|
| 168 |
-
|
| 169 |
-
if self.update_mode_active:
|
| 170 |
-
return "In update mode. Please enter a configuration command (or 'sagor is python/help' for commands)."
|
| 171 |
-
|
| 172 |
-
if not self.phases:
|
| 173 |
-
return "Error: Roadmap data not loaded correctly."
|
| 174 |
-
if not self.rules:
|
| 175 |
-
return "Error: Rules data not loaded correctly."
|
| 176 |
-
|
| 177 |
-
query_lower = user_query.lower()
|
| 178 |
-
|
| 179 |
-
if "roadmap" in query_lower:
|
| 180 |
-
return self.get_roadmap_summary()
|
| 181 |
-
if "rules" in query_lower:
|
| 182 |
-
return self.get_rules_summary()
|
| 183 |
-
if "switch model to" in query_lower:
|
| 184 |
-
parts = user_query.lower().split("switch model to")
|
| 185 |
-
if len(parts) > 1:
|
| 186 |
-
model_name_or_key = parts[1].strip()
|
| 187 |
-
for key, model_data in self.available_models_config.items():
|
| 188 |
-
if model_data['name'].lower() == model_name_or_key.lower() or key.lower() == model_name_or_key.lower():
|
| 189 |
-
switch_result = self.switch_llm_model(key)
|
| 190 |
-
return switch_result + "\n" + self.get_chatbot_greeting()
|
| 191 |
-
return f"Model '{model_name_or_key}' not found in available models."
|
| 192 |
-
|
| 193 |
-
if self.current_phase:
|
| 194 |
-
current_phase_data = self.phases.get(self.current_phase)
|
| 195 |
-
if current_phase_data:
|
| 196 |
-
phase_response = self.get_phase_guidance(current_phase_data, user_query)
|
| 197 |
-
if phase_response:
|
| 198 |
-
return phase_response
|
| 199 |
-
|
| 200 |
-
for phase_key, phase_data in self.phases.items():
|
| 201 |
-
if phase_data['name'].lower() in query_lower:
|
| 202 |
-
self.current_phase = phase_key
|
| 203 |
-
return self.get_phase_introduction(phase_data)
|
| 204 |
-
|
| 205 |
-
llm_response = self.generate_llm_response(user_query)
|
| 206 |
-
if llm_response:
|
| 207 |
-
return llm_response
|
| 208 |
-
|
| 209 |
-
return self.response_config.get('default_instruction', "How can I help you with your project phases or general questions?")
|
| 210 |
-
|
| 211 |
-
def get_update_mode_help(self):
|
| 212 |
-
"""Provides help message for update mode commands."""
|
| 213 |
-
help_message = "Update Mode Commands:\n"
|
| 214 |
-
help_message += "- `sagor is python/exit`: Exit update mode and reload configuration.\n"
|
| 215 |
-
help_message += "- `sagor is python/modify_rule <category> <rule_key> <new rule text>`: Modify a rule in rules.yaml.\n"
|
| 216 |
-
help_message += " Example: `sagor is python/modify_rule general rule_1 Prioritize open and responsible AI.`\n"
|
| 217 |
-
help_message += "- `sagor is python/add_phase ...`: (Not yet implemented) Add a new phase to roadmap.yaml.\n"
|
| 218 |
-
help_message += "- `sagor is python/help`: Show this help message.\n"
|
| 219 |
-
help_message += "\nMake sure to use the correct syntax for commands. After exiting update mode, the chatbot will reload the configuration."
|
| 220 |
-
return help_message
|
| 221 |
-
|
| 222 |
-
def modify_rule_in_config(self, category, rule_key, new_rule_text):
|
| 223 |
-
"""Modifies a rule in the rules.yaml configuration."""
|
| 224 |
-
if not self.rules_data or 'project_rules' not in self.rules_data:
|
| 225 |
-
error_message = "Error: Rules data not loaded or invalid format."
|
| 226 |
-
logging.error(error_message)
|
| 227 |
-
return error_message
|
| 228 |
-
if category not in self.rules_data['project_rules']:
|
| 229 |
-
error_message = f"Error: Rule category '{category}' not found."
|
| 230 |
-
logging.error(error_message)
|
| 231 |
-
return error_message
|
| 232 |
-
if rule_key not in self.rules_data['project_rules'][category]:
|
| 233 |
-
error_message = f"Error: Rule key '{rule_key}' not found in category '{category}'."
|
| 234 |
-
logging.error(error_message)
|
| 235 |
-
return error_message
|
| 236 |
-
|
| 237 |
-
self.rules_data['project_rules'][category][rule_key] = new_rule_text
|
| 238 |
-
|
| 239 |
-
try:
|
| 240 |
-
with open(self.rules_file, 'w') as f:
|
| 241 |
-
yaml.dump(self.rules_data, f, indent=2)
|
| 242 |
-
self.reload_config()
|
| 243 |
-
return f"Rule '{rule_key}' in category '{category}' updated to: '{new_rule_text}'. Configuration reloaded."
|
| 244 |
-
except Exception as e:
|
| 245 |
-
error_message = f"Error saving changes to {self.rules_file}: {e}"
|
| 246 |
-
logging.exception(error_message)
|
| 247 |
-
return error_message
|
| 248 |
-
|
| 249 |
-
def get_roadmap_summary(self):
|
| 250 |
-
summary = "Project Roadmap:\n"
|
| 251 |
-
for phase_key, phase_data in self.phases.items():
|
| 252 |
-
summary += f"- **Phase: {phase_data['name']}**\n"
|
| 253 |
-
summary += f" Description: {phase_data['description']}\n"
|
| 254 |
-
summary += f" Milestones: {', '.join(phase_data['milestones'])}\n"
|
| 255 |
-
return summary
|
| 256 |
-
|
| 257 |
-
def get_rules_summary(self):
|
| 258 |
-
summary = "Project Rules:\n"
|
| 259 |
-
for rule_category, rules_list in self.rules.items():
|
| 260 |
-
summary += f"**{rule_category.capitalize()} Rules:**\n"
|
| 261 |
-
for rule_key, rule_text in rules_list.items():
|
| 262 |
-
summary += f"- {rule_text}\n"
|
| 263 |
-
return summary
|
| 264 |
-
|
| 265 |
-
def get_phase_introduction(self, phase_data):
|
| 266 |
-
return f"Okay, let's focus on **Phase: {phase_data['name']}**. \nDescription: {phase_data['description']}. \nKey milestones are: {', '.join(phase_data['milestones'])}. \nWhat would you like to know or do in this phase?"
|
| 267 |
-
|
| 268 |
-
def get_phase_guidance(self, phase_data, user_query):
|
| 269 |
-
query_lower = user_query.lower()
|
| 270 |
-
|
| 271 |
-
if "milestones" in query_lower:
|
| 272 |
-
return "The milestones for this phase are: " + ", ".join(phase_data['milestones'])
|
| 273 |
-
if "actions" in query_lower or "how to" in query_lower:
|
| 274 |
-
if 'actions' in phase_data:
|
| 275 |
-
return "Recommended actions for this phase: " + ", ".join(phase_data['actions'])
|
| 276 |
-
else:
|
| 277 |
-
return "No specific actions are listed for this phase in the roadmap."
|
| 278 |
-
if "code" in query_lower or "script" in query_lower:
|
| 279 |
-
if 'code_generation_hint' in phase_data:
|
| 280 |
-
template_filename_prefix = phase_data['name'].lower().replace(" ", "_")
|
| 281 |
-
template_filepath = os.path.join(self.code_templates_dir, f"{template_filename_prefix}_template.py.txt")
|
| 282 |
-
if os.path.exists(template_filepath):
|
| 283 |
-
code_snippet = self.generate_code_snippet(template_filepath, phase_data)
|
| 284 |
-
return "Here's a starting code snippet for this phase:\n\n```python\n" + code_snippet + "\n```\n\nRemember to adapt it to your specific needs."
|
| 285 |
-
else:
|
| 286 |
-
return f"A code template for this phase ({phase_data['name']}) is not yet available. However, the hint is: {phase_data['code_generation_hint']}"
|
| 287 |
-
else:
|
| 288 |
-
return "No code generation hint is available for this phase."
|
| 289 |
-
|
| 290 |
-
return f"For phase '{phase_data['name']}', remember the description: {phase_data['description']}. Consider the milestones and actions. What specific aspect are you interested in?"
|
| 291 |
-
|
| 292 |
-
def generate_code_snippet(self, template_filepath, phase_data):
|
| 293 |
-
"""Generates code snippet from a template file. (Simple template filling example)"""
|
| 294 |
-
try:
|
| 295 |
-
with open(template_filepath, 'r') as f:
|
| 296 |
-
template_content = f.read()
|
| 297 |
|
| 298 |
-
|
| 299 |
-
|
| 300 |
-
|
| 301 |
-
return f"Error: Code template file not found at {template_filepath}"
|
| 302 |
-
except Exception as e:
|
| 303 |
-
return f"Error generating code snippet: {e}"
|
| 304 |
|
| 305 |
-
|
| 306 |
-
if __name__ == '__main__':
|
| 307 |
-
chatbot = ProjectGuidanceChatbot(
|
| 308 |
-
roadmap_file="roadmap.yaml",
|
| 309 |
-
rules_file="rules.yaml",
|
| 310 |
-
config_file="configs/chatbot_config.yaml",
|
| 311 |
-
code_templates_dir="scripts/code_templates"
|
| 312 |
-
)
|
| 313 |
-
print(chatbot.get_chatbot_greeting())
|
| 314 |
|
| 315 |
-
|
| 316 |
-
user_input = input("You: ")
|
| 317 |
-
if user_input.lower() == "exit":
|
| 318 |
-
break
|
| 319 |
-
response = chatbot.process_query(user_input)
|
| 320 |
-
print("Chatbot:", response)
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
from scripts.chatbot_logic import ProjectGuidanceChatbot
|
| 3 |
+
|
| 4 |
+
# Initialize Chatbot
|
| 5 |
+
chatbot = ProjectGuidanceChatbot(
|
| 6 |
+
roadmap_file="roadmap.yaml",
|
| 7 |
+
rules_file="rules.yaml",
|
| 8 |
+
config_file="configs/chatbot_config.yaml",
|
| 9 |
+
code_templates_dir="scripts/code_templates"
|
| 10 |
+
)
|
| 11 |
+
|
| 12 |
+
def respond(message, chat_history):
|
| 13 |
+
bot_message = chatbot.process_query(message)
|
| 14 |
+
chat_history.append((message, bot_message))
|
| 15 |
+
return "", chat_history
|
| 16 |
+
|
| 17 |
+
def switch_model(model_key):
|
| 18 |
+
model_switch_result = chatbot.switch_llm_model(model_key) # Get result message
|
| 19 |
+
greeting_message = chatbot.get_chatbot_greeting()
|
| 20 |
+
|
| 21 |
+
if isinstance(model_switch_result, str) and "Error:" in model_switch_result: # Check if result is an error string
|
| 22 |
+
return gr.Warning(model_switch_result), greeting_message # Display error as Gradio Warning
|
| 23 |
+
else:
|
| 24 |
+
return None, greeting_message # No warning, just update greeting
|
| 25 |
+
|
| 26 |
+
with gr.Blocks() as demo:
|
| 27 |
+
chatbot_greeting_md = gr.Markdown(chatbot.get_chatbot_greeting())
|
| 28 |
+
gr.Markdown(f"# {chatbot.chatbot_config.get('name', 'Project Guidance Chatbot')}")
|
| 29 |
+
|
| 30 |
+
model_choices = [(model['name'], key) for key, model in chatbot.available_models_config.items()] # Updated choices to include FLAN-T5 and Gemini
|
| 31 |
+
model_dropdown = gr.Dropdown(
|
| 32 |
+
choices=model_choices,
|
| 33 |
+
value=chatbot.active_model_info['name'] if chatbot.active_model_info else None,
|
| 34 |
+
label="Select LLM Model"
|
| 35 |
+
)
|
| 36 |
+
model_error_output = gr.Warning(visible=False) # Initially hidden warning component
|
| 37 |
+
model_dropdown.change(
|
| 38 |
+
fn=switch_model,
|
| 39 |
+
inputs=model_dropdown,
|
| 40 |
+
outputs=[model_error_output, chatbot_greeting_md] # Output both warning and greeting
|
| 41 |
+
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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