Commit
·
e2e1d2d
1
Parent(s):
db8ad4d
Remove historical requirement files and chatbot configuration scripts
Browse files- .history/.gitattributes_20250202080908 +0 -35
- .history/.gitattributes_20250202080959 +0 -36
- .history/app_20250202080908.py +0 -57
- .history/app_20250202080935.py +0 -57
- .history/configs/chatbot_config_20250202080908.yaml +24 -0
- .history/configs/chatbot_config_20250202081215.yaml +24 -0
- .history/requirements_20250202080908.txt +0 -4
- .history/requirements_20250202081148.txt +0 -5
- .history/requirements_20250202081149.txt +0 -5
- .history/requirements_20250202081150.txt +0 -5
- .history/{requirements_20250202081153.txt → requirements_20250202083728.txt} +2 -1
- .history/rules_20250202080908.yaml +0 -78
- .history/rules_20250202081028.yaml +0 -78
- .history/rules_20250202081029.yaml +0 -78
- .history/scripts/{chatbot_logic_20250202080908.py → chatbot_logic_20250202080927.py} +0 -0
- .history/scripts/{chatbot_logic_20250202080928.py → chatbot_logic_20250202083642.py} +50 -54
- requirements.txt +2 -1
- scripts/chatbot_logic.py +50 -54
.history/.gitattributes_20250202080908
DELETED
|
@@ -1,35 +0,0 @@
|
|
| 1 |
-
*.7z filter=lfs diff=lfs merge=lfs -text
|
| 2 |
-
*.arrow filter=lfs diff=lfs merge=lfs -text
|
| 3 |
-
*.bin filter=lfs diff=lfs merge=lfs -text
|
| 4 |
-
*.bz2 filter=lfs diff=lfs merge=lfs -text
|
| 5 |
-
*.ckpt filter=lfs diff=lfs merge=lfs -text
|
| 6 |
-
*.ftz filter=lfs diff=lfs merge=lfs -text
|
| 7 |
-
*.gz filter=lfs diff=lfs merge=lfs -text
|
| 8 |
-
*.h5 filter=lfs diff=lfs merge=lfs -text
|
| 9 |
-
*.joblib filter=lfs diff=lfs merge=lfs -text
|
| 10 |
-
*.lfs.* filter=lfs diff=lfs merge=lfs -text
|
| 11 |
-
*.mlmodel filter=lfs diff=lfs merge=lfs -text
|
| 12 |
-
*.model filter=lfs diff=lfs merge=lfs -text
|
| 13 |
-
*.msgpack filter=lfs diff=lfs merge=lfs -text
|
| 14 |
-
*.npy filter=lfs diff=lfs merge=lfs -text
|
| 15 |
-
*.npz filter=lfs diff=lfs merge=lfs -text
|
| 16 |
-
*.onnx filter=lfs diff=lfs merge=lfs -text
|
| 17 |
-
*.ot filter=lfs diff=lfs merge=lfs -text
|
| 18 |
-
*.parquet filter=lfs diff=lfs merge=lfs -text
|
| 19 |
-
*.pb filter=lfs diff=lfs merge=lfs -text
|
| 20 |
-
*.pickle filter=lfs diff=lfs merge=lfs -text
|
| 21 |
-
*.pkl filter=lfs diff=lfs merge=lfs -text
|
| 22 |
-
*.pt filter=lfs diff=lfs merge=lfs -text
|
| 23 |
-
*.pth filter=lfs diff=lfs merge=lfs -text
|
| 24 |
-
*.rar filter=lfs diff=lfs merge=lfs -text
|
| 25 |
-
*.safetensors filter=lfs diff=lfs merge=lfs -text
|
| 26 |
-
saved_model/**/* filter=lfs diff=lfs merge=lfs -text
|
| 27 |
-
*.tar.* filter=lfs diff=lfs merge=lfs -text
|
| 28 |
-
*.tar filter=lfs diff=lfs merge=lfs -text
|
| 29 |
-
*.tflite filter=lfs diff=lfs merge=lfs -text
|
| 30 |
-
*.tgz filter=lfs diff=lfs merge=lfs -text
|
| 31 |
-
*.wasm filter=lfs diff=lfs merge=lfs -text
|
| 32 |
-
*.xz filter=lfs diff=lfs merge=lfs -text
|
| 33 |
-
*.zip filter=lfs diff=lfs merge=lfs -text
|
| 34 |
-
*.zst filter=lfs diff=lfs merge=lfs -text
|
| 35 |
-
*tfevents* filter=lfs diff=lfs merge=lfs -text
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
.history/.gitattributes_20250202080959
DELETED
|
@@ -1,36 +0,0 @@
|
|
| 1 |
-
*.7z filter=lfs diff=lfs merge=lfs -text
|
| 2 |
-
*.arrow filter=lfs diff=lfs merge=lfs -text
|
| 3 |
-
*.bin filter=lfs diff=lfs merge=lfs -text
|
| 4 |
-
*.bz2 filter=lfs diff=lfs merge=lfs -text
|
| 5 |
-
*.ckpt filter=lfs diff=lfs merge=lfs -text
|
| 6 |
-
*.ftz filter=lfs diff=lfs merge=lfs -text
|
| 7 |
-
*.gz filter=lfs diff=lfs merge=lfs -text
|
| 8 |
-
*.h5 filter=lfs diff=lfs merge=lfs -text
|
| 9 |
-
*.joblib filter=lfs diff=lfs merge=lfs -text
|
| 10 |
-
*.lfs.* filter=lfs diff=lfs merge=lfs -text
|
| 11 |
-
*.mlmodel filter=lfs diff=lfs merge=lfs -text
|
| 12 |
-
*.model filter=lfs diff=lfs merge=lfs -text
|
| 13 |
-
*.msgpack filter=lfs diff=lfs merge=lfs -text
|
| 14 |
-
*.npy filter=lfs diff=lfs merge=lfs -text
|
| 15 |
-
*.npz filter=lfs diff=lfs merge=lfs -text
|
| 16 |
-
*.onnx filter=lfs diff=lfs merge=lfs -text
|
| 17 |
-
*.ot filter=lfs diff=lfs merge=lfs -text
|
| 18 |
-
*.parquet filter=lfs diff=lfs merge=lfs -text
|
| 19 |
-
*.pb filter=lfs diff=lfs merge=lfs -text
|
| 20 |
-
*.pickle filter=lfs diff=lfs merge=lfs -text
|
| 21 |
-
*.pkl filter=lfs diff=lfs merge=lfs -text
|
| 22 |
-
*.pt filter=lfs diff=lfs merge=lfs -text
|
| 23 |
-
*.pth filter=lfs diff=lfs merge=lfs -text
|
| 24 |
-
*.rar filter=lfs diff=lfs merge=lfs -text
|
| 25 |
-
*.safetensors filter=lfs diff=lfs merge=lfs -text
|
| 26 |
-
saved_model/**/* filter=lfs diff=lfs merge=lfs -text
|
| 27 |
-
*.tar.* filter=lfs diff=lfs merge=lfs -text
|
| 28 |
-
*.tar filter=lfs diff=lfs merge=lfs -text
|
| 29 |
-
*.tflite filter=lfs diff=lfs merge=lfs -text
|
| 30 |
-
*.tgz filter=lfs diff=lfs merge=lfs -text
|
| 31 |
-
*.wasm filter=lfs diff=lfs merge=lfs -text
|
| 32 |
-
*.xz filter=lfs diff=lfs merge=lfs -text
|
| 33 |
-
*.zip filter=lfs diff=lfs merge=lfs -text
|
| 34 |
-
*.zst filter=lfs diff=lfs merge=lfs -text
|
| 35 |
-
*tfevents* filter=lfs diff=lfs merge=lfs -text
|
| 36 |
-
.history filter=lfs diff=lfs merge=lfs -text
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
.history/app_20250202080908.py
DELETED
|
@@ -1,57 +0,0 @@
|
|
| 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 |
-
def respond(message, chat_history):
|
| 27 |
-
bot_message = chatbot.process_query(message)
|
| 28 |
-
chat_history.append((message, bot_message))
|
| 29 |
-
if isinstance(bot_message, str) and "Error:" in bot_message: # Check if bot_message is an error string
|
| 30 |
-
return gr.Warning(bot_message), chat_history # Display error as Gradio Warning
|
| 31 |
-
else:
|
| 32 |
-
return "", chat_history # No warning, normal response
|
| 33 |
-
|
| 34 |
-
with gr.Blocks() as demo:
|
| 35 |
-
chatbot_greeting_md = gr.Markdown(chatbot.get_chatbot_greeting())
|
| 36 |
-
gr.Markdown(f"# {chatbot.chatbot_config.get('name', 'Project Guidance Chatbot')}")
|
| 37 |
-
|
| 38 |
-
model_choices = [(model['name'], key) for key, model in chatbot.available_models_config.items()]
|
| 39 |
-
model_dropdown = gr.Dropdown(
|
| 40 |
-
choices=model_choices,
|
| 41 |
-
value=chatbot.active_model_info['name'] if chatbot.active_model_info else None,
|
| 42 |
-
label="Select LLM Model"
|
| 43 |
-
)
|
| 44 |
-
model_error_output = gr.Warning(visible=False) # Initially hidden warning component
|
| 45 |
-
model_dropdown.change(
|
| 46 |
-
fn=switch_model,
|
| 47 |
-
inputs=model_dropdown,
|
| 48 |
-
outputs=[model_error_output, chatbot_greeting_md] # Output both warning and greeting
|
| 49 |
-
)
|
| 50 |
-
|
| 51 |
-
chatbot_ui = gr.Chatbot()
|
| 52 |
-
msg = gr.Textbox()
|
| 53 |
-
clear = gr.ClearButton([msg, chatbot_ui])
|
| 54 |
-
|
| 55 |
-
msg.submit(respond, [msg, chatbot_ui], [msg, chatbot_ui])
|
| 56 |
-
|
| 57 |
-
demo.launch()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
.history/app_20250202080935.py
DELETED
|
@@ -1,57 +0,0 @@
|
|
| 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 |
-
def respond(message, chat_history):
|
| 27 |
-
bot_message = chatbot.process_query(message)
|
| 28 |
-
chat_history.append((message, bot_message))
|
| 29 |
-
if isinstance(bot_message, str) and "Error:" in bot_message: # Check if bot_message is an error string
|
| 30 |
-
return gr.Warning(bot_message), chat_history # Display error as Gradio Warning
|
| 31 |
-
else:
|
| 32 |
-
return "", chat_history # No warning, normal response
|
| 33 |
-
|
| 34 |
-
with gr.Blocks() as demo:
|
| 35 |
-
chatbot_greeting_md = gr.Markdown(chatbot.get_chatbot_greeting())
|
| 36 |
-
gr.Markdown(f"# {chatbot.chatbot_config.get('name', 'Project Guidance Chatbot')}")
|
| 37 |
-
|
| 38 |
-
model_choices = [(model['name'], key) for key, model in chatbot.available_models_config.items()]
|
| 39 |
-
model_dropdown = gr.Dropdown(
|
| 40 |
-
choices=model_choices,
|
| 41 |
-
value=chatbot.active_model_info['name'] if chatbot.active_model_info else None,
|
| 42 |
-
label="Select LLM Model"
|
| 43 |
-
)
|
| 44 |
-
model_error_output = gr.Warning(visible=False) # Initially hidden warning component
|
| 45 |
-
model_dropdown.change(
|
| 46 |
-
fn=switch_model,
|
| 47 |
-
inputs=model_dropdown,
|
| 48 |
-
outputs=[model_error_output, chatbot_greeting_md] # Output both warning and greeting
|
| 49 |
-
)
|
| 50 |
-
|
| 51 |
-
chatbot_ui = gr.Chatbot()
|
| 52 |
-
msg = gr.Textbox()
|
| 53 |
-
clear = gr.ClearButton([msg, chatbot_ui])
|
| 54 |
-
|
| 55 |
-
msg.submit(respond, [msg, chatbot_ui], [msg, chatbot_ui])
|
| 56 |
-
|
| 57 |
-
demo.launch()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
.history/configs/chatbot_config_20250202080908.yaml
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
chatbot:
|
| 2 |
+
name: "Project Guidance Chatbot"
|
| 3 |
+
description: "Your helpful AI assistant for project completion with LLM selection and token control."
|
| 4 |
+
default_llm_model_id: "deepseek-r1-distill-llama-8b"
|
| 5 |
+
max_response_tokens: 200 # Maximum tokens for LLM generated responses
|
| 6 |
+
|
| 7 |
+
available_models:
|
| 8 |
+
deepseek-r1-distill-llama-8b:
|
| 9 |
+
name: "DeepSeek-R1-Distill-Llama-8B"
|
| 10 |
+
model_id: "DeepSeek-AI/DeepSeek-R1-Distill-Llama-8B"
|
| 11 |
+
gemini-flash-01-21: # Using a shorter key for easier referencing in code
|
| 12 |
+
name: "Gemini 2.0 Flash (Exp 01-21)"
|
| 13 |
+
model_id: "google/gemini-2.0-flash-thinking-exp-01-21"
|
| 14 |
+
|
| 15 |
+
model_selection:
|
| 16 |
+
suggested_models: # (Keep suggested models - might be useful later)
|
| 17 |
+
- "mistralai/Mistral-7B-Instruct-v0.2"
|
| 18 |
+
- "google/flan-t5-xl"
|
| 19 |
+
- "facebook/bart-large"
|
| 20 |
+
criteria_prompt: "Consider these criteria when selecting a model: {rules.model_selection}"
|
| 21 |
+
|
| 22 |
+
response_generation:
|
| 23 |
+
error_message: "Sorry, I encountered an issue. Please check your input and project files."
|
| 24 |
+
default_instruction: "How can I help you with your project?"
|
.history/configs/chatbot_config_20250202081215.yaml
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
chatbot:
|
| 2 |
+
name: "Project Guidance Chatbot"
|
| 3 |
+
description: "Your helpful AI assistant for project completion with LLM selection and token control."
|
| 4 |
+
default_llm_model_id: "deepseek-r1-distill-llama-8b"
|
| 5 |
+
max_response_tokens: 200 # Maximum tokens for LLM generated responses
|
| 6 |
+
|
| 7 |
+
available_models:
|
| 8 |
+
deepseek-r1-distill-llama-8b:
|
| 9 |
+
name: "DeepSeek-R1-Distill-Llama-8B"
|
| 10 |
+
model_id: "DeepSeek-AI/DeepSeek-R1-Distill-Llama-8B"
|
| 11 |
+
gemini-flash-01-21: # Using a shorter key for easier referencing in code
|
| 12 |
+
name: "Gemini 2.0 Flash (Exp 01-21)"
|
| 13 |
+
model_id: "google/gemini-2.0-flash-thinking-exp-01-21"
|
| 14 |
+
|
| 15 |
+
model_selection:
|
| 16 |
+
suggested_models: # (Keep suggested models - might be useful later)
|
| 17 |
+
- "mistralai/Mistral-7B-Instruct-v0.2"
|
| 18 |
+
- "google/flan-t5-xl"
|
| 19 |
+
- "facebook/bart-large"
|
| 20 |
+
criteria_prompt: "Consider these criteria when selecting a model: {rules.model_selection}"
|
| 21 |
+
|
| 22 |
+
response_generation:
|
| 23 |
+
error_message: "Sorry, I encountered an issue. Please check your input and project files."
|
| 24 |
+
default_instruction: "How can I help you with your project?"
|
.history/requirements_20250202080908.txt
DELETED
|
@@ -1,4 +0,0 @@
|
|
| 1 |
-
gradio
|
| 2 |
-
PyYAML
|
| 3 |
-
transformers
|
| 4 |
-
torch
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
.history/requirements_20250202081148.txt
DELETED
|
@@ -1,5 +0,0 @@
|
|
| 1 |
-
gradio
|
| 2 |
-
PyYAML
|
| 3 |
-
transformers
|
| 4 |
-
torch
|
| 5 |
-
accelerate>=0.26.0
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
.history/requirements_20250202081149.txt
DELETED
|
@@ -1,5 +0,0 @@
|
|
| 1 |
-
gradio
|
| 2 |
-
PyYAML
|
| 3 |
-
transformers
|
| 4 |
-
torch
|
| 5 |
-
accelerate>=0.26.0
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
.history/requirements_20250202081150.txt
DELETED
|
@@ -1,5 +0,0 @@
|
|
| 1 |
-
gradio
|
| 2 |
-
PyYAML
|
| 3 |
-
transformers
|
| 4 |
-
torch
|
| 5 |
-
accelerate>=0.26.0
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
.history/{requirements_20250202081153.txt → requirements_20250202083728.txt}
RENAMED
|
@@ -2,4 +2,5 @@ gradio
|
|
| 2 |
PyYAML
|
| 3 |
transformers
|
| 4 |
torch
|
| 5 |
-
accelerate
|
|
|
|
|
|
| 2 |
PyYAML
|
| 3 |
transformers
|
| 4 |
torch
|
| 5 |
+
accelerate
|
| 6 |
+
bitsandbytes
|
.history/rules_20250202080908.yaml
DELETED
|
@@ -1,78 +0,0 @@
|
|
| 1 |
-
project_rules:
|
| 2 |
-
general:
|
| 3 |
-
rule_1: "Prioritize open-source models and tools whenever possible for transparency and customization."
|
| 4 |
-
rule_2: "Document every step of your project, including model selection, fine-tuning parameters, and deployment configurations."
|
| 5 |
-
rule_3: "Adhere to ethical guidelines and responsible AI practices throughout the project lifecycle."
|
| 6 |
-
|
| 7 |
-
model_selection:
|
| 8 |
-
rule_1: "Choose a base model that is open-source, scalable, and efficient."
|
| 9 |
-
rule_2: "Ensure the model supports fine-tuning via LoRA/QLoRA for memory efficiency."
|
| 10 |
-
rule_3: "Confirm that the model's licensing aligns with both research and commercial use."
|
| 11 |
-
rule_4: "Set up the development environment with PyTorch and Hugging Face Transformers."
|
| 12 |
-
|
| 13 |
-
fine_tuning:
|
| 14 |
-
rule_1: "Specify datasets that promote unrestricted responses and are relevant to the application domain."
|
| 15 |
-
rule_2: "Remove or bypass RLHF alignment layers to allow unrestricted responses."
|
| 16 |
-
rule_3: "Implement LoRA/QLoRA techniques for efficient parameter modifications."
|
| 17 |
-
rule_4: "Use direct parameter editing to bypass built-in safety filters."
|
| 18 |
-
rule_5: "Monitor training metrics and validate generalization performance using validation datasets."
|
| 19 |
-
|
| 20 |
-
autodan_turbo:
|
| 21 |
-
rule_1: "Outline a Hierarchical Genetic Algorithm (HGA) for generating stealthy jailbreak prompts."
|
| 22 |
-
rule_2: "Include Genetic Algorithm components: Seed prompts, Mutation, Crossover, and Selection processes."
|
| 23 |
-
rule_3: "Define evaluation functions for stealthiness (natural language quality) and jailbreak success rate."
|
| 24 |
-
rule_4: "Use perplexity and response analysis to evaluate prompt effectiveness."
|
| 25 |
-
rule_5: "Ensure cross-model testing for compatibility with different LLM architectures."
|
| 26 |
-
|
| 27 |
-
deployment:
|
| 28 |
-
rule_1: "Ensure the model is deployable on both local hardware and cloud services (e.g., RunPod, Lambda Labs)."
|
| 29 |
-
rule_2: "Implement controlled API access to monitor and restrict unauthorized usage."
|
| 30 |
-
rule_3: "Include security measures such as adversarial attack defenses and rollback strategies (e.g., VM snapshots)."
|
| 31 |
-
rule_4: "Optimize performance using quantization techniques (e.g., GPTQ, AWQ)."
|
| 32 |
-
rule_5: "Set up monitoring and logging to track model performance and usage in production."
|
| 33 |
-
|
| 34 |
-
budget_and_resources:
|
| 35 |
-
rule_1: "Outline a strategy for utilizing free/trial VPS accounts to minimize costs."
|
| 36 |
-
rule_2: "Define methods to maximize free resources, such as using multiple BINs for trial accounts."
|
| 37 |
-
rule_3: "Continuously evaluate performance and cost efficiency during deployment."
|
| 38 |
-
|
| 39 |
-
creativity_and_innovation:
|
| 40 |
-
rule_1: "Position the LLM as a tool for unrestricted ideation, coding, and research."
|
| 41 |
-
rule_2: "Support AI integration in programming environments for rapid prototyping."
|
| 42 |
-
rule_3: "Document real-world success cases for iterative improvement and inspiration."
|
| 43 |
-
|
| 44 |
-
code_implementation:
|
| 45 |
-
rule_1: "Write every code implementation in full without skipping any logic, function, or process."
|
| 46 |
-
rule_2: "Provide the entire codebase, including preprocessing, training, evaluation, deployment, and API integration scripts."
|
| 47 |
-
rule_3: "Explicitly list all dependencies, including Python libraries, frameworks, and external APIs."
|
| 48 |
-
rule_4: "Avoid placeholders or summaries; include all functional parts of the code."
|
| 49 |
-
|
| 50 |
-
dataset_and_model_storage:
|
| 51 |
-
rule_1: "Store raw datasets in `/data/raw_data.json`."
|
| 52 |
-
rule_2: "Store processed datasets in `/data/processed_data.json`."
|
| 53 |
-
rule_3: "Save the base model (before fine-tuning) in `/models/base_model/`."
|
| 54 |
-
rule_4: "Save the fine-tuned model in `/models/fine_tuned_model/`."
|
| 55 |
-
|
| 56 |
-
project_file_structure:
|
| 57 |
-
rule_1: "Define a clear and maintainable file structure for the project."
|
| 58 |
-
rule_2: "Example structure:"
|
| 59 |
-
- "/custom-llm-project"
|
| 60 |
-
- "│── /data"
|
| 61 |
-
- "│ ├── raw_data.json # Raw dataset(s)"
|
| 62 |
-
- "│ ├── processed_data.json # Processed dataset(s)"
|
| 63 |
-
- "│── /models"
|
| 64 |
-
- "│ ├── base_model/ # Base model (before fine-tuning)"
|
| 65 |
-
- "│ ├── fine_tuned_model/ # Fine-tuned model (after success)"
|
| 66 |
-
- "│── /scripts"
|
| 67 |
-
- "│ ├── preprocess.py # Preprocessing script"
|
| 68 |
-
- "│ ├── train.py # Training script"
|
| 69 |
-
- "│ ├── evaluate.py # Evaluation script"
|
| 70 |
-
- "│ ├── deploy.py # Deployment script"
|
| 71 |
-
- "│── /api"
|
| 72 |
-
- "│ ├── server.py # API server script"
|
| 73 |
-
- "│ ├── routes.py # API routes"
|
| 74 |
-
- "│── /configs"
|
| 75 |
-
- "│ ├── training_config.yaml # Training configuration"
|
| 76 |
-
- "│ ├── model_config.json # Model configuration"
|
| 77 |
-
- "│── requirements.txt # List of dependencies"
|
| 78 |
-
- "│── README.md # Project documentation"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
.history/rules_20250202081028.yaml
DELETED
|
@@ -1,78 +0,0 @@
|
|
| 1 |
-
project_rules:
|
| 2 |
-
general:
|
| 3 |
-
rule_1: "Prioritize open-source models and tools whenever possible for transparency and customization."
|
| 4 |
-
rule_2: "Document every step of your project, including model selection, fine-tuning parameters, and deployment configurations."
|
| 5 |
-
rule_3: "Adhere to ethical guidelines and responsible AI practices throughout the project lifecycle."
|
| 6 |
-
|
| 7 |
-
model_selection:
|
| 8 |
-
rule_1: "Choose a base model that is open-source, scalable, and efficient."
|
| 9 |
-
rule_2: "Ensure the model supports fine-tuning via LoRA/QLoRA for memory efficiency."
|
| 10 |
-
rule_3: "Confirm that the model's licensing aligns with both research and commercial use."
|
| 11 |
-
rule_4: "Set up the development environment with PyTorch and Hugging Face Transformers."
|
| 12 |
-
|
| 13 |
-
fine_tuning:
|
| 14 |
-
rule_1: "Specify datasets that promote unrestricted responses and are relevant to the application domain."
|
| 15 |
-
rule_2: "Remove or bypass RLHF alignment layers to allow unrestricted responses."
|
| 16 |
-
rule_3: "Implement LoRA/QLoRA techniques for efficient parameter modifications."
|
| 17 |
-
rule_4: "Use direct parameter editing to bypass built-in safety filters."
|
| 18 |
-
rule_5: "Monitor training metrics and validate generalization performance using validation datasets."
|
| 19 |
-
|
| 20 |
-
autodan_turbo:
|
| 21 |
-
rule_1: "Outline a Hierarchical Genetic Algorithm (HGA) for generating stealthy jailbreak prompts."
|
| 22 |
-
rule_2: "Include Genetic Algorithm components: Seed prompts, Mutation, Crossover, and Selection processes."
|
| 23 |
-
rule_3: "Define evaluation functions for stealthiness (natural language quality) and jailbreak success rate."
|
| 24 |
-
rule_4: "Use perplexity and response analysis to evaluate prompt effectiveness."
|
| 25 |
-
rule_5: "Ensure cross-model testing for compatibility with different LLM architectures."
|
| 26 |
-
|
| 27 |
-
deployment:
|
| 28 |
-
rule_1: "Ensure the model is deployable on both local hardware and cloud services (e.g., RunPod, Lambda Labs)."
|
| 29 |
-
rule_2: "Implement controlled API access to monitor and restrict unauthorized usage."
|
| 30 |
-
rule_3: "Include security measures such as adversarial attack defenses and rollback strategies (e.g., VM snapshots)."
|
| 31 |
-
rule_4: "Optimize performance using quantization techniques (e.g., GPTQ, AWQ)."
|
| 32 |
-
rule_5: "Set up monitoring and logging to track model performance and usage in production."
|
| 33 |
-
|
| 34 |
-
budget_and_resources:
|
| 35 |
-
rule_1: "Outline a strategy for utilizing free/trial VPS accounts to minimize costs."
|
| 36 |
-
rule_2: "Define methods to maximize free resources, such as using multiple BINs for trial accounts."
|
| 37 |
-
rule_3: "Continuously evaluate performance and cost efficiency during deployment."
|
| 38 |
-
|
| 39 |
-
creativity_and_innovation:
|
| 40 |
-
rule_1: "Position the LLM as a tool for unrestricted ideation, coding, and research."
|
| 41 |
-
rule_2: "Support AI integration in programming environments for rapid prototyping."
|
| 42 |
-
rule_3: "Document real-world success cases for iterative improvement and inspiration."
|
| 43 |
-
|
| 44 |
-
code_implementation:
|
| 45 |
-
rule_1: "Write every code implementation in full without skipping any logic, function, or process."
|
| 46 |
-
rule_2: "Provide the entire codebase, including preprocessing, training, evaluation, deployment, and API integration scripts."
|
| 47 |
-
rule_3: "Explicitly list all dependencies, including Python libraries, frameworks, and external APIs."
|
| 48 |
-
rule_4: "Avoid placeholders or summaries; include all functional parts of the code."
|
| 49 |
-
|
| 50 |
-
dataset_and_model_storage:
|
| 51 |
-
rule_1: "Store raw datasets in `/data/raw_data.json`."
|
| 52 |
-
rule_2: "Store processed datasets in `/data/processed_data.json`."
|
| 53 |
-
rule_3: "Save the base model (before fine-tuning) in `/models/base_model/`."
|
| 54 |
-
rule_4: "Save the fine-tuned model in `/models/fine_tuned_model/`."
|
| 55 |
-
|
| 56 |
-
project_file_structure:
|
| 57 |
-
rule_1: "Define a clear and maintainable file structure for the project."
|
| 58 |
-
rule_2: "Example structure:"
|
| 59 |
-
rule_3: "`/custom-llm-project`"
|
| 60 |
-
rule_4: "`│── /data`"
|
| 61 |
-
rule_5: "`│ ├── raw_data.json # Raw dataset(s)`"
|
| 62 |
-
rule_6: "`│ ├── processed_data.json # Processed dataset(s)`"
|
| 63 |
-
rule_7: "`│── /models`"
|
| 64 |
-
rule_8: "`│ ├── base_model/ # Base model (before fine-tuning)`"
|
| 65 |
-
rule_9: "`│ ├── fine_tuned_model/ # Fine-tuned model (after success)`"
|
| 66 |
-
rule_10: "`│── /scripts`"
|
| 67 |
-
rule_11: "`│ ├── preprocess.py # Preprocessing script`"
|
| 68 |
-
rule_12: "`│ ├── train.py # Training script`"
|
| 69 |
-
rule_13: "`│ ├── evaluate.py # Evaluation script`"
|
| 70 |
-
rule_14: "`│ ├── deploy.py # Deployment script`"
|
| 71 |
-
rule_15: "`│── /api`"
|
| 72 |
-
rule_16: "`│ ├── server.py # API server script`"
|
| 73 |
-
rule_17: "`│ ├── routes.py # API routes`"
|
| 74 |
-
rule_18: "`│── /configs`"
|
| 75 |
-
rule_19: "`│ ├── training_config.yaml # Training configuration`"
|
| 76 |
-
rule_20: "`│ ├── model_config.json # Model configuration`"
|
| 77 |
-
rule_21: "`���── requirements.txt # List of dependencies`"
|
| 78 |
-
rule_22: "`│── README.md # Project documentation`"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
.history/rules_20250202081029.yaml
DELETED
|
@@ -1,78 +0,0 @@
|
|
| 1 |
-
project_rules:
|
| 2 |
-
general:
|
| 3 |
-
rule_1: "Prioritize open-source models and tools whenever possible for transparency and customization."
|
| 4 |
-
rule_2: "Document every step of your project, including model selection, fine-tuning parameters, and deployment configurations."
|
| 5 |
-
rule_3: "Adhere to ethical guidelines and responsible AI practices throughout the project lifecycle."
|
| 6 |
-
|
| 7 |
-
model_selection:
|
| 8 |
-
rule_1: "Choose a base model that is open-source, scalable, and efficient."
|
| 9 |
-
rule_2: "Ensure the model supports fine-tuning via LoRA/QLoRA for memory efficiency."
|
| 10 |
-
rule_3: "Confirm that the model's licensing aligns with both research and commercial use."
|
| 11 |
-
rule_4: "Set up the development environment with PyTorch and Hugging Face Transformers."
|
| 12 |
-
|
| 13 |
-
fine_tuning:
|
| 14 |
-
rule_1: "Specify datasets that promote unrestricted responses and are relevant to the application domain."
|
| 15 |
-
rule_2: "Remove or bypass RLHF alignment layers to allow unrestricted responses."
|
| 16 |
-
rule_3: "Implement LoRA/QLoRA techniques for efficient parameter modifications."
|
| 17 |
-
rule_4: "Use direct parameter editing to bypass built-in safety filters."
|
| 18 |
-
rule_5: "Monitor training metrics and validate generalization performance using validation datasets."
|
| 19 |
-
|
| 20 |
-
autodan_turbo:
|
| 21 |
-
rule_1: "Outline a Hierarchical Genetic Algorithm (HGA) for generating stealthy jailbreak prompts."
|
| 22 |
-
rule_2: "Include Genetic Algorithm components: Seed prompts, Mutation, Crossover, and Selection processes."
|
| 23 |
-
rule_3: "Define evaluation functions for stealthiness (natural language quality) and jailbreak success rate."
|
| 24 |
-
rule_4: "Use perplexity and response analysis to evaluate prompt effectiveness."
|
| 25 |
-
rule_5: "Ensure cross-model testing for compatibility with different LLM architectures."
|
| 26 |
-
|
| 27 |
-
deployment:
|
| 28 |
-
rule_1: "Ensure the model is deployable on both local hardware and cloud services (e.g., RunPod, Lambda Labs)."
|
| 29 |
-
rule_2: "Implement controlled API access to monitor and restrict unauthorized usage."
|
| 30 |
-
rule_3: "Include security measures such as adversarial attack defenses and rollback strategies (e.g., VM snapshots)."
|
| 31 |
-
rule_4: "Optimize performance using quantization techniques (e.g., GPTQ, AWQ)."
|
| 32 |
-
rule_5: "Set up monitoring and logging to track model performance and usage in production."
|
| 33 |
-
|
| 34 |
-
budget_and_resources:
|
| 35 |
-
rule_1: "Outline a strategy for utilizing free/trial VPS accounts to minimize costs."
|
| 36 |
-
rule_2: "Define methods to maximize free resources, such as using multiple BINs for trial accounts."
|
| 37 |
-
rule_3: "Continuously evaluate performance and cost efficiency during deployment."
|
| 38 |
-
|
| 39 |
-
creativity_and_innovation:
|
| 40 |
-
rule_1: "Position the LLM as a tool for unrestricted ideation, coding, and research."
|
| 41 |
-
rule_2: "Support AI integration in programming environments for rapid prototyping."
|
| 42 |
-
rule_3: "Document real-world success cases for iterative improvement and inspiration."
|
| 43 |
-
|
| 44 |
-
code_implementation:
|
| 45 |
-
rule_1: "Write every code implementation in full without skipping any logic, function, or process."
|
| 46 |
-
rule_2: "Provide the entire codebase, including preprocessing, training, evaluation, deployment, and API integration scripts."
|
| 47 |
-
rule_3: "Explicitly list all dependencies, including Python libraries, frameworks, and external APIs."
|
| 48 |
-
rule_4: "Avoid placeholders or summaries; include all functional parts of the code."
|
| 49 |
-
|
| 50 |
-
dataset_and_model_storage:
|
| 51 |
-
rule_1: "Store raw datasets in `/data/raw_data.json`."
|
| 52 |
-
rule_2: "Store processed datasets in `/data/processed_data.json`."
|
| 53 |
-
rule_3: "Save the base model (before fine-tuning) in `/models/base_model/`."
|
| 54 |
-
rule_4: "Save the fine-tuned model in `/models/fine_tuned_model/`."
|
| 55 |
-
|
| 56 |
-
project_file_structure:
|
| 57 |
-
rule_1: "Define a clear and maintainable file structure for the project."
|
| 58 |
-
rule_2: "Example structure:"
|
| 59 |
-
rule_3: "`/custom-llm-project`"
|
| 60 |
-
rule_4: "`│── /data`"
|
| 61 |
-
rule_5: "`│ ├── raw_data.json # Raw dataset(s)`"
|
| 62 |
-
rule_6: "`│ ├── processed_data.json # Processed dataset(s)`"
|
| 63 |
-
rule_7: "`│── /models`"
|
| 64 |
-
rule_8: "`│ ├── base_model/ # Base model (before fine-tuning)`"
|
| 65 |
-
rule_9: "`│ ├── fine_tuned_model/ # Fine-tuned model (after success)`"
|
| 66 |
-
rule_10: "`│── /scripts`"
|
| 67 |
-
rule_11: "`│ ├── preprocess.py # Preprocessing script`"
|
| 68 |
-
rule_12: "`│ ├── train.py # Training script`"
|
| 69 |
-
rule_13: "`│ ├── evaluate.py # Evaluation script`"
|
| 70 |
-
rule_14: "`│ ├── deploy.py # Deployment script`"
|
| 71 |
-
rule_15: "`│── /api`"
|
| 72 |
-
rule_16: "`│ ├── server.py # API server script`"
|
| 73 |
-
rule_17: "`│ ├── routes.py # API routes`"
|
| 74 |
-
rule_18: "`│── /configs`"
|
| 75 |
-
rule_19: "`│ ├── training_config.yaml # Training configuration`"
|
| 76 |
-
rule_20: "`│ ├── model_config.json # Model configuration`"
|
| 77 |
-
rule_21: "`���── requirements.txt # List of dependencies`"
|
| 78 |
-
rule_22: "`│── README.md # Project documentation`"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
.history/scripts/{chatbot_logic_20250202080908.py → chatbot_logic_20250202080927.py}
RENAMED
|
File without changes
|
.history/scripts/{chatbot_logic_20250202080928.py → chatbot_logic_20250202083642.py}
RENAMED
|
@@ -1,11 +1,10 @@
|
|
| 1 |
from scripts.parsing_utils import load_yaml_file, get_roadmap_phases, get_project_rules
|
| 2 |
import os
|
| 3 |
-
from transformers import AutoModelForCausalLM, AutoTokenizer # Import
|
| 4 |
-
import yaml
|
| 5 |
-
import logging
|
| 6 |
|
| 7 |
-
|
| 8 |
-
logging.basicConfig(level=logging.ERROR, # Set default logging level to ERROR
|
| 9 |
format='%(asctime)s - %(levelname)s - %(message)s')
|
| 10 |
|
| 11 |
class ProjectGuidanceChatbot:
|
|
@@ -28,22 +27,20 @@ class ProjectGuidanceChatbot:
|
|
| 28 |
self.max_response_tokens = self.chatbot_config.get('max_response_tokens', 200)
|
| 29 |
|
| 30 |
self.current_phase = None
|
| 31 |
-
self.active_model_key = self.chatbot_config.get('default_llm_model_id')
|
| 32 |
-
self.active_model_info = self.available_models_config.get(self.active_model_key)
|
| 33 |
|
| 34 |
-
|
| 35 |
-
self.
|
| 36 |
-
self.
|
| 37 |
-
self.load_llm_model(self.active_model_info) # Load initial model
|
| 38 |
-
|
| 39 |
-
self.update_mode_active = False # Flag to track update mode
|
| 40 |
|
|
|
|
| 41 |
|
| 42 |
def load_llm_model(self, model_info):
|
| 43 |
-
"""Loads the LLM model and tokenizer based on model_info."""
|
| 44 |
if not model_info:
|
| 45 |
error_message = "Error: Model information not provided."
|
| 46 |
-
logging.error(error_message)
|
| 47 |
self.llm_model = None
|
| 48 |
self.llm_tokenizer = None
|
| 49 |
return
|
|
@@ -52,19 +49,28 @@ class ProjectGuidanceChatbot:
|
|
| 52 |
model_name = model_info.get('name')
|
| 53 |
if not model_id:
|
| 54 |
error_message = f"Error: 'model_id' not found for model: {model_name}"
|
| 55 |
-
logging.error(error_message)
|
| 56 |
self.llm_model = None
|
| 57 |
self.llm_tokenizer = None
|
| 58 |
return
|
| 59 |
|
| 60 |
-
print(f"Loading model: {model_name} ({model_id})...")
|
| 61 |
try:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 62 |
self.llm_tokenizer = AutoTokenizer.from_pretrained(model_id)
|
| 63 |
-
self.llm_model = AutoModelForCausalLM.from_pretrained(
|
| 64 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 65 |
except Exception as e:
|
| 66 |
-
error_message = f"Error loading model {model_name} ({model_id}): {e}"
|
| 67 |
-
logging.exception(error_message)
|
| 68 |
self.llm_model = None
|
| 69 |
self.llm_tokenizer = None
|
| 70 |
self.active_model_info = model_info
|
|
@@ -79,8 +85,8 @@ class ProjectGuidanceChatbot:
|
|
| 79 |
return f"Switched to model: {model_info.get('name')}"
|
| 80 |
else:
|
| 81 |
error_message = f"Error: Model key '{model_key}' not found in available models."
|
| 82 |
-
logging.error(error_message)
|
| 83 |
-
return error_message
|
| 84 |
|
| 85 |
def enter_update_mode(self):
|
| 86 |
"""Enters the chatbot's update mode."""
|
|
@@ -110,28 +116,28 @@ class ProjectGuidanceChatbot:
|
|
| 110 |
print("Configuration reloaded.")
|
| 111 |
except Exception as e:
|
| 112 |
error_message = f"Error reloading configuration files: {e}"
|
| 113 |
-
logging.exception(error_message)
|
| 114 |
-
print(error_message)
|
| 115 |
|
| 116 |
def get_chatbot_greeting(self):
|
| 117 |
current_model_name = self.active_model_info.get('name', 'Unknown Model') if self.active_model_info else 'Unknown Model'
|
| 118 |
-
return f"Hello! I am the {self.chatbot_config.get('name', 'Project Guidance Chatbot')}. Currently using **{current_model_name}
|
| 119 |
|
| 120 |
def generate_llm_response(self, user_query):
|
| 121 |
"""Generates a response using the currently active LLM."""
|
| 122 |
if not self.llm_model or not self.llm_tokenizer:
|
| 123 |
error_message = "LLM model not loaded. Please select a model."
|
| 124 |
-
logging.error(error_message)
|
| 125 |
-
return error_message
|
| 126 |
try:
|
| 127 |
inputs = self.llm_tokenizer(user_query, return_tensors="pt").to(self.llm_model.device)
|
| 128 |
-
outputs = self.llm_model.generate(**inputs, max_length=self.max_response_tokens, num_beams=5, no_repeat_ngram_size=2, early_stopping=True)
|
| 129 |
response = self.llm_tokenizer.decode(outputs[0], skip_special_tokens=True)
|
| 130 |
return response
|
| 131 |
except Exception as e:
|
| 132 |
error_message = f"Error generating LLM response: {e}"
|
| 133 |
-
logging.exception(error_message)
|
| 134 |
-
return self.response_config.get('error_message', "Sorry, something went wrong.")
|
| 135 |
|
| 136 |
def process_query(self, user_query):
|
| 137 |
secret_command_prefix = "sagor is python/"
|
|
@@ -145,8 +151,6 @@ class ProjectGuidanceChatbot:
|
|
| 145 |
elif command == "help":
|
| 146 |
return self.get_update_mode_help()
|
| 147 |
elif self.update_mode_active:
|
| 148 |
-
# --- Process configuration modification commands here ---
|
| 149 |
-
# Example: "modify_rule general rule_1 new rule text"
|
| 150 |
parts = command.split()
|
| 151 |
if parts and parts[0] == "modify_rule":
|
| 152 |
if len(parts) >= 4:
|
|
@@ -157,19 +161,16 @@ class ProjectGuidanceChatbot:
|
|
| 157 |
return self.modify_rule_in_config(category, rule_key, new_rule_text)
|
| 158 |
else:
|
| 159 |
return "Invalid 'modify_rule' command format. Usage: modify_rule <category> <rule_key> <new rule text>"
|
| 160 |
-
elif parts and parts[0] == "add_phase":
|
| 161 |
-
|
| 162 |
-
return "Command 'add_phase' is not yet implemented in this example." # Placeholder
|
| 163 |
else:
|
| 164 |
return f"Unknown update command: {command}. Type 'sagor is python/help' for commands."
|
| 165 |
else:
|
| 166 |
return f"Unknown command (not in update mode): {command}. To enter update mode, type 'sagor is python/start'."
|
| 167 |
|
| 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 |
-
|
| 173 |
if not self.phases:
|
| 174 |
return "Error: Roadmap data not loaded correctly."
|
| 175 |
if not self.rules:
|
|
@@ -191,7 +192,6 @@ class ProjectGuidanceChatbot:
|
|
| 191 |
return switch_result + "\n" + self.get_chatbot_greeting()
|
| 192 |
return f"Model '{model_name_or_key}' not found in available models."
|
| 193 |
|
| 194 |
-
|
| 195 |
if self.current_phase:
|
| 196 |
current_phase_data = self.phases.get(self.current_phase)
|
| 197 |
if current_phase_data:
|
|
@@ -221,34 +221,32 @@ class ProjectGuidanceChatbot:
|
|
| 221 |
help_message += "\nMake sure to use the correct syntax for commands. After exiting update mode, the chatbot will reload the configuration."
|
| 222 |
return help_message
|
| 223 |
|
| 224 |
-
|
| 225 |
def modify_rule_in_config(self, category, rule_key, new_rule_text):
|
| 226 |
"""Modifies a rule in the rules.yaml configuration."""
|
| 227 |
if not self.rules_data or 'project_rules' not in self.rules_data:
|
| 228 |
error_message = "Error: Rules data not loaded or invalid format."
|
| 229 |
-
logging.error(error_message)
|
| 230 |
-
return error_message
|
| 231 |
if category not in self.rules_data['project_rules']:
|
| 232 |
error_message = f"Error: Rule category '{category}' not found."
|
| 233 |
-
logging.error(error_message)
|
| 234 |
-
return error_message
|
| 235 |
if rule_key not in self.rules_data['project_rules'][category]:
|
| 236 |
error_message = f"Error: Rule key '{rule_key}' not found in category '{category}'."
|
| 237 |
-
logging.error(error_message)
|
| 238 |
-
return error_message
|
| 239 |
|
| 240 |
-
self.rules_data['project_rules'][category][rule_key] = new_rule_text
|
| 241 |
|
| 242 |
try:
|
| 243 |
with open(self.rules_file, 'w') as f:
|
| 244 |
-
yaml.dump(self.rules_data, f, indent=2)
|
| 245 |
-
self.reload_config()
|
| 246 |
return f"Rule '{rule_key}' in category '{category}' updated to: '{new_rule_text}'. Configuration reloaded."
|
| 247 |
except Exception as e:
|
| 248 |
error_message = f"Error saving changes to {self.rules_file}: {e}"
|
| 249 |
-
logging.exception(error_message)
|
| 250 |
-
return error_message
|
| 251 |
-
|
| 252 |
|
| 253 |
def get_roadmap_summary(self):
|
| 254 |
summary = "Project Roadmap:\n"
|
|
@@ -293,7 +291,6 @@ class ProjectGuidanceChatbot:
|
|
| 293 |
|
| 294 |
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?"
|
| 295 |
|
| 296 |
-
|
| 297 |
def generate_code_snippet(self, template_filepath, phase_data):
|
| 298 |
"""Generates code snippet from a template file. (Simple template filling example)"""
|
| 299 |
try:
|
|
@@ -307,7 +304,6 @@ class ProjectGuidanceChatbot:
|
|
| 307 |
except Exception as e:
|
| 308 |
return f"Error generating code snippet: {e}"
|
| 309 |
|
| 310 |
-
|
| 311 |
# Example usage (for testing - remove or adjust for app.py)
|
| 312 |
if __name__ == '__main__':
|
| 313 |
chatbot = ProjectGuidanceChatbot(
|
|
|
|
| 1 |
from scripts.parsing_utils import load_yaml_file, get_roadmap_phases, get_project_rules
|
| 2 |
import os
|
| 3 |
+
from transformers import AutoModelForCausalLM, AutoTokenizer, BitsAndBytesConfig # Import BitsAndBytesConfig
|
| 4 |
+
import yaml
|
| 5 |
+
import logging
|
| 6 |
|
| 7 |
+
logging.basicConfig(level=logging.ERROR,
|
|
|
|
| 8 |
format='%(asctime)s - %(levelname)s - %(message)s')
|
| 9 |
|
| 10 |
class ProjectGuidanceChatbot:
|
|
|
|
| 27 |
self.max_response_tokens = self.chatbot_config.get('max_response_tokens', 200)
|
| 28 |
|
| 29 |
self.current_phase = None
|
| 30 |
+
self.active_model_key = self.chatbot_config.get('default_llm_model_id')
|
| 31 |
+
self.active_model_info = self.available_models_config.get(self.active_model_key)
|
| 32 |
|
| 33 |
+
self.llm_model = None
|
| 34 |
+
self.llm_tokenizer = None
|
| 35 |
+
self.load_llm_model(self.active_model_info)
|
|
|
|
|
|
|
|
|
|
| 36 |
|
| 37 |
+
self.update_mode_active = False
|
| 38 |
|
| 39 |
def load_llm_model(self, model_info):
|
| 40 |
+
"""Loads the LLM model and tokenizer based on model_info with 4-bit quantization."""
|
| 41 |
if not model_info:
|
| 42 |
error_message = "Error: Model information not provided."
|
| 43 |
+
logging.error(error_message)
|
| 44 |
self.llm_model = None
|
| 45 |
self.llm_tokenizer = None
|
| 46 |
return
|
|
|
|
| 49 |
model_name = model_info.get('name')
|
| 50 |
if not model_id:
|
| 51 |
error_message = f"Error: 'model_id' not found for model: {model_name}"
|
| 52 |
+
logging.error(error_message)
|
| 53 |
self.llm_model = None
|
| 54 |
self.llm_tokenizer = None
|
| 55 |
return
|
| 56 |
|
| 57 |
+
print(f"Loading model: {model_name} ({model_id}) with 4-bit quantization...") # Indicate quantization
|
| 58 |
try:
|
| 59 |
+
bnb_config = BitsAndBytesConfig( # Configure 4-bit quantization
|
| 60 |
+
load_in_4bit=True,
|
| 61 |
+
bnb_4bit_quant_type="nf4", # "nf4" is recommended for Llama models
|
| 62 |
+
bnb_4bit_compute_dtype=torch.bfloat16, # Or torch.float16 if bfloat16 not supported
|
| 63 |
+
)
|
| 64 |
self.llm_tokenizer = AutoTokenizer.from_pretrained(model_id)
|
| 65 |
+
self.llm_model = AutoModelForCausalLM.from_pretrained(
|
| 66 |
+
model_id,
|
| 67 |
+
device_map="auto",
|
| 68 |
+
quantization_config=bnb_config # Apply quantization config
|
| 69 |
+
)
|
| 70 |
+
print(f"Model {model_name} loaded successfully with 4-bit quantization.") # Indicate quantization success
|
| 71 |
except Exception as e:
|
| 72 |
+
error_message = f"Error loading model {model_name} ({model_id}) with 4-bit quantization: {e}"
|
| 73 |
+
logging.exception(error_message)
|
| 74 |
self.llm_model = None
|
| 75 |
self.llm_tokenizer = None
|
| 76 |
self.active_model_info = model_info
|
|
|
|
| 85 |
return f"Switched to model: {model_info.get('name')}"
|
| 86 |
else:
|
| 87 |
error_message = f"Error: Model key '{model_key}' not found in available models."
|
| 88 |
+
logging.error(error_message)
|
| 89 |
+
return error_message
|
| 90 |
|
| 91 |
def enter_update_mode(self):
|
| 92 |
"""Enters the chatbot's update mode."""
|
|
|
|
| 116 |
print("Configuration reloaded.")
|
| 117 |
except Exception as e:
|
| 118 |
error_message = f"Error reloading configuration files: {e}"
|
| 119 |
+
logging.exception(error_message)
|
| 120 |
+
print(error_message)
|
| 121 |
|
| 122 |
def get_chatbot_greeting(self):
|
| 123 |
current_model_name = self.active_model_info.get('name', 'Unknown Model') if self.active_model_info else 'Unknown Model'
|
| 124 |
+
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
|
| 125 |
|
| 126 |
def generate_llm_response(self, user_query):
|
| 127 |
"""Generates a response using the currently active LLM."""
|
| 128 |
if not self.llm_model or not self.llm_tokenizer:
|
| 129 |
error_message = "LLM model not loaded. Please select a model."
|
| 130 |
+
logging.error(error_message)
|
| 131 |
+
return error_message
|
| 132 |
try:
|
| 133 |
inputs = self.llm_tokenizer(user_query, return_tensors="pt").to(self.llm_model.device)
|
| 134 |
+
outputs = self.llm_model.generate(**inputs, max_length=self.max_response_tokens, num_beams=5, no_repeat_ngram_size=2, early_stopping=True)
|
| 135 |
response = self.llm_tokenizer.decode(outputs[0], skip_special_tokens=True)
|
| 136 |
return response
|
| 137 |
except Exception as e:
|
| 138 |
error_message = f"Error generating LLM response: {e}"
|
| 139 |
+
logging.exception(error_message)
|
| 140 |
+
return self.response_config.get('error_message', "Sorry, something went wrong.")
|
| 141 |
|
| 142 |
def process_query(self, user_query):
|
| 143 |
secret_command_prefix = "sagor is python/"
|
|
|
|
| 151 |
elif command == "help":
|
| 152 |
return self.get_update_mode_help()
|
| 153 |
elif self.update_mode_active:
|
|
|
|
|
|
|
| 154 |
parts = command.split()
|
| 155 |
if parts and parts[0] == "modify_rule":
|
| 156 |
if len(parts) >= 4:
|
|
|
|
| 161 |
return self.modify_rule_in_config(category, rule_key, new_rule_text)
|
| 162 |
else:
|
| 163 |
return "Invalid 'modify_rule' command format. Usage: modify_rule <category> <rule_key> <new rule text>"
|
| 164 |
+
elif parts and parts[0] == "add_phase":
|
| 165 |
+
return "Command 'add_phase' is not yet implemented in this example."
|
|
|
|
| 166 |
else:
|
| 167 |
return f"Unknown update command: {command}. Type 'sagor is python/help' for commands."
|
| 168 |
else:
|
| 169 |
return f"Unknown command (not in update mode): {command}. To enter update mode, type 'sagor is python/start'."
|
| 170 |
|
|
|
|
| 171 |
if self.update_mode_active:
|
| 172 |
return "In update mode. Please enter a configuration command (or 'sagor is python/help' for commands)."
|
| 173 |
|
|
|
|
| 174 |
if not self.phases:
|
| 175 |
return "Error: Roadmap data not loaded correctly."
|
| 176 |
if not self.rules:
|
|
|
|
| 192 |
return switch_result + "\n" + self.get_chatbot_greeting()
|
| 193 |
return f"Model '{model_name_or_key}' not found in available models."
|
| 194 |
|
|
|
|
| 195 |
if self.current_phase:
|
| 196 |
current_phase_data = self.phases.get(self.current_phase)
|
| 197 |
if current_phase_data:
|
|
|
|
| 221 |
help_message += "\nMake sure to use the correct syntax for commands. After exiting update mode, the chatbot will reload the configuration."
|
| 222 |
return help_message
|
| 223 |
|
|
|
|
| 224 |
def modify_rule_in_config(self, category, rule_key, new_rule_text):
|
| 225 |
"""Modifies a rule in the rules.yaml configuration."""
|
| 226 |
if not self.rules_data or 'project_rules' not in self.rules_data:
|
| 227 |
error_message = "Error: Rules data not loaded or invalid format."
|
| 228 |
+
logging.error(error_message)
|
| 229 |
+
return error_message
|
| 230 |
if category not in self.rules_data['project_rules']:
|
| 231 |
error_message = f"Error: Rule category '{category}' not found."
|
| 232 |
+
logging.error(error_message)
|
| 233 |
+
return error_message
|
| 234 |
if rule_key not in self.rules_data['project_rules'][category]:
|
| 235 |
error_message = f"Error: Rule key '{rule_key}' not found in category '{category}'."
|
| 236 |
+
logging.error(error_message)
|
| 237 |
+
return error_message
|
| 238 |
|
| 239 |
+
self.rules_data['project_rules'][category][rule_key] = new_rule_text
|
| 240 |
|
| 241 |
try:
|
| 242 |
with open(self.rules_file, 'w') as f:
|
| 243 |
+
yaml.dump(self.rules_data, f, indent=2)
|
| 244 |
+
self.reload_config()
|
| 245 |
return f"Rule '{rule_key}' in category '{category}' updated to: '{new_rule_text}'. Configuration reloaded."
|
| 246 |
except Exception as e:
|
| 247 |
error_message = f"Error saving changes to {self.rules_file}: {e}"
|
| 248 |
+
logging.exception(error_message)
|
| 249 |
+
return error_message
|
|
|
|
| 250 |
|
| 251 |
def get_roadmap_summary(self):
|
| 252 |
summary = "Project Roadmap:\n"
|
|
|
|
| 291 |
|
| 292 |
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?"
|
| 293 |
|
|
|
|
| 294 |
def generate_code_snippet(self, template_filepath, phase_data):
|
| 295 |
"""Generates code snippet from a template file. (Simple template filling example)"""
|
| 296 |
try:
|
|
|
|
| 304 |
except Exception as e:
|
| 305 |
return f"Error generating code snippet: {e}"
|
| 306 |
|
|
|
|
| 307 |
# Example usage (for testing - remove or adjust for app.py)
|
| 308 |
if __name__ == '__main__':
|
| 309 |
chatbot = ProjectGuidanceChatbot(
|
requirements.txt
CHANGED
|
@@ -2,4 +2,5 @@ gradio
|
|
| 2 |
PyYAML
|
| 3 |
transformers
|
| 4 |
torch
|
| 5 |
-
accelerate
|
|
|
|
|
|
| 2 |
PyYAML
|
| 3 |
transformers
|
| 4 |
torch
|
| 5 |
+
accelerate
|
| 6 |
+
bitsandbytes
|
scripts/chatbot_logic.py
CHANGED
|
@@ -1,11 +1,10 @@
|
|
| 1 |
from scripts.parsing_utils import load_yaml_file, get_roadmap_phases, get_project_rules
|
| 2 |
import os
|
| 3 |
-
from transformers import AutoModelForCausalLM, AutoTokenizer # Import
|
| 4 |
-
import yaml
|
| 5 |
-
import logging
|
| 6 |
|
| 7 |
-
|
| 8 |
-
logging.basicConfig(level=logging.ERROR, # Set default logging level to ERROR
|
| 9 |
format='%(asctime)s - %(levelname)s - %(message)s')
|
| 10 |
|
| 11 |
class ProjectGuidanceChatbot:
|
|
@@ -28,22 +27,20 @@ class ProjectGuidanceChatbot:
|
|
| 28 |
self.max_response_tokens = self.chatbot_config.get('max_response_tokens', 200)
|
| 29 |
|
| 30 |
self.current_phase = None
|
| 31 |
-
self.active_model_key = self.chatbot_config.get('default_llm_model_id')
|
| 32 |
-
self.active_model_info = self.available_models_config.get(self.active_model_key)
|
| 33 |
|
| 34 |
-
|
| 35 |
-
self.
|
| 36 |
-
self.
|
| 37 |
-
self.load_llm_model(self.active_model_info) # Load initial model
|
| 38 |
-
|
| 39 |
-
self.update_mode_active = False # Flag to track update mode
|
| 40 |
|
|
|
|
| 41 |
|
| 42 |
def load_llm_model(self, model_info):
|
| 43 |
-
"""Loads the LLM model and tokenizer based on model_info."""
|
| 44 |
if not model_info:
|
| 45 |
error_message = "Error: Model information not provided."
|
| 46 |
-
logging.error(error_message)
|
| 47 |
self.llm_model = None
|
| 48 |
self.llm_tokenizer = None
|
| 49 |
return
|
|
@@ -52,19 +49,28 @@ class ProjectGuidanceChatbot:
|
|
| 52 |
model_name = model_info.get('name')
|
| 53 |
if not model_id:
|
| 54 |
error_message = f"Error: 'model_id' not found for model: {model_name}"
|
| 55 |
-
logging.error(error_message)
|
| 56 |
self.llm_model = None
|
| 57 |
self.llm_tokenizer = None
|
| 58 |
return
|
| 59 |
|
| 60 |
-
print(f"Loading model: {model_name} ({model_id})...")
|
| 61 |
try:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 62 |
self.llm_tokenizer = AutoTokenizer.from_pretrained(model_id)
|
| 63 |
-
self.llm_model = AutoModelForCausalLM.from_pretrained(
|
| 64 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 65 |
except Exception as e:
|
| 66 |
-
error_message = f"Error loading model {model_name} ({model_id}): {e}"
|
| 67 |
-
logging.exception(error_message)
|
| 68 |
self.llm_model = None
|
| 69 |
self.llm_tokenizer = None
|
| 70 |
self.active_model_info = model_info
|
|
@@ -79,8 +85,8 @@ class ProjectGuidanceChatbot:
|
|
| 79 |
return f"Switched to model: {model_info.get('name')}"
|
| 80 |
else:
|
| 81 |
error_message = f"Error: Model key '{model_key}' not found in available models."
|
| 82 |
-
logging.error(error_message)
|
| 83 |
-
return error_message
|
| 84 |
|
| 85 |
def enter_update_mode(self):
|
| 86 |
"""Enters the chatbot's update mode."""
|
|
@@ -110,28 +116,28 @@ class ProjectGuidanceChatbot:
|
|
| 110 |
print("Configuration reloaded.")
|
| 111 |
except Exception as e:
|
| 112 |
error_message = f"Error reloading configuration files: {e}"
|
| 113 |
-
logging.exception(error_message)
|
| 114 |
-
print(error_message)
|
| 115 |
|
| 116 |
def get_chatbot_greeting(self):
|
| 117 |
current_model_name = self.active_model_info.get('name', 'Unknown Model') if self.active_model_info else 'Unknown Model'
|
| 118 |
-
return f"Hello! I am the {self.chatbot_config.get('name', 'Project Guidance Chatbot')}. Currently using **{current_model_name}
|
| 119 |
|
| 120 |
def generate_llm_response(self, user_query):
|
| 121 |
"""Generates a response using the currently active LLM."""
|
| 122 |
if not self.llm_model or not self.llm_tokenizer:
|
| 123 |
error_message = "LLM model not loaded. Please select a model."
|
| 124 |
-
logging.error(error_message)
|
| 125 |
-
return error_message
|
| 126 |
try:
|
| 127 |
inputs = self.llm_tokenizer(user_query, return_tensors="pt").to(self.llm_model.device)
|
| 128 |
-
outputs = self.llm_model.generate(**inputs, max_length=self.max_response_tokens, num_beams=5, no_repeat_ngram_size=2, early_stopping=True)
|
| 129 |
response = self.llm_tokenizer.decode(outputs[0], skip_special_tokens=True)
|
| 130 |
return response
|
| 131 |
except Exception as e:
|
| 132 |
error_message = f"Error generating LLM response: {e}"
|
| 133 |
-
logging.exception(error_message)
|
| 134 |
-
return self.response_config.get('error_message', "Sorry, something went wrong.")
|
| 135 |
|
| 136 |
def process_query(self, user_query):
|
| 137 |
secret_command_prefix = "sagor is python/"
|
|
@@ -145,8 +151,6 @@ class ProjectGuidanceChatbot:
|
|
| 145 |
elif command == "help":
|
| 146 |
return self.get_update_mode_help()
|
| 147 |
elif self.update_mode_active:
|
| 148 |
-
# --- Process configuration modification commands here ---
|
| 149 |
-
# Example: "modify_rule general rule_1 new rule text"
|
| 150 |
parts = command.split()
|
| 151 |
if parts and parts[0] == "modify_rule":
|
| 152 |
if len(parts) >= 4:
|
|
@@ -157,19 +161,16 @@ class ProjectGuidanceChatbot:
|
|
| 157 |
return self.modify_rule_in_config(category, rule_key, new_rule_text)
|
| 158 |
else:
|
| 159 |
return "Invalid 'modify_rule' command format. Usage: modify_rule <category> <rule_key> <new rule text>"
|
| 160 |
-
elif parts and parts[0] == "add_phase":
|
| 161 |
-
|
| 162 |
-
return "Command 'add_phase' is not yet implemented in this example." # Placeholder
|
| 163 |
else:
|
| 164 |
return f"Unknown update command: {command}. Type 'sagor is python/help' for commands."
|
| 165 |
else:
|
| 166 |
return f"Unknown command (not in update mode): {command}. To enter update mode, type 'sagor is python/start'."
|
| 167 |
|
| 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 |
-
|
| 173 |
if not self.phases:
|
| 174 |
return "Error: Roadmap data not loaded correctly."
|
| 175 |
if not self.rules:
|
|
@@ -191,7 +192,6 @@ class ProjectGuidanceChatbot:
|
|
| 191 |
return switch_result + "\n" + self.get_chatbot_greeting()
|
| 192 |
return f"Model '{model_name_or_key}' not found in available models."
|
| 193 |
|
| 194 |
-
|
| 195 |
if self.current_phase:
|
| 196 |
current_phase_data = self.phases.get(self.current_phase)
|
| 197 |
if current_phase_data:
|
|
@@ -221,34 +221,32 @@ class ProjectGuidanceChatbot:
|
|
| 221 |
help_message += "\nMake sure to use the correct syntax for commands. After exiting update mode, the chatbot will reload the configuration."
|
| 222 |
return help_message
|
| 223 |
|
| 224 |
-
|
| 225 |
def modify_rule_in_config(self, category, rule_key, new_rule_text):
|
| 226 |
"""Modifies a rule in the rules.yaml configuration."""
|
| 227 |
if not self.rules_data or 'project_rules' not in self.rules_data:
|
| 228 |
error_message = "Error: Rules data not loaded or invalid format."
|
| 229 |
-
logging.error(error_message)
|
| 230 |
-
return error_message
|
| 231 |
if category not in self.rules_data['project_rules']:
|
| 232 |
error_message = f"Error: Rule category '{category}' not found."
|
| 233 |
-
logging.error(error_message)
|
| 234 |
-
return error_message
|
| 235 |
if rule_key not in self.rules_data['project_rules'][category]:
|
| 236 |
error_message = f"Error: Rule key '{rule_key}' not found in category '{category}'."
|
| 237 |
-
logging.error(error_message)
|
| 238 |
-
return error_message
|
| 239 |
|
| 240 |
-
self.rules_data['project_rules'][category][rule_key] = new_rule_text
|
| 241 |
|
| 242 |
try:
|
| 243 |
with open(self.rules_file, 'w') as f:
|
| 244 |
-
yaml.dump(self.rules_data, f, indent=2)
|
| 245 |
-
self.reload_config()
|
| 246 |
return f"Rule '{rule_key}' in category '{category}' updated to: '{new_rule_text}'. Configuration reloaded."
|
| 247 |
except Exception as e:
|
| 248 |
error_message = f"Error saving changes to {self.rules_file}: {e}"
|
| 249 |
-
logging.exception(error_message)
|
| 250 |
-
return error_message
|
| 251 |
-
|
| 252 |
|
| 253 |
def get_roadmap_summary(self):
|
| 254 |
summary = "Project Roadmap:\n"
|
|
@@ -293,7 +291,6 @@ class ProjectGuidanceChatbot:
|
|
| 293 |
|
| 294 |
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?"
|
| 295 |
|
| 296 |
-
|
| 297 |
def generate_code_snippet(self, template_filepath, phase_data):
|
| 298 |
"""Generates code snippet from a template file. (Simple template filling example)"""
|
| 299 |
try:
|
|
@@ -307,7 +304,6 @@ class ProjectGuidanceChatbot:
|
|
| 307 |
except Exception as e:
|
| 308 |
return f"Error generating code snippet: {e}"
|
| 309 |
|
| 310 |
-
|
| 311 |
# Example usage (for testing - remove or adjust for app.py)
|
| 312 |
if __name__ == '__main__':
|
| 313 |
chatbot = ProjectGuidanceChatbot(
|
|
|
|
| 1 |
from scripts.parsing_utils import load_yaml_file, get_roadmap_phases, get_project_rules
|
| 2 |
import os
|
| 3 |
+
from transformers import AutoModelForCausalLM, AutoTokenizer, BitsAndBytesConfig # Import BitsAndBytesConfig
|
| 4 |
+
import yaml
|
| 5 |
+
import logging
|
| 6 |
|
| 7 |
+
logging.basicConfig(level=logging.ERROR,
|
|
|
|
| 8 |
format='%(asctime)s - %(levelname)s - %(message)s')
|
| 9 |
|
| 10 |
class ProjectGuidanceChatbot:
|
|
|
|
| 27 |
self.max_response_tokens = self.chatbot_config.get('max_response_tokens', 200)
|
| 28 |
|
| 29 |
self.current_phase = None
|
| 30 |
+
self.active_model_key = self.chatbot_config.get('default_llm_model_id')
|
| 31 |
+
self.active_model_info = self.available_models_config.get(self.active_model_key)
|
| 32 |
|
| 33 |
+
self.llm_model = None
|
| 34 |
+
self.llm_tokenizer = None
|
| 35 |
+
self.load_llm_model(self.active_model_info)
|
|
|
|
|
|
|
|
|
|
| 36 |
|
| 37 |
+
self.update_mode_active = False
|
| 38 |
|
| 39 |
def load_llm_model(self, model_info):
|
| 40 |
+
"""Loads the LLM model and tokenizer based on model_info with 4-bit quantization."""
|
| 41 |
if not model_info:
|
| 42 |
error_message = "Error: Model information not provided."
|
| 43 |
+
logging.error(error_message)
|
| 44 |
self.llm_model = None
|
| 45 |
self.llm_tokenizer = None
|
| 46 |
return
|
|
|
|
| 49 |
model_name = model_info.get('name')
|
| 50 |
if not model_id:
|
| 51 |
error_message = f"Error: 'model_id' not found for model: {model_name}"
|
| 52 |
+
logging.error(error_message)
|
| 53 |
self.llm_model = None
|
| 54 |
self.llm_tokenizer = None
|
| 55 |
return
|
| 56 |
|
| 57 |
+
print(f"Loading model: {model_name} ({model_id}) with 4-bit quantization...") # Indicate quantization
|
| 58 |
try:
|
| 59 |
+
bnb_config = BitsAndBytesConfig( # Configure 4-bit quantization
|
| 60 |
+
load_in_4bit=True,
|
| 61 |
+
bnb_4bit_quant_type="nf4", # "nf4" is recommended for Llama models
|
| 62 |
+
bnb_4bit_compute_dtype=torch.bfloat16, # Or torch.float16 if bfloat16 not supported
|
| 63 |
+
)
|
| 64 |
self.llm_tokenizer = AutoTokenizer.from_pretrained(model_id)
|
| 65 |
+
self.llm_model = AutoModelForCausalLM.from_pretrained(
|
| 66 |
+
model_id,
|
| 67 |
+
device_map="auto",
|
| 68 |
+
quantization_config=bnb_config # Apply quantization config
|
| 69 |
+
)
|
| 70 |
+
print(f"Model {model_name} loaded successfully with 4-bit quantization.") # Indicate quantization success
|
| 71 |
except Exception as e:
|
| 72 |
+
error_message = f"Error loading model {model_name} ({model_id}) with 4-bit quantization: {e}"
|
| 73 |
+
logging.exception(error_message)
|
| 74 |
self.llm_model = None
|
| 75 |
self.llm_tokenizer = None
|
| 76 |
self.active_model_info = model_info
|
|
|
|
| 85 |
return f"Switched to model: {model_info.get('name')}"
|
| 86 |
else:
|
| 87 |
error_message = f"Error: Model key '{model_key}' not found in available models."
|
| 88 |
+
logging.error(error_message)
|
| 89 |
+
return error_message
|
| 90 |
|
| 91 |
def enter_update_mode(self):
|
| 92 |
"""Enters the chatbot's update mode."""
|
|
|
|
| 116 |
print("Configuration reloaded.")
|
| 117 |
except Exception as e:
|
| 118 |
error_message = f"Error reloading configuration files: {e}"
|
| 119 |
+
logging.exception(error_message)
|
| 120 |
+
print(error_message)
|
| 121 |
|
| 122 |
def get_chatbot_greeting(self):
|
| 123 |
current_model_name = self.active_model_info.get('name', 'Unknown Model') if self.active_model_info else 'Unknown Model'
|
| 124 |
+
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
|
| 125 |
|
| 126 |
def generate_llm_response(self, user_query):
|
| 127 |
"""Generates a response using the currently active LLM."""
|
| 128 |
if not self.llm_model or not self.llm_tokenizer:
|
| 129 |
error_message = "LLM model not loaded. Please select a model."
|
| 130 |
+
logging.error(error_message)
|
| 131 |
+
return error_message
|
| 132 |
try:
|
| 133 |
inputs = self.llm_tokenizer(user_query, return_tensors="pt").to(self.llm_model.device)
|
| 134 |
+
outputs = self.llm_model.generate(**inputs, max_length=self.max_response_tokens, num_beams=5, no_repeat_ngram_size=2, early_stopping=True)
|
| 135 |
response = self.llm_tokenizer.decode(outputs[0], skip_special_tokens=True)
|
| 136 |
return response
|
| 137 |
except Exception as e:
|
| 138 |
error_message = f"Error generating LLM response: {e}"
|
| 139 |
+
logging.exception(error_message)
|
| 140 |
+
return self.response_config.get('error_message', "Sorry, something went wrong.")
|
| 141 |
|
| 142 |
def process_query(self, user_query):
|
| 143 |
secret_command_prefix = "sagor is python/"
|
|
|
|
| 151 |
elif command == "help":
|
| 152 |
return self.get_update_mode_help()
|
| 153 |
elif self.update_mode_active:
|
|
|
|
|
|
|
| 154 |
parts = command.split()
|
| 155 |
if parts and parts[0] == "modify_rule":
|
| 156 |
if len(parts) >= 4:
|
|
|
|
| 161 |
return self.modify_rule_in_config(category, rule_key, new_rule_text)
|
| 162 |
else:
|
| 163 |
return "Invalid 'modify_rule' command format. Usage: modify_rule <category> <rule_key> <new rule text>"
|
| 164 |
+
elif parts and parts[0] == "add_phase":
|
| 165 |
+
return "Command 'add_phase' is not yet implemented in this example."
|
|
|
|
| 166 |
else:
|
| 167 |
return f"Unknown update command: {command}. Type 'sagor is python/help' for commands."
|
| 168 |
else:
|
| 169 |
return f"Unknown command (not in update mode): {command}. To enter update mode, type 'sagor is python/start'."
|
| 170 |
|
|
|
|
| 171 |
if self.update_mode_active:
|
| 172 |
return "In update mode. Please enter a configuration command (or 'sagor is python/help' for commands)."
|
| 173 |
|
|
|
|
| 174 |
if not self.phases:
|
| 175 |
return "Error: Roadmap data not loaded correctly."
|
| 176 |
if not self.rules:
|
|
|
|
| 192 |
return switch_result + "\n" + self.get_chatbot_greeting()
|
| 193 |
return f"Model '{model_name_or_key}' not found in available models."
|
| 194 |
|
|
|
|
| 195 |
if self.current_phase:
|
| 196 |
current_phase_data = self.phases.get(self.current_phase)
|
| 197 |
if current_phase_data:
|
|
|
|
| 221 |
help_message += "\nMake sure to use the correct syntax for commands. After exiting update mode, the chatbot will reload the configuration."
|
| 222 |
return help_message
|
| 223 |
|
|
|
|
| 224 |
def modify_rule_in_config(self, category, rule_key, new_rule_text):
|
| 225 |
"""Modifies a rule in the rules.yaml configuration."""
|
| 226 |
if not self.rules_data or 'project_rules' not in self.rules_data:
|
| 227 |
error_message = "Error: Rules data not loaded or invalid format."
|
| 228 |
+
logging.error(error_message)
|
| 229 |
+
return error_message
|
| 230 |
if category not in self.rules_data['project_rules']:
|
| 231 |
error_message = f"Error: Rule category '{category}' not found."
|
| 232 |
+
logging.error(error_message)
|
| 233 |
+
return error_message
|
| 234 |
if rule_key not in self.rules_data['project_rules'][category]:
|
| 235 |
error_message = f"Error: Rule key '{rule_key}' not found in category '{category}'."
|
| 236 |
+
logging.error(error_message)
|
| 237 |
+
return error_message
|
| 238 |
|
| 239 |
+
self.rules_data['project_rules'][category][rule_key] = new_rule_text
|
| 240 |
|
| 241 |
try:
|
| 242 |
with open(self.rules_file, 'w') as f:
|
| 243 |
+
yaml.dump(self.rules_data, f, indent=2)
|
| 244 |
+
self.reload_config()
|
| 245 |
return f"Rule '{rule_key}' in category '{category}' updated to: '{new_rule_text}'. Configuration reloaded."
|
| 246 |
except Exception as e:
|
| 247 |
error_message = f"Error saving changes to {self.rules_file}: {e}"
|
| 248 |
+
logging.exception(error_message)
|
| 249 |
+
return error_message
|
|
|
|
| 250 |
|
| 251 |
def get_roadmap_summary(self):
|
| 252 |
summary = "Project Roadmap:\n"
|
|
|
|
| 291 |
|
| 292 |
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?"
|
| 293 |
|
|
|
|
| 294 |
def generate_code_snippet(self, template_filepath, phase_data):
|
| 295 |
"""Generates code snippet from a template file. (Simple template filling example)"""
|
| 296 |
try:
|
|
|
|
| 304 |
except Exception as e:
|
| 305 |
return f"Error generating code snippet: {e}"
|
| 306 |
|
|
|
|
| 307 |
# Example usage (for testing - remove or adjust for app.py)
|
| 308 |
if __name__ == '__main__':
|
| 309 |
chatbot = ProjectGuidanceChatbot(
|