From ca90a22e6b262758b6c33e4da0a117d7b4a3178a Mon Sep 17 00:00:00 2001 From: killian <63927363+KillianLucas@users.noreply.github.com> Date: Sun, 17 Nov 2024 21:04:32 -0800 Subject: [PATCH] Improved CLI, pass through params to LiteLLM --- interpreter_1/cli.py | 6 +++++- interpreter_1/interpreter.py | 17 ++++++++++++++++- interpreter_1/misc/get_input.py | 25 ++++++++++++++++++++----- interpreter_1/misc/help.py | 6 +++--- interpreter_1/misc/welcome.py | 2 +- interpreter_1/profiles.py | 1 + 6 files changed, 46 insertions(+), 11 deletions(-) diff --git a/interpreter_1/cli.py b/interpreter_1/cli.py index 11de43066..14b5c9668 100644 --- a/interpreter_1/cli.py +++ b/interpreter_1/cli.py @@ -143,6 +143,11 @@ def _profile_to_arg_params(profile: Profile) -> Dict[str, Dict[str, Any]]: "default": profile.instructions, "help": "Appended to default system message", }, + "input": { + "flags": ["--input"], + "default": profile.input, + "help": "Pre-fill first user message", + }, "max_turns": { "flags": ["--max-turns"], "type": int, @@ -237,7 +242,6 @@ def parse_args(): parser.add_argument("--help", "-h", action="store_true", help=argparse.SUPPRESS) parser.add_argument("--version", action="store_true", help=argparse.SUPPRESS) - parser.add_argument("--input", action="store", help=argparse.SUPPRESS) parser.add_argument( "--profiles", action="store_true", help="Open profiles directory" ) diff --git a/interpreter_1/interpreter.py b/interpreter_1/interpreter.py index 4ab4e3bf1..3bf2f332f 100644 --- a/interpreter_1/interpreter.py +++ b/interpreter_1/interpreter.py @@ -627,9 +627,16 @@ async def async_respond(self): else: api_base = self.api_base else: + if ( + not self.model.startswith("openai/") + and self.provider == "openai" + ): + actual_model = "openai/" + self.model + else: + actual_model = self.model + stream = True api_base = self.api_base - actual_model = self.model if not self.tool_calling: system_message += "\n\nPLEASE write code to satisfy the user's request, use ```bash\n...\n``` to run code. You CAN run code." @@ -641,6 +648,8 @@ async def async_respond(self): "stream": stream, "api_base": api_base, "temperature": self.temperature, + "api_key": self.api_key, + "api_version": self.api_version, } if self.tool_calling: @@ -652,6 +661,12 @@ async def async_respond(self): if self.debug: print(params) + if self.debug: + print("Sending request...", params) + import time + + time.sleep(3) + raw_response = litellm.completion(**params) if not stream: diff --git a/interpreter_1/misc/get_input.py b/interpreter_1/misc/get_input.py index 9784335f6..e36e80726 100644 --- a/interpreter_1/misc/get_input.py +++ b/interpreter_1/misc/get_input.py @@ -6,7 +6,9 @@ import termios -async def get_input(placeholder_text=None, placeholder_color: str = "gray") -> str: +async def get_input( + placeholder_text=None, placeholder_color: str = "gray", multiline_support=True +) -> str: if placeholder_text is None: common_placeholders = [ "How can I help you?", @@ -15,7 +17,7 @@ async def get_input(placeholder_text=None, placeholder_color: str = "gray") -> s 'Use """ for multi-line input', "Psst... try the wtf command", ] - very_rare_placeholders = ["Let's make history together!"] + very_rare_placeholders = [""] # 69% common, 30% rare, 1% very rare rand = random.random() @@ -56,13 +58,15 @@ async def get_input(placeholder_text=None, placeholder_color: str = "gray") -> s def redraw(): sys.stdout.write("\r\033[K") # Clear line - sys.stdout.write("\r> ") + if multiline_support: + sys.stdout.write("\r> ") if current_input: sys.stdout.write("".join(current_input)) elif show_placeholder: color_code = COLORS.get(placeholder_color.lower(), COLORS["gray"]) sys.stdout.write(f"{color_code}{placeholder_text}{RESET}") - sys.stdout.write("\r> ") + if multiline_support: + sys.stdout.write("\r> ") sys.stdout.flush() try: @@ -74,7 +78,18 @@ def redraw(): if char == "\n": if current_input: result = "".join(current_input) - return result + # Multiline support + if multiline_support and result.startswith('"""'): + while True: + print() + extra_input = await get_input(multiline_support=False) + if extra_input.endswith('"""'): + result += extra_input + return result + else: + result += extra_input + else: + return result else: redraw() elif char == "\x7f": # Backspace diff --git a/interpreter_1/misc/help.py b/interpreter_1/misc/help.py index 5ff267779..13005ceba 100644 --- a/interpreter_1/misc/help.py +++ b/interpreter_1/misc/help.py @@ -74,12 +74,12 @@ def help_message(): def help_message(): print( """ -usage: interpreter [flags] +usage: interpreter [options] i [prompt] A modern command-line assistant. -flags: +options: --model model to use for completion --provider api provider (e.g. openai, anthropic) --api-base base url for api requests @@ -104,7 +104,7 @@ def help_message(): --profiles open profiles directory --serve start openai-compatible server -example: i want a venv here +example: i want a venv example: interpreter --model ollama/llama3.2 --serve example: i -y --input "run pytest, fix errors" example: cat instructions.txt | i diff --git a/interpreter_1/misc/welcome.py b/interpreter_1/misc/welcome.py index 2980aad32..c216e51bb 100644 --- a/interpreter_1/misc/welcome.py +++ b/interpreter_1/misc/welcome.py @@ -301,6 +301,6 @@ def welcome_message(): or: interpreter [options] Documentation: docs.openinterpreter.com -Run 'interpreter --help' for full options +Run 'interpreter --help' for all options """ ) diff --git a/interpreter_1/profiles.py b/interpreter_1/profiles.py index 26a6d5c47..a0919fe51 100644 --- a/interpreter_1/profiles.py +++ b/interpreter_1/profiles.py @@ -51,6 +51,7 @@ def __init__(self): self.messages = [] # List of conversation messages self.system_message = None # System message override self.instructions = "" # Additional model instructions + self.input = None # Pre-filled first user message # Available tools and settings self.tools = ["interpreter", "editor"] # Enabled tool modules