/home/project_murky/chat/pages/notes
/home/project_murky/chat/pages/scripts
/home/project_murky/chat/pages/settings
import os
import subprocess
import json
from huggingface_hub import InferenceClient
Initialize Hugging Face client
client = InferenceClient("HuggingFaceH4/zephyr-7b-beta")
Load script paths and command mappings from JSON configuration
def load_config(config_path):
try:
with open(config_path, 'r') as file:
config = json.load(file)
return config["scripts"], config["commands"]
except (json.JSONDecodeError, IOError) as e:
print(f"Failed to load configuration file '{config_path}': {e}")
return {}, {}
Paths to configuration file
CONFIG_PATH = '/home/project_murky/chat/config/script_paths.json'
SCRIPT_PATHS, COMMAND_LIST = load_config(CONFIG_PATH)
def run_script(script_name):
"""Run the specified script using subprocess."""
script_path = SCRIPT_PATHS.get(script_name)
if script_path and os.path.exists(script_path):
try:
process = subprocess.Popen(['python3', script_path])
process.wait() # Wait for the process to complete
except Exception as e:
print(f"An error occurred while running script {script_name}: {e}")
else:
print(f"Script '{script_name}' not found at configured path.")
def ai_understand_command(user_input):
"""Use AI to understand and determine the task based on user input."""
try:
prompt = ("Determine if the input command relates to 'add', 'edit', or 'search'. "
"Respond with only the most relevant keyword: 'add', 'edit', or 'search'.")
ai_response = client.chat_completion([{"role": "user", "content": user_input}]).choices[0].message['content'].strip().lower()
if ai_response in SCRIPT_PATHS:
return ai_response
print(f"AI interpreted command as: '{ai_response}'. Cannot map to expected tasks.")
return None
except Exception as e:
print(f"Failed to understand command with AI: {e}")
return None
def display_command_options():
"""Display available command options."""
print("\nAvailable Commands:")
for number, command in COMMAND_LIST.items():
print(f"{number}. {command.capitalize()} Note")
def display_settings_menu():
"""Display settings menu options."""
print("\nSettings Menu:")
print("1. View Hierarchical Project Structure")
print("2. Customize AI Parameters")
print("3. Edit Script Paths")
print("0. Back to Main Menu")
def view_project_structure(base_folder):
"""Display the hierarchical structure of the project."""
if os.path.exists(base_folder):
for root, dirs, files in os.walk(base_folder):
level = root.replace(base_folder, '').count(os.sep)
indent = ' ' * 4 * (level)
print(f"{indent}{os.path.basename(root)}/")
sub_indent = ' ' * 4 * (level + 1)
for f in files:
print(f"{sub_indent}{f}")
else:
print(f"Base folder '{base_folder}' does not exist.")
def customize_ai_parameters():
"""Allow user to customize AI parameters."""
# Here, implement the logic to customize parameters like human threshold and max token values
pass
def edit_script_paths():
"""Allow user to edit script paths."""
# Here, implement the logic to view, add, or edit script paths
pass
def main():
print("Welcome to the Advanced Master Chat Assistant")
display_command_options()
while True:
user_input = input("Enter a command number, type the command, or type 'exit' to quit: ").strip().lower()
if user_input == 'exit':
print("Exiting Master Chat Assistant.")
break
if user_input in COMMAND_LIST:
task_type = COMMAND_LIST[user_input]
else:
task_type = ai_understand_command(user_input)
if task_type:
print(f"Running '{task_type}' script...")
run_script(task_type)
print("\n" + "-" * 30) # Divider line after running the script
display_command_options() # Display the menu again
else:
print(f"The command '{user_input}' could not be mapped to any task by the AI. Please try again.")
print("\n" + "-" * 30) # Divider line for unsuccessful mapping
display_command_options() # Display the menu again
# After displaying command options, check for settings
display_settings_menu()
settings_choice = input("Choose a settings option (0 to go back): ")
if settings_choice == '1':
base_folder = input("Enter the base folder path for project structure: ")
view_project_structure(base_folder)
elif settings_choice == '2':
customize_ai_parameters()
elif settings_choice == '3':
edit_script_paths()
elif settings_choice == '0':
continue
else:
print("Invalid choice. Please try again.")
if name == "main":
main()