Skip to content

Commit

Permalink
Improved CLI, pass through params to LiteLLM
Browse files Browse the repository at this point in the history
  • Loading branch information
KillianLucas committed Nov 18, 2024
1 parent a9e4178 commit ca90a22
Show file tree
Hide file tree
Showing 6 changed files with 46 additions and 11 deletions.
6 changes: 5 additions & 1 deletion interpreter_1/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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"
)
Expand Down
17 changes: 16 additions & 1 deletion interpreter_1/interpreter.py
Original file line number Diff line number Diff line change
Expand Up @@ -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."
Expand All @@ -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:
Expand All @@ -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:
Expand Down
25 changes: 20 additions & 5 deletions interpreter_1/misc/get_input.py
Original file line number Diff line number Diff line change
Expand Up @@ -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?",
Expand All @@ -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()
Expand Down Expand Up @@ -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:
Expand All @@ -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
Expand Down
6 changes: 3 additions & 3 deletions interpreter_1/misc/help.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion interpreter_1/misc/welcome.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
"""
)
1 change: 1 addition & 0 deletions interpreter_1/profiles.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit ca90a22

Please sign in to comment.