rogerthat11 commited on
Commit
c3a4273
Β·
1 Parent(s): 3cedfb2

This Space has encountered a runtime error that prevents it from running.

Browse files
.gitattributes CHANGED
@@ -33,3 +33,4 @@ saved_model/**/* 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
 
 
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/.gitattributes_20250202080908 ADDED
@@ -0,0 +1,35 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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 ADDED
@@ -0,0 +1,36 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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 ADDED
@@ -0,0 +1,57 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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 ADDED
@@ -0,0 +1,57 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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/rules_20250202080908.yaml ADDED
@@ -0,0 +1,78 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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 ADDED
@@ -0,0 +1,78 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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 ADDED
@@ -0,0 +1,78 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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 ADDED
@@ -0,0 +1,326 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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 necessary classes
4
+ import yaml # Import yaml for config modification
5
+ import logging # Import logging
6
+
7
+ # Set up logging
8
+ logging.basicConfig(level=logging.ERROR, # Set default logging level to ERROR
9
+ format='%(asctime)s - %(levelname)s - %(message)s')
10
+
11
+ class ProjectGuidanceChatbot:
12
+ def __init__(self, roadmap_file, rules_file, config_file, code_templates_dir):
13
+ self.roadmap_file = roadmap_file
14
+ self.rules_file = rules_file
15
+ self.config_file = config_file
16
+ self.code_templates_dir = code_templates_dir
17
+
18
+ self.roadmap_data = load_yaml_file(self.roadmap_file)
19
+ self.rules_data = load_yaml_file(self.rules_file)
20
+ self.config_data = load_yaml_file(self.config_file)
21
+
22
+ self.phases = get_roadmap_phases(self.roadmap_data)
23
+ self.rules = get_project_rules(self.rules_data)
24
+ self.chatbot_config = self.config_data.get('chatbot', {}) if self.config_data else {}
25
+ self.model_config = self.config_data.get('model_selection', {}) if self.config_data else {}
26
+ self.response_config = self.config_data.get('response_generation', {}) if self.config_data else {}
27
+ self.available_models_config = self.config_data.get('available_models', {}) if self.config_data else {}
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') # Get default model key
32
+ self.active_model_info = self.available_models_config.get(self.active_model_key) # Get model info from config
33
+
34
+ # Placeholder for actual model and tokenizer - replace with LLM loading logic
35
+ self.llm_model = None # Placeholder for loaded model
36
+ self.llm_tokenizer = None # Placeholder for tokenizer
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) # Log the error
47
+ self.llm_model = None
48
+ self.llm_tokenizer = None
49
+ return
50
+
51
+ model_id = model_info.get('model_id')
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) # Log the error
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(model_id, device_map="auto") # device_map="auto" for GPU/CPU handling
64
+ print(f"Model {model_name} loaded successfully.")
65
+ except Exception as e:
66
+ error_message = f"Error loading model {model_name} ({model_id}): {e}"
67
+ logging.exception(error_message) # Log exception with traceback
68
+ self.llm_model = None
69
+ self.llm_tokenizer = None
70
+ self.active_model_info = model_info
71
+
72
+ def switch_llm_model(self, model_key):
73
+ """Switches the active LLM model based on the provided model key."""
74
+ if model_key in self.available_models_config:
75
+ model_info = self.available_models_config[model_key]
76
+ print(f"Switching LLM model to: {model_info.get('name')}")
77
+ self.load_llm_model(model_info)
78
+ self.active_model_key = model_key
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) # Log the error
83
+ return error_message # Return error message to UI
84
+
85
+ def enter_update_mode(self):
86
+ """Enters the chatbot's update mode."""
87
+ self.update_mode_active = True
88
+ return "Entering update mode. Please enter configuration commands (or 'sagor is python/help' for commands)."
89
+
90
+ def exit_update_mode(self):
91
+ """Exits the chatbot's update mode and reloads configuration."""
92
+ self.update_mode_active = False
93
+ self.reload_config()
94
+ return "Exiting update mode. Configuration reloaded."
95
+
96
+ def reload_config(self):
97
+ """Reloads configuration files."""
98
+ print("Reloading configuration...")
99
+ try:
100
+ self.config_data = load_yaml_file(self.config_file)
101
+ self.roadmap_data = load_yaml_file(self.roadmap_file)
102
+ self.rules_data = load_yaml_file(self.rules_file)
103
+ self.chatbot_config = self.config_data.get('chatbot', {}) if self.config_data else {}
104
+ self.model_config = self.config_data.get('model_selection', {}) if self.config_data else {}
105
+ self.response_config = self.config_data.get('response_generation', {}) if self.config_data else {}
106
+ self.available_models_config = self.config_data.get('available_models', {}) if self.config_data else {}
107
+ self.max_response_tokens = self.chatbot_config.get('max_response_tokens', 200)
108
+ self.phases = get_roadmap_phases(self.roadmap_data)
109
+ self.rules = get_project_rules(self.rules_data)
110
+ print("Configuration reloaded.")
111
+ except Exception as e:
112
+ error_message = f"Error reloading configuration files: {e}"
113
+ logging.exception(error_message) # Log exception with traceback
114
+ print(error_message) # Print to console as well, as reloading might be critical
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}**. Max response tokens: {self.max_response_tokens}. {self.chatbot_config.get('description', 'How can I help you with your project?')}"
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) # Log the error
125
+ return error_message # Return error to UI
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) # Use max_response_tokens
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) # Log exception with traceback
134
+ return self.response_config.get('error_message', "Sorry, something went wrong.") # Return generic error to UI
135
+
136
+ def process_query(self, user_query):
137
+ secret_command_prefix = "sagor is python/"
138
+
139
+ if user_query.startswith(secret_command_prefix):
140
+ command = user_query[len(secret_command_prefix):].strip()
141
+ if command == "start":
142
+ return self.enter_update_mode()
143
+ elif command == "exit":
144
+ return self.exit_update_mode()
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:
153
+ category = parts[1]
154
+ rule_key = parts[2]
155
+ new_rule_text_parts = parts[3:]
156
+ new_rule_text = " ".join(new_rule_text_parts)
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": # Example for adding phase - you'll need to expand this logic
161
+ # ... (Parsing logic for 'add_phase' command and calling a function to modify roadmap.yaml) ...
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:
176
+ return "Error: Rules data not loaded correctly."
177
+
178
+ query_lower = user_query.lower()
179
+
180
+ if "roadmap" in query_lower:
181
+ return self.get_roadmap_summary()
182
+ if "rules" in query_lower:
183
+ return self.get_rules_summary()
184
+ if "switch model to" in query_lower:
185
+ parts = user_query.lower().split("switch model to")
186
+ if len(parts) > 1:
187
+ model_name_or_key = parts[1].strip()
188
+ for key, model_data in self.available_models_config.items():
189
+ if model_data['name'].lower() == model_name_or_key.lower() or key.lower() == model_name_or_key.lower():
190
+ switch_result = self.switch_llm_model(key)
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:
198
+ phase_response = self.get_phase_guidance(current_phase_data, user_query)
199
+ if phase_response:
200
+ return phase_response
201
+
202
+ for phase_key, phase_data in self.phases.items():
203
+ if phase_data['name'].lower() in query_lower:
204
+ self.current_phase = phase_key
205
+ return self.get_phase_introduction(phase_data)
206
+
207
+ llm_response = self.generate_llm_response(user_query)
208
+ if llm_response:
209
+ return llm_response
210
+
211
+ return self.response_config.get('default_instruction', "How can I help you with your project phases or general questions?")
212
+
213
+ def get_update_mode_help(self):
214
+ """Provides help message for update mode commands."""
215
+ help_message = "Update Mode Commands:\n"
216
+ help_message += "- `sagor is python/exit`: Exit update mode and reload configuration.\n"
217
+ help_message += "- `sagor is python/modify_rule <category> <rule_key> <new rule text>`: Modify a rule in rules.yaml.\n"
218
+ help_message += " Example: `sagor is python/modify_rule general rule_1 Prioritize open and responsible AI.`\n"
219
+ help_message += "- `sagor is python/add_phase ...`: (Not yet implemented) Add a new phase to roadmap.yaml.\n"
220
+ help_message += "- `sagor is python/help`: Show this help message.\n"
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) # Log the error
230
+ return error_message # Return error to UI
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) # Log the error
234
+ return error_message # Return error to UI
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) # Log the error
238
+ return error_message # Return error to UI
239
+
240
+ self.rules_data['project_rules'][category][rule_key] = new_rule_text # Update rule in memory
241
+
242
+ try:
243
+ with open(self.rules_file, 'w') as f:
244
+ yaml.dump(self.rules_data, f, indent=2) # Save changes to rules.yaml
245
+ self.reload_config() # Reload config to reflect changes immediately
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) # Log exception with traceback
250
+ return error_message # Return error to UI
251
+
252
+
253
+ def get_roadmap_summary(self):
254
+ summary = "Project Roadmap:\n"
255
+ for phase_key, phase_data in self.phases.items():
256
+ summary += f"- **Phase: {phase_data['name']}**\n"
257
+ summary += f" Description: {phase_data['description']}\n"
258
+ summary += f" Milestones: {', '.join(phase_data['milestones'])}\n"
259
+ return summary
260
+
261
+ def get_rules_summary(self):
262
+ summary = "Project Rules:\n"
263
+ for rule_category, rules_list in self.rules.items():
264
+ summary += f"**{rule_category.capitalize()} Rules:**\n"
265
+ for rule_key, rule_text in rules_list.items():
266
+ summary += f"- {rule_text}\n"
267
+ return summary
268
+
269
+ def get_phase_introduction(self, phase_data):
270
+ 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?"
271
+
272
+ def get_phase_guidance(self, phase_data, user_query):
273
+ query_lower = user_query.lower()
274
+
275
+ if "milestones" in query_lower:
276
+ return "The milestones for this phase are: " + ", ".join(phase_data['milestones'])
277
+ if "actions" in query_lower or "how to" in query_lower:
278
+ if 'actions' in phase_data:
279
+ return "Recommended actions for this phase: " + ", ".join(phase_data['actions'])
280
+ else:
281
+ return "No specific actions are listed for this phase in the roadmap."
282
+ if "code" in query_lower or "script" in query_lower:
283
+ if 'code_generation_hint' in phase_data:
284
+ template_filename_prefix = phase_data['name'].lower().replace(" ", "_")
285
+ template_filepath = os.path.join(self.code_templates_dir, f"{template_filename_prefix}_template.py.txt")
286
+ if os.path.exists(template_filepath):
287
+ code_snippet = self.generate_code_snippet(template_filepath, phase_data)
288
+ 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."
289
+ else:
290
+ return f"A code template for this phase ({phase_data['name']}) is not yet available. However, the hint is: {phase_data['code_generation_hint']}"
291
+ else:
292
+ return "No code generation hint is available for this phase."
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:
300
+ with open(template_filepath, 'r') as f:
301
+ template_content = f.read()
302
+
303
+ code_snippet = template_content.replace("{{phase_name}}", phase_data['name'])
304
+ return code_snippet
305
+ except FileNotFoundError:
306
+ return f"Error: Code template file not found at {template_filepath}"
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(
314
+ roadmap_file="roadmap.yaml",
315
+ rules_file="rules.yaml",
316
+ config_file="configs/chatbot_config.yaml",
317
+ code_templates_dir="scripts/code_templates"
318
+ )
319
+ print(chatbot.get_chatbot_greeting())
320
+
321
+ while True:
322
+ user_input = input("You: ")
323
+ if user_input.lower() == "exit":
324
+ break
325
+ response = chatbot.process_query(user_input)
326
+ print("Chatbot:", response)
.history/scripts/chatbot_logic_20250202080928.py ADDED
@@ -0,0 +1,326 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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 necessary classes
4
+ import yaml # Import yaml for config modification
5
+ import logging # Import logging
6
+
7
+ # Set up logging
8
+ logging.basicConfig(level=logging.ERROR, # Set default logging level to ERROR
9
+ format='%(asctime)s - %(levelname)s - %(message)s')
10
+
11
+ class ProjectGuidanceChatbot:
12
+ def __init__(self, roadmap_file, rules_file, config_file, code_templates_dir):
13
+ self.roadmap_file = roadmap_file
14
+ self.rules_file = rules_file
15
+ self.config_file = config_file
16
+ self.code_templates_dir = code_templates_dir
17
+
18
+ self.roadmap_data = load_yaml_file(self.roadmap_file)
19
+ self.rules_data = load_yaml_file(self.rules_file)
20
+ self.config_data = load_yaml_file(self.config_file)
21
+
22
+ self.phases = get_roadmap_phases(self.roadmap_data)
23
+ self.rules = get_project_rules(self.rules_data)
24
+ self.chatbot_config = self.config_data.get('chatbot', {}) if self.config_data else {}
25
+ self.model_config = self.config_data.get('model_selection', {}) if self.config_data else {}
26
+ self.response_config = self.config_data.get('response_generation', {}) if self.config_data else {}
27
+ self.available_models_config = self.config_data.get('available_models', {}) if self.config_data else {}
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') # Get default model key
32
+ self.active_model_info = self.available_models_config.get(self.active_model_key) # Get model info from config
33
+
34
+ # Placeholder for actual model and tokenizer - replace with LLM loading logic
35
+ self.llm_model = None # Placeholder for loaded model
36
+ self.llm_tokenizer = None # Placeholder for tokenizer
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) # Log the error
47
+ self.llm_model = None
48
+ self.llm_tokenizer = None
49
+ return
50
+
51
+ model_id = model_info.get('model_id')
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) # Log the error
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(model_id, device_map="auto") # device_map="auto" for GPU/CPU handling
64
+ print(f"Model {model_name} loaded successfully.")
65
+ except Exception as e:
66
+ error_message = f"Error loading model {model_name} ({model_id}): {e}"
67
+ logging.exception(error_message) # Log exception with traceback
68
+ self.llm_model = None
69
+ self.llm_tokenizer = None
70
+ self.active_model_info = model_info
71
+
72
+ def switch_llm_model(self, model_key):
73
+ """Switches the active LLM model based on the provided model key."""
74
+ if model_key in self.available_models_config:
75
+ model_info = self.available_models_config[model_key]
76
+ print(f"Switching LLM model to: {model_info.get('name')}")
77
+ self.load_llm_model(model_info)
78
+ self.active_model_key = model_key
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) # Log the error
83
+ return error_message # Return error message to UI
84
+
85
+ def enter_update_mode(self):
86
+ """Enters the chatbot's update mode."""
87
+ self.update_mode_active = True
88
+ return "Entering update mode. Please enter configuration commands (or 'sagor is python/help' for commands)."
89
+
90
+ def exit_update_mode(self):
91
+ """Exits the chatbot's update mode and reloads configuration."""
92
+ self.update_mode_active = False
93
+ self.reload_config()
94
+ return "Exiting update mode. Configuration reloaded."
95
+
96
+ def reload_config(self):
97
+ """Reloads configuration files."""
98
+ print("Reloading configuration...")
99
+ try:
100
+ self.config_data = load_yaml_file(self.config_file)
101
+ self.roadmap_data = load_yaml_file(self.roadmap_file)
102
+ self.rules_data = load_yaml_file(self.rules_file)
103
+ self.chatbot_config = self.config_data.get('chatbot', {}) if self.config_data else {}
104
+ self.model_config = self.config_data.get('model_selection', {}) if self.config_data else {}
105
+ self.response_config = self.config_data.get('response_generation', {}) if self.config_data else {}
106
+ self.available_models_config = self.config_data.get('available_models', {}) if self.config_data else {}
107
+ self.max_response_tokens = self.chatbot_config.get('max_response_tokens', 200)
108
+ self.phases = get_roadmap_phases(self.roadmap_data)
109
+ self.rules = get_project_rules(self.rules_data)
110
+ print("Configuration reloaded.")
111
+ except Exception as e:
112
+ error_message = f"Error reloading configuration files: {e}"
113
+ logging.exception(error_message) # Log exception with traceback
114
+ print(error_message) # Print to console as well, as reloading might be critical
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}**. Max response tokens: {self.max_response_tokens}. {self.chatbot_config.get('description', 'How can I help you with your project?')}"
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) # Log the error
125
+ return error_message # Return error to UI
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) # Use max_response_tokens
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) # Log exception with traceback
134
+ return self.response_config.get('error_message', "Sorry, something went wrong.") # Return generic error to UI
135
+
136
+ def process_query(self, user_query):
137
+ secret_command_prefix = "sagor is python/"
138
+
139
+ if user_query.startswith(secret_command_prefix):
140
+ command = user_query[len(secret_command_prefix):].strip()
141
+ if command == "start":
142
+ return self.enter_update_mode()
143
+ elif command == "exit":
144
+ return self.exit_update_mode()
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:
153
+ category = parts[1]
154
+ rule_key = parts[2]
155
+ new_rule_text_parts = parts[3:]
156
+ new_rule_text = " ".join(new_rule_text_parts)
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": # Example for adding phase - you'll need to expand this logic
161
+ # ... (Parsing logic for 'add_phase' command and calling a function to modify roadmap.yaml) ...
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:
176
+ return "Error: Rules data not loaded correctly."
177
+
178
+ query_lower = user_query.lower()
179
+
180
+ if "roadmap" in query_lower:
181
+ return self.get_roadmap_summary()
182
+ if "rules" in query_lower:
183
+ return self.get_rules_summary()
184
+ if "switch model to" in query_lower:
185
+ parts = user_query.lower().split("switch model to")
186
+ if len(parts) > 1:
187
+ model_name_or_key = parts[1].strip()
188
+ for key, model_data in self.available_models_config.items():
189
+ if model_data['name'].lower() == model_name_or_key.lower() or key.lower() == model_name_or_key.lower():
190
+ switch_result = self.switch_llm_model(key)
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:
198
+ phase_response = self.get_phase_guidance(current_phase_data, user_query)
199
+ if phase_response:
200
+ return phase_response
201
+
202
+ for phase_key, phase_data in self.phases.items():
203
+ if phase_data['name'].lower() in query_lower:
204
+ self.current_phase = phase_key
205
+ return self.get_phase_introduction(phase_data)
206
+
207
+ llm_response = self.generate_llm_response(user_query)
208
+ if llm_response:
209
+ return llm_response
210
+
211
+ return self.response_config.get('default_instruction', "How can I help you with your project phases or general questions?")
212
+
213
+ def get_update_mode_help(self):
214
+ """Provides help message for update mode commands."""
215
+ help_message = "Update Mode Commands:\n"
216
+ help_message += "- `sagor is python/exit`: Exit update mode and reload configuration.\n"
217
+ help_message += "- `sagor is python/modify_rule <category> <rule_key> <new rule text>`: Modify a rule in rules.yaml.\n"
218
+ help_message += " Example: `sagor is python/modify_rule general rule_1 Prioritize open and responsible AI.`\n"
219
+ help_message += "- `sagor is python/add_phase ...`: (Not yet implemented) Add a new phase to roadmap.yaml.\n"
220
+ help_message += "- `sagor is python/help`: Show this help message.\n"
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) # Log the error
230
+ return error_message # Return error to UI
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) # Log the error
234
+ return error_message # Return error to UI
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) # Log the error
238
+ return error_message # Return error to UI
239
+
240
+ self.rules_data['project_rules'][category][rule_key] = new_rule_text # Update rule in memory
241
+
242
+ try:
243
+ with open(self.rules_file, 'w') as f:
244
+ yaml.dump(self.rules_data, f, indent=2) # Save changes to rules.yaml
245
+ self.reload_config() # Reload config to reflect changes immediately
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) # Log exception with traceback
250
+ return error_message # Return error to UI
251
+
252
+
253
+ def get_roadmap_summary(self):
254
+ summary = "Project Roadmap:\n"
255
+ for phase_key, phase_data in self.phases.items():
256
+ summary += f"- **Phase: {phase_data['name']}**\n"
257
+ summary += f" Description: {phase_data['description']}\n"
258
+ summary += f" Milestones: {', '.join(phase_data['milestones'])}\n"
259
+ return summary
260
+
261
+ def get_rules_summary(self):
262
+ summary = "Project Rules:\n"
263
+ for rule_category, rules_list in self.rules.items():
264
+ summary += f"**{rule_category.capitalize()} Rules:**\n"
265
+ for rule_key, rule_text in rules_list.items():
266
+ summary += f"- {rule_text}\n"
267
+ return summary
268
+
269
+ def get_phase_introduction(self, phase_data):
270
+ 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?"
271
+
272
+ def get_phase_guidance(self, phase_data, user_query):
273
+ query_lower = user_query.lower()
274
+
275
+ if "milestones" in query_lower:
276
+ return "The milestones for this phase are: " + ", ".join(phase_data['milestones'])
277
+ if "actions" in query_lower or "how to" in query_lower:
278
+ if 'actions' in phase_data:
279
+ return "Recommended actions for this phase: " + ", ".join(phase_data['actions'])
280
+ else:
281
+ return "No specific actions are listed for this phase in the roadmap."
282
+ if "code" in query_lower or "script" in query_lower:
283
+ if 'code_generation_hint' in phase_data:
284
+ template_filename_prefix = phase_data['name'].lower().replace(" ", "_")
285
+ template_filepath = os.path.join(self.code_templates_dir, f"{template_filename_prefix}_template.py.txt")
286
+ if os.path.exists(template_filepath):
287
+ code_snippet = self.generate_code_snippet(template_filepath, phase_data)
288
+ 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."
289
+ else:
290
+ return f"A code template for this phase ({phase_data['name']}) is not yet available. However, the hint is: {phase_data['code_generation_hint']}"
291
+ else:
292
+ return "No code generation hint is available for this phase."
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:
300
+ with open(template_filepath, 'r') as f:
301
+ template_content = f.read()
302
+
303
+ code_snippet = template_content.replace("{{phase_name}}", phase_data['name'])
304
+ return code_snippet
305
+ except FileNotFoundError:
306
+ return f"Error: Code template file not found at {template_filepath}"
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(
314
+ roadmap_file="roadmap.yaml",
315
+ rules_file="rules.yaml",
316
+ config_file="configs/chatbot_config.yaml",
317
+ code_templates_dir="scripts/code_templates"
318
+ )
319
+ print(chatbot.get_chatbot_greeting())
320
+
321
+ while True:
322
+ user_input = input("You: ")
323
+ if user_input.lower() == "exit":
324
+ break
325
+ response = chatbot.process_query(user_input)
326
+ print("Chatbot:", response)
rules.yaml CHANGED
@@ -56,23 +56,23 @@ project_rules:
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"
 
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`"