Files
command-assistant/edison/core/prompt_manager.py
T
2025-04-09 09:34:15 +02:00

55 lines
1.6 KiB
Python

"""
Prompt management for the Edison application.
"""
import os
import logging
from edison.utils import os_utils
logger = logging.getLogger(__name__)
def get_prompt_template_path():
"""
Get the path to the prompt template file.
Returns:
str: The path to the prompt template file.
"""
script_dir = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
return os.path.join(script_dir, "edison.prompt")
def get_full_prompt(user_prompt, shell):
"""
Construct a full prompt from the template and user input.
Args:
user_prompt (str): The user's prompt.
shell (str): The shell to use.
Returns:
str: The full prompt.
"""
# Get the path to the prompt template
prompt_file = get_prompt_template_path()
try:
# Load the prompt template
with open(prompt_file, "r") as f:
pre_prompt = f.read()
# Replace placeholders
pre_prompt = pre_prompt.replace("{shell}", shell)
pre_prompt = pre_prompt.replace("{os}", os_utils.get_os_friendly_name())
# Append the user prompt
prompt = pre_prompt + user_prompt
# Make it a question if it's not already
if prompt[-1:] != "?" and prompt[-1:] != ".":
prompt += "?"
return prompt
except Exception as e:
logger.error(f"Error loading prompt template: {e}")
# Fallback to a simple prompt
return f"Act as a natural language to {shell} command translation engine on {os_utils.get_os_friendly_name()}. {user_prompt}"