Skip to content

Commit a5290cd

Browse files
committed
Whitespace error fix and better piping
1 parent 194772a commit a5290cd

File tree

5 files changed

+56
-56
lines changed

5 files changed

+56
-56
lines changed

Diff for: interpreter_1/cli.py

+20-21
Original file line numberDiff line numberDiff line change
@@ -89,11 +89,6 @@ def _profile_to_arg_params(profile: Profile) -> Dict[str, Dict[str, Any]]:
8989
"default": profile.instructions,
9090
"help": "Appended to default system message",
9191
},
92-
"input": {
93-
"flags": ["--input"],
94-
"default": profile.input,
95-
"help": "Set initial input message",
96-
},
9792
"max_turns": {
9893
"flags": ["--max-turns"],
9994
"type": int,
@@ -125,6 +120,8 @@ def parse_args():
125120

126121
# Hidden arguments
127122
parser.add_argument("--help", "-h", action="store_true", help=argparse.SUPPRESS)
123+
parser.add_argument("--version", action="store_true", help=argparse.SUPPRESS)
124+
parser.add_argument("--input", action="store", help=argparse.SUPPRESS)
128125

129126
# Add arguments programmatically from config
130127
arg_params = _profile_to_arg_params(profile)
@@ -134,7 +131,7 @@ def parse_args():
134131

135132
# If second argument exists and doesn't start with '-', treat as input message
136133
if len(sys.argv) > 1 and not sys.argv[1].startswith("-"):
137-
return {**vars(parser.parse_args([])), "input_message": " ".join(sys.argv[1:])}
134+
return {**vars(parser.parse_args([])), "input": "i " + " ".join(sys.argv[1:])}
138135

139136
args = vars(parser.parse_args())
140137

@@ -146,16 +143,6 @@ def parse_args():
146143
if key in args and args[key] is None:
147144
args[key] = value
148145

149-
if args["help"]:
150-
from .misc.help import help_message
151-
152-
arguments_string = ""
153-
for action in parser._actions:
154-
if action.help != argparse.SUPPRESS:
155-
arguments_string += f"\n {action.option_strings[0]:<12} {action.help}"
156-
help_message(arguments_string)
157-
sys.exit(0)
158-
159146
return args
160147

161148

@@ -172,6 +159,20 @@ def load_interpreter():
172159
if hasattr(interpreter, key) and value is not None:
173160
setattr(interpreter, key, value)
174161

162+
if args["help"]:
163+
from .misc.help import help_message
164+
165+
help_message()
166+
sys.exit(0)
167+
168+
if args["version"]:
169+
# Print version of currently installed interpreter
170+
# Get this from the package metadata
171+
from importlib.metadata import version
172+
173+
print("Open Interpreter " + version("open-interpreter"))
174+
sys.exit(0)
175+
175176
# Check if we should start the server
176177
if args["serve"]:
177178
# Load interpreter immediately for server mode
@@ -208,21 +209,19 @@ async def async_load():
208209
spinner.start()
209210
load_interpreter()
210211
spinner.stop()
211-
if args["input"]:
212+
213+
if args["input"] is not None:
212214
message = args["input"]
213215
else:
214216
message = sys.stdin.read().strip()
215-
# print("---")
216-
# print(message)
217-
# print("---")
218217
interpreter.messages = [{"role": "user", "content": message}]
219218

220219
# Run the generator until completion
221220
for _ in interpreter.respond():
222221
pass
223222
print()
224223

225-
if sys.stdin.isatty():
224+
if interpreter.interactive:
226225
interpreter.chat() # Continue in interactive mode
227226

228227

Diff for: interpreter_1/interpreter.py

+23-26
Original file line numberDiff line numberDiff line change
@@ -345,7 +345,7 @@ async def async_respond(self):
345345
if getattr(self, "auto_run", False):
346346
user_approval = "y"
347347
else:
348-
if not sys.stdin.isatty():
348+
if not self.interactive:
349349
print(
350350
"Error: Non-interactive environment requires auto_run=True to run tools"
351351
)
@@ -805,31 +805,28 @@ def chat(self):
805805
placeholder = HTML(
806806
f"<{placeholder_color}>{placeholder_text}</{placeholder_color}>"
807807
)
808-
if self.input:
809-
user_input = self.input
810-
else:
811-
if self._prompt_session is None:
812-
self._prompt_session = PromptSession()
813-
user_input = self._prompt_session.prompt(
814-
"> ", placeholder=placeholder
815-
).strip()
816-
print()
808+
if self._prompt_session is None:
809+
self._prompt_session = PromptSession()
810+
user_input = self._prompt_session.prompt(
811+
"> ", placeholder=placeholder
812+
).strip()
813+
print()
817814

818-
# Handle multi-line input
819-
if user_input == '"""':
820-
user_input = ""
821-
print('> """')
822-
while True:
823-
placeholder = HTML(
824-
f'<{placeholder_color}>Use """ again to finish</{placeholder_color}>'
825-
)
826-
line = self._prompt_session.prompt(
827-
"", placeholder=placeholder
828-
).strip()
829-
if line == '"""':
830-
break
831-
user_input += line + "\n"
832-
print()
815+
# Handle multi-line input
816+
if user_input == '"""':
817+
user_input = ""
818+
print('> """')
819+
while True:
820+
placeholder = HTML(
821+
f'<{placeholder_color}>Use """ again to finish</{placeholder_color}>'
822+
)
823+
line = self._prompt_session.prompt(
824+
"", placeholder=placeholder
825+
).strip()
826+
if line == '"""':
827+
break
828+
user_input += line + "\n"
829+
print()
833830

834831
message_count += 1 # Increment counter after each message
835832

@@ -860,7 +857,7 @@ def chat(self):
860857
self._spinner.stop()
861858
print(traceback.format_exc())
862859
print("\n\n\033[91mAn error has occurred.\033[0m")
863-
if sys.stdin.isatty(): # Only prompt if in interactive mode
860+
if self.interactive:
864861
print(
865862
"\nOpen Interpreter is self-healing. If you report this error, it will be autonomously repaired."
866863
)

Diff for: interpreter_1/misc/help.py

+3-5
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,9 @@
11
import json
2-
import random
3-
import time
42

53
from ..ui.tool import ToolRenderer
6-
from .stream_text import stream_text
74

85

9-
def help_message(u):
6+
def help_message():
107
tips = [
118
"\033[38;5;240mTip: Pipe in prompts using `$ANYTHING | i`\033[0m",
129
"\033[38;5;240mTip: Type `wtf` in your terminal to fix the last error\033[0m",
@@ -39,10 +36,11 @@ def help_message(u):
3936
{BLUE_COLOR}--allowed-paths{RESET_COLOR} Paths the model can access
4037
{BLUE_COLOR}--no-tool-calling{RESET_COLOR} Disable tool usage (enabled by default)
4138
{BLUE_COLOR}--auto-run{RESET_COLOR}, {BLUE_COLOR}-y{RESET_COLOR} Auto-run suggested commands
39+
{BLUE_COLOR}--interactive{RESET_COLOR} Enable interactive mode (enabled if sys.stdin.isatty())
40+
{BLUE_COLOR}--no-interactive{RESET_COLOR} Disable interactive mode
4241
4342
{BLUE_COLOR}--system-message{RESET_COLOR} Override default system message
4443
{BLUE_COLOR}--instructions{RESET_COLOR} Additional instructions in system message
45-
{BLUE_COLOR}--max-budget{RESET_COLOR} Maximum spend allowed (-1 for unlimited)
4644
{BLUE_COLOR}--max-turns{RESET_COLOR} Maximum conversation turns (-1 for unlimited)
4745
4846
{BLUE_COLOR}--profile{RESET_COLOR} Load settings from config file

Diff for: interpreter_1/profiles.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import json
22
import os
33
import platform
4+
import sys
45
from datetime import datetime
56

67
# System prompt with dynamic values
@@ -63,12 +64,12 @@ def __init__(self):
6364
self.messages = [] # List of conversation messages
6465
self.system_message = SYSTEM_PROMPT # System prompt override
6566
self.instructions = "" # Additional model instructions
66-
self.input = None # Input message override
6767

6868
# Available tools and settings
6969
self.tools = ["interpreter", "editor"] # Enabled tool modules
7070
self.auto_run = False # Whether to auto-run tools without confirmation
7171
self.tool_calling = True # Whether to allow tool/function calling
72+
self.interactive = sys.stdin.isatty() # Whether to prompt for input
7273

7374
# Server settings
7475
self.serve = False # Whether to start the server

Diff for: interpreter_1/tools/bash.py

+8-3
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,9 @@ async def watch_for_ctrl_c():
140140
if self._sentinel in full_output:
141141
# Remove sentinel and everything after it
142142
clean_output = full_output.split(self._sentinel)[0]
143-
# print(clean_output, end="", flush=True)
143+
# If output is empty or only whitespace, return a message
144+
if not clean_output.strip():
145+
return CLIResult(output="<No output>")
144146
return CLIResult(output=clean_output)
145147
else:
146148
print(chunk_str, end="", flush=True)
@@ -153,8 +155,11 @@ async def watch_for_ctrl_c():
153155
else:
154156
output, error = await self._process.communicate()
155157
output_str = output.decode()
156-
print(output_str, end="", flush=True)
157-
return CLIResult(output=output_str + "\n" + error.decode())
158+
error_str = error.decode()
159+
combined_output = output_str + "\n" + error_str
160+
if not combined_output.strip():
161+
return CLIResult(output="<No output>")
162+
return CLIResult(output=combined_output)
158163

159164
except (KeyboardInterrupt, asyncio.CancelledError):
160165
self.stop()

0 commit comments

Comments
 (0)