Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enhance integration capabilities by enabling passing of initial prompt to LLM from command line #1097

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions docs/settings/all-settings.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -561,6 +561,18 @@ system_message: "You are Open Interpreter..."

</CodeGroup>

### Load Message

You can pass the first prompt at startup via a text file. This is achieved by using the `--load_message` flag.

<CodeGroup>

```bash Terminal
interpreter --load_message prompt.txt
```

</CodeGroup>

### Disable Telemetry

Opt out of [telemetry](telemetry/telemetry).
Expand Down
14 changes: 12 additions & 2 deletions interpreter/terminal_interface/start_terminal_interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,12 @@ def start_terminal_interface(interpreter):
"help_text": "get Open Interpreter's version number",
"type": bool,
},
{
"name": "load_message",
"help_text": "load a first prompt from a file",
"type": str,
"default": None,
},
]

# Check for deprecated flags before parsing arguments
Expand Down Expand Up @@ -408,11 +414,15 @@ def start_terminal_interface(interpreter):
interpreter.server()
return

loaded_message = None
if args.load_message:
with open(args.load_message, "r") as f:
loaded_message = f.read()

validate_llm_settings(interpreter)

interpreter.in_terminal_interface = True

interpreter.chat()
interpreter.chat(message=loaded_message)


def set_attributes(args, arguments):
Expand Down
13 changes: 11 additions & 2 deletions interpreter/terminal_interface/terminal_interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,14 @@
# If they don't have readline, that's fine
pass

def has_loaded_message(interpreter, message):
return bool(message) and len(interpreter.messages) == 0

def terminal_interface(interpreter, message):

def terminal_interface(
interpreter,
message,
):
# Auto run and offline (this.. this isnt right) don't display messages.
# Probably worth abstracting this to something like "debug_cli" at some point.
if not interpreter.auto_run and not interpreter.offline:
Expand All @@ -68,6 +74,8 @@ def terminal_interface(interpreter, message):
interactive = False
else:
interactive = True
if has_loaded_message(interpreter, message):
interactive = True

active_block = None
voice_subprocess = None
Expand All @@ -76,7 +84,8 @@ def terminal_interface(interpreter, message):
try:
if interactive:
### This is the primary input for Open Interpreter.
message = cli_input("> ").strip() if interpreter.multi_line else input("> ").strip()
if not has_loaded_message(interpreter, message): # When the first chat, interpreter has no messages
message = cli_input("> ").strip() if interpreter.multi_line else input("> ").strip()

try:
# This lets users hit the up arrow key for past messages
Expand Down