Skip to content

Commit 0506db5

Browse files
committed
Async spinner, help text
1 parent 4d7b2ee commit 0506db5

File tree

3 files changed

+87
-41
lines changed

3 files changed

+87
-41
lines changed

interpreter_1/misc/help.py

Lines changed: 38 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
from .stream_text import stream_text
77

88

9-
def help_message(arguments_string):
9+
def help_message(u):
1010
tips = [
1111
"\033[38;5;240mTip: Pipe in prompts using `$ANYTHING | i`\033[0m",
1212
"\033[38;5;240mTip: Type `wtf` in your terminal to fix the last error\033[0m",
@@ -18,39 +18,58 @@ def help_message(arguments_string):
1818
content = f"""
1919
A standard interface for computer-controlling agents.
2020
21-
Run {BLUE_COLOR}interpreter{RESET_COLOR} or {BLUE_COLOR}i [prompt]{RESET_COLOR} to begin.
2221
23-
{BLUE_COLOR}--model{RESET_COLOR} Specify language model or OpenAI-compatible URL
24-
{BLUE_COLOR}--serve{RESET_COLOR} Start an OpenAI-compatible server at {BLUE_COLOR}/{RESET_COLOR}
22+
\033[1mUSAGE\033[0m
2523
26-
{BLUE_COLOR}-y{RESET_COLOR} Automatically approve tools
27-
{BLUE_COLOR}-d{RESET_COLOR} Run in debug mode
24+
{BLUE_COLOR}interpreter{RESET_COLOR} [flags] \033[38;5;240m(e.g. interpreter --model gpt-4o)\033[0m
25+
{BLUE_COLOR}i{RESET_COLOR} [prompt] \033[38;5;240m(e.g. i want deno)\033[0m
2826
29-
Examples:
3027
31-
{BLUE_COLOR}i need help with my code{RESET_COLOR}
32-
{BLUE_COLOR}i --model gpt-4o-mini --serve{RESET_COLOR}
33-
{BLUE_COLOR}i --model https://localhost:1234/v1{RESET_COLOR}
28+
\033[1mFLAGS\033[0m
3429
35-
{arguments_string}
30+
{BLUE_COLOR}--model{RESET_COLOR} Model to use for completion
31+
{BLUE_COLOR}--provider{RESET_COLOR} API provider (e.g. OpenAI, Anthropic)
32+
{BLUE_COLOR}--api-base{RESET_COLOR} Base URL for API requests
33+
{BLUE_COLOR}--api-key{RESET_COLOR} API key for authentication
34+
{BLUE_COLOR}--api-version{RESET_COLOR} API version to use
35+
{BLUE_COLOR}--temperature{RESET_COLOR} Sampling temperature (default: 0)
3636
37-
{random.choice(tips)}
38-
""".strip()
37+
{BLUE_COLOR}--tools{RESET_COLOR} Comma-separated tools: interpreter,editor,gui
38+
{BLUE_COLOR}--allowed-commands{RESET_COLOR} Commands the model can execute
39+
{BLUE_COLOR}--allowed-paths{RESET_COLOR} Paths the model can access
40+
{BLUE_COLOR}--no-tool-calling{RESET_COLOR} Disable tool usage (enabled by default)
41+
{BLUE_COLOR}--auto-run{RESET_COLOR}, {BLUE_COLOR}-y{RESET_COLOR} Auto-run suggested commands
42+
43+
{BLUE_COLOR}--system-message{RESET_COLOR} Override default system message
44+
{BLUE_COLOR}--instructions{RESET_COLOR} Additional instructions to append
45+
{BLUE_COLOR}--max-budget{RESET_COLOR} Maximum spend allowed (-1 for unlimited)
46+
{BLUE_COLOR}--max-turns{RESET_COLOR} Maximum conversation turns (-1 for unlimited)
47+
48+
{BLUE_COLOR}--profile{RESET_COLOR} Load settings from config file
49+
{BLUE_COLOR}--serve{RESET_COLOR} Start OpenAI-compatible server
50+
51+
52+
"""
53+
54+
# Add an indent to each line
55+
# content = "\n".join(f" {line}" for line in content.split("\n"))
3956

4057
string = json.dumps(
4158
{"command": "Open Interpreter", "path": "", "file_text": content}
4259
)
4360

4461
renderer = ToolRenderer(name="str_replace_editor")
4562

46-
for chunk in stream_text(string):
47-
renderer.feed(chunk)
63+
# for chunk in stream_text(string, min_delay=0.00001, max_delay=0.0001, max_chunk=50):
64+
# renderer.feed(chunk)
65+
66+
renderer.feed(string)
4867

4968
renderer.close()
5069

51-
time.sleep(0.03)
70+
# time.sleep(0.03)
5271
print("")
53-
time.sleep(0.04)
72+
# time.sleep(0.04)
5473
# print("\033[38;5;238mA.C., 2024. https://openinterpreter.com/\033[0m\n")
55-
print("\033[38;5;238mhttps://openinterpreter.com/\033[0m\n")
56-
time.sleep(0.05)
74+
print("\033[38;5;238mhttps://docs.openinterpreter.com/\033[0m\n")
75+
# time.sleep(0.05)

interpreter_1/misc/spinner.py

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import asyncio
12
import sys
23
import threading
34
import time
@@ -12,21 +13,27 @@ def __init__(self, text=""):
1213
self.keep_running = False
1314
self.spinner_thread = None
1415

15-
def _spin(self):
16+
async def _spin(self):
1617
while self.keep_running:
1718
for frame in self.spinner_cycle:
1819
if not self.keep_running:
1920
break
2021
# Clear the line and write the new frame
2122
sys.stdout.write("\r" + self.text + frame)
2223
sys.stdout.flush()
23-
time.sleep(0.2) # Control animation speed
24+
try:
25+
await asyncio.sleep(0.2) # Async sleep for better cancellation
26+
except asyncio.CancelledError:
27+
break
2428

2529
def start(self):
2630
"""Start the spinner animation in a separate thread."""
2731
if not self.spinner_thread:
2832
self.keep_running = True
29-
self.spinner_thread = threading.Thread(target=self._spin)
33+
loop = asyncio.new_event_loop()
34+
self.spinner_thread = threading.Thread(
35+
target=lambda: loop.run_until_complete(self._spin())
36+
)
3037
self.spinner_thread.daemon = True
3138
self.spinner_thread.start()
3239

interpreter_1/ui/tool.py

Lines changed: 39 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -28,18 +28,31 @@ def flush(self):
2828
class CodeRenderer(ContentRenderer):
2929
def __init__(self, style):
3030
super().__init__(style)
31-
SchemaRenderer.print_separator("┼")
3231
self.line_number = 1
3332
self.code_lang = None
3433
self.buffer = ""
3534
self.rendered_content = ""
3635
self.spinner = SimpleSpinner("")
3736
self.is_spinning = False
3837
self.terminal_width = os.get_terminal_size().columns
39-
self.prefix_width = 6 # "123 │ " = 6 characters
4038
self.safety_padding = 4 # Extra padding to prevent edge cases
4139
self.json_obj = None
4240

41+
# Set prefix width based on INTERPRETER_LINE_NUMBERS
42+
self.show_line_numbers = (
43+
os.environ.get("INTERPRETER_LINE_NUMBERS", "true").lower() == "true"
44+
)
45+
self.prefix_width = (
46+
6 if self.show_line_numbers else 0
47+
) # "123 │ " = 6 characters
48+
49+
# Print appropriate separator
50+
if self.show_line_numbers:
51+
SchemaRenderer.print_separator("┼")
52+
else:
53+
SchemaRenderer.print_separator("┴")
54+
print()
55+
4356
def feed(self, json_obj):
4457
self.json_obj = json_obj
4558

@@ -141,25 +154,28 @@ def _render_line(self, line):
141154
else:
142155
chunks = [line]
143156

144-
# Highlight and print first chunk with line number
145-
line_prefix = f"{SchemaRenderer.GRAY_COLOR}{str(self.line_number).rjust(3)}{SchemaRenderer.RESET_COLOR}"
146-
# if self.json_obj and self.json_obj.get("command") == "Open Interpreter":
147-
# line_prefix = f"{SchemaRenderer.GRAY_COLOR} │ {SchemaRenderer.RESET_COLOR}"
148-
highlighted = highlight(chunks[0] + "\n", lexer, formatter).rstrip()
157+
if self.show_line_numbers:
158+
# Highlight and print first chunk with line number
159+
line_prefix = f"{SchemaRenderer.GRAY_COLOR}{str(self.line_number).rjust(3)}{SchemaRenderer.RESET_COLOR}"
160+
highlighted = highlight(chunks[0] + "\n", lexer, formatter).rstrip()
149161

150-
if self.line_number == 0 and highlighted.strip() == "":
151-
return
162+
if self.line_number == 0 and highlighted.strip() == "":
163+
return
152164

153-
sys.stdout.write(f"{line_prefix}{highlighted}\n")
154-
# sys.stdout.write(f"{line_prefix}" + " ".join(highlighted) + "\n") # For debugging
165+
sys.stdout.write(f"{line_prefix}{highlighted}\n")
155166

156-
# Print remaining chunks with padding and pipe
157-
continuation_prefix = (
158-
f"{SchemaRenderer.GRAY_COLOR}{SchemaRenderer.RESET_COLOR}"
159-
)
160-
for chunk in chunks[1:]:
161-
highlighted = highlight(chunk + "\n", lexer, formatter).rstrip()
162-
sys.stdout.write(f"{continuation_prefix}{highlighted}\n")
167+
# Print remaining chunks with padding and pipe
168+
continuation_prefix = (
169+
f"{SchemaRenderer.GRAY_COLOR}{SchemaRenderer.RESET_COLOR}"
170+
)
171+
for chunk in chunks[1:]:
172+
highlighted = highlight(chunk + "\n", lexer, formatter).rstrip()
173+
sys.stdout.write(f"{continuation_prefix}{highlighted}\n")
174+
else:
175+
# Print chunks without line numbers
176+
for chunk in chunks:
177+
highlighted = highlight(chunk + "\n", lexer, formatter).rstrip()
178+
sys.stdout.write(f"{highlighted}\n")
163179

164180
sys.stdout.flush()
165181
self.line_number += 1
@@ -174,7 +190,11 @@ def flush(self):
174190

175191
def close(self):
176192
self.flush()
177-
SchemaRenderer.print_separator("┴", newline=False)
193+
if self.show_line_numbers:
194+
SchemaRenderer.print_separator("┴", newline=False)
195+
else:
196+
print()
197+
SchemaRenderer.print_separator("─", newline=False)
178198

179199

180200
class PathRenderer(ContentRenderer):

0 commit comments

Comments
 (0)