diff --git a/README.md b/README.md index 74a6da1..a559e72 100644 --- a/README.md +++ b/README.md @@ -208,6 +208,11 @@ python interpreter.py -m 'code-llama' -md 'code' -s python interpreter.py -m 'gemini-pro' -md 'code' -s -l 'language-name' ``` +- Switching to File mode for prompt input
+```python +python interpreter.py -m 'gemini-pro' -md 'code' --file +``` + - Using Upgrade interpreter
```python python interpreter.py --upgrade @@ -231,6 +236,7 @@ Here are the available commands: - 🚪 `/exit` - Exit the interpreter. - 📜 `/log` - Toggle different modes of logging. - ⏫ `/upgrade` - Upgrade the interpreter. +- 📁 `/prompt` - Switch the prompt mode. - 💻 `/shell` - Access the shell. ## ⚙️ **Settings** @@ -307,6 +313,7 @@ If you're interested in contributing to **Code-Interpreter**, we'd love to have 🔥 **v2.1** - Added AnhtorpicAI Claude-3 models powerful _Opus,Sonnet,Haiku_ models. - **v2.1.1** - Added **Groq-AI** Model _Gemma-7B_ with **700 Tokens/Sec**. +- **v2.1.2** - Added **Prompt input Mode** now you can input prompt from file as well. ## 📜 **License** diff --git a/interpreter.py b/interpreter.py index 0de71f3..5710fc6 100755 --- a/interpreter.py +++ b/interpreter.py @@ -24,7 +24,7 @@ from libs.utility_manager import UtilityManager # The main version of the interpreter. -INTERPRETER_VERSION = "2.1.1" +INTERPRETER_VERSION = "2.1.2" def main(): parser = argparse.ArgumentParser(description='Code - Interpreter') @@ -37,6 +37,7 @@ def main(): parser.add_argument('--display_code', '-dc', action='store_true', default=False, help='Display the code in output') parser.add_argument('--history', '-hi', action='store_true', default=False, help='Use history as memory') parser.add_argument('--upgrade', '-up', action='store_true', default=False, help='Upgrade the interpreter') + parser.add_argument('--file', '-f', type=str, nargs='?', const='prompt.txt', default=None, help='Sets the file to read the input prompt from') args = parser.parse_args() # Check if only the application name is passed diff --git a/libs/interpreter_lib.py b/libs/interpreter_lib.py index 49a3f36..72f8af0 100644 --- a/libs/interpreter_lib.py +++ b/libs/interpreter_lib.py @@ -57,6 +57,16 @@ def initialize(self): self.system_message = "" self.INTERPRETER_MODE = 'code' + if self.args.file is None: + self.INTERPRETER_PROMPT_FILE = False + self.INTERPRETER_PROMPT_INPUT = True + else: + self.INTERPRETER_PROMPT_FILE = True + self.INTERPRETER_PROMPT_INPUT = False + # If the user didn't provide a file name, use the default one + if self.args.file == '': + self.args.file = 'prompt.txt' + # Set the history optional(Argparse) if hasattr(self.args, 'history'): self.INTERPRETER_HISTORY = self.args.history @@ -452,16 +462,59 @@ def interpreter_main(self,version): self.logger.info(f"Mode: {self.INTERPRETER_MODE} Start separator: {start_sep}, End separator: {end_sep}, Skip first line: {skip_first_line}") # Display system and Assistant information. - display_code(f"OS: '{os_name}', Language: '{self.INTERPRETER_LANGUAGE}', Mode: '{self.INTERPRETER_MODE}' Model: '{self.INTERPRETER_MODEL}'") - display_markdown_message("Welcome to the **Interpreter**. I'm here to **assist** you with your everyday tasks. " - "\nPlease enter your task and I'll do my best to help you out.") + input_prompt_mode = "File" if self.INTERPRETER_PROMPT_FILE else "Input" + display_code(f"OS: '{os_name}', Language: '{self.INTERPRETER_LANGUAGE}', Mode: '{self.INTERPRETER_MODE}', Prompt: '{input_prompt_mode}', Model: '{self.INTERPRETER_MODEL}'") + + # Display the welcome message. + display_markdown_message("Welcome to the **Interpreter**, I'm here to **assist** you with your everyday tasks. " + "\nEnter your task and I'll do my best to help you out.") # Main System and Assistant loop. running = True while running: try: - # Main input prompt - System and Assistant. - task = input("> ") + task = None + + if self.INTERPRETER_PROMPT_INPUT: + self.logger.info(f"Reading prompt from input.") + # Main input prompt - System and Assistant. + task = input("> ") + elif self.INTERPRETER_PROMPT_FILE: + prompt_file_name = self.args.file + + # Setting the prompt file path. + if not prompt_file_name: + prompt_file_name = 'prompt.txt' + + prompt_file_path = os.path.join(os.getcwd(),'system',prompt_file_name) + display_markdown_message(f"\nEnter your task in the file **'{prompt_file_path}'**") + + # File mode command section. + prompt_confirmation = input(f"Execute the prompt (Y/N/P/C) (P = Prompt Mode,C = Command Mode)?: ") + if prompt_confirmation.lower() == 'y': + self.logger.info(f"Executing prompt from file.") + + self.logger.info(f"Executing prompt from file {prompt_file_path}") + task = self.utility_manager.read_file(prompt_file_path) + elif prompt_confirmation.lower() == 'n': + self.logger.info(f"Waiting for user confirmation to execute prompt from file.") + print("Waiting for user confirmation to execute prompt from file.") + self.utility_manager.clear_screen() + continue + elif prompt_confirmation.lower() == 'p': + self.INTERPRETER_PROMPT_INPUT = True + self.INTERPRETER_PROMPT_FILE = False + self.logger.info(f"Changing input mode to prompt from file.") + self.utility_manager.clear_screen() + continue + elif prompt_confirmation.lower() == 'c': + self.logger.info(f"Changing input mode to command from file.") + task = input("> ") + else: + # Invalid input mode (0x000022) + self.logger.error("Invalid input mode.") + self.utility_manager.clear_screen() + continue # EXIT - Command section. if task.lower() == '/exit': @@ -482,6 +535,18 @@ def interpreter_main(self,version): self.utility_manager.display_version(self.interpreter_version) continue + # PROMPT - Command section. + elif task.lower() == '/prompt': + if self.INTERPRETER_PROMPT_INPUT: + self.INTERPRETER_PROMPT_INPUT = False + self.INTERPRETER_PROMPT_FILE = True + self.logger.info(f"Input mode changed to File.") + else: + self.INTERPRETER_PROMPT_INPUT = True + self.INTERPRETER_PROMPT_FILE = False + self.logger.info(f"Input mode changed to Prompt.") + continue + # HISTORY - Command section. elif task.lower() == '/history': self.INTERPRETER_HISTORY = not self.INTERPRETER_HISTORY @@ -643,7 +708,7 @@ def interpreter_main(self,version): if model: model_config_file = f"configs/{model}.config" if not os.path.isfile(model_config_file): - display_markdown_message(f"Model {model} does not exists. Please check the model name.") + display_markdown_message(f"Model {model} does not exists. Please check the model name using '/list' command.") continue else: self.INTERPRETER_MODEL = model diff --git a/libs/utility_manager.py b/libs/utility_manager.py index e0fbedb..dc7e995 100644 --- a/libs/utility_manager.py +++ b/libs/utility_manager.py @@ -213,6 +213,7 @@ def display_help(self): /list - List the available models.\n\ /version - Display the version of the interpreter.\n\ /log - Switch between Verbose and Silent mode.\n\ + /prompt - Switch input prompt mode between file and prompt.\n\ /upgrade - Upgrade the interpreter.\n\ /shell - Access the shell.\n") @@ -221,6 +222,22 @@ def display_version(self,version): def clear_screen(self): os.system('cls' if os.name == 'nt' else 'clear') + + def read_file(self, file_path): + try: + with open(file_path, "r") as file: + return file.read() + except Exception as exception: + self.logger.error(f"Error in reading file: {str(exception)}") + raise + + def write_file(self, file_path, content): + try: + with open(file_path, "w") as file: + file.write(content) + except Exception as exception: + self.logger.error(f"Error in writing file: {str(exception)}") + raise # method to download file from Web and save it diff --git a/system/prompt.txt b/system/prompt.txt new file mode 100644 index 0000000..0d5fd0f --- /dev/null +++ b/system/prompt.txt @@ -0,0 +1 @@ +Enter your prompt in plain text here for Code Interpreter to execute. \ No newline at end of file