Skip to content

Commit 9124d2c

Browse files
authored
Disable active line highlighting, export to md, allow running from executable
Disable active line highlighting, export to `md`, allow running from executable
2 parents 75596be + e19b890 commit 9124d2c

File tree

11 files changed

+100
-21
lines changed

11 files changed

+100
-21
lines changed

docs/ROADMAP.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
- [ ] Figure out how to get OI to answer to user input requests like python's `input()`. Do we somehow detect a delay in the output..? Is there some universal flag that TUIs emit when they expect user input? Should we do this semantically with embeddings, then ask OI to review it and respond..?
1010
- [ ] Placeholder text that gives a compelling example OI request. Probably use `textual`
1111
- [ ] Everything else `textual` offers, like could we make it easier to select text? Copy paste in and out? Code editing interface?
12-
- [ ] Let people turn off the active line highlighting
12+
- [x] Let people turn off the active line highlighting
1313
- [ ] Add a --plain flag which doesn't use rich, just prints stuff in plain text
1414
- [ ] Use iPython stuff to track the active line, instead of inserting print statements, which makes debugging weird (From ChatGPT: For deeper insights into what's happening behind the scenes, including which line of code is being executed, you can increase the logging level of the IPython kernel. You can configure the kernel's logger to a more verbose setting, which logs each execution request. However, this requires modifying the kernel's startup settings, which might involve changing logging configurations in the IPython kernel source or when launching the kernel.)
1515
- [ ] Let people edit the code OI writes. Could just open it in the user's preferred editor. Simple. [Full description of how to implement this here.](https://github.com/KillianLucas/open-interpreter/pull/830#issuecomment-1854989795)

docs/guides/advanced-terminal-usage.mdx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,4 +13,5 @@ Magic commands can be used to control the interpreter's behavior in interactive
1313
- `%tokens [prompt]`: EXPERIMENTAL: Calculate the tokens used by the next request based on the current conversation's messages and estimate the cost of that request; optionally provide a prompt to also calculate the tokens used by that prompt and the total amount of tokens that will be sent with the next request.
1414
- `%info`: Show system and interpreter information.
1515
- `%help`: Show this help message.
16-
- `%jupyter`: Export the current session to a Jupyter notebook file (.ipynb) to the Downloads folder.
16+
- `%jupyter`: Export the current session to a Jupyter notebook file (.ipynb) to the Downloads folder.
17+
- `%markdown [path]`: Export the conversation to a specified Markdown path. If no path is provided, it will be saved to the Downloads folder with a generated conversation name.

docs/usage/terminal/magic-commands.mdx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,3 +13,4 @@ Magic commands can be used to control the interpreter's behavior in interactive
1313
- `%tokens [prompt]`: EXPERIMENTAL: Calculate the tokens used by the next request based on the current conversation's messages and estimate the cost of that request; optionally provide a prompt to also calculate the tokens used by that prompt and the total amount of tokens that will be sent with the next request.
1414
- `%info`: Show system and interpreter information.
1515
- `%help`: Show this help message.
16+
- `%markdown [path]`: Export the conversation to a specified Markdown path. If no path is provided, it will be saved to the Downloads folder with a generated conversation name.

interpreter/core/computer/terminal/languages/jupyter_language.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55

66
import ast
77
import logging
8+
import sys
89
import os
910
import queue
1011
import re
@@ -18,6 +19,17 @@
1819

1920
DEBUG_MODE = False
2021

22+
# When running from an executable, ipykernel calls itself infinitely
23+
# This is a workaround to detect it and launch it manually
24+
if 'ipykernel_launcher' in sys.argv:
25+
if sys.path[0] == '':
26+
del sys.path[0]
27+
28+
from ipykernel import kernelapp as app
29+
30+
app.launch_new_instance()
31+
sys.exit(0)
32+
2133

2234
class JupyterLanguage(BaseLanguage):
2335
file_extension = "py"

interpreter/core/core.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,7 @@ def __init__(
9999
self.multi_line = multi_line
100100
self.contribute_conversation = contribute_conversation
101101
self.plain_text_display = plain_text_display
102+
self.highlight_active_line = True # additional setting to toggle active line highlighting. Defaults to True
102103

103104
# Loop messages
104105
self.loop = loop

interpreter/core/llm/run_tool_calling_llm.py

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -104,14 +104,6 @@ def run_tool_calling_llm(llm, request_params):
104104
]
105105
request_params["tools"] = [tool_schema]
106106

107-
import pprint
108-
109-
pprint.pprint(
110-
[str(m)[:600] if len(str(m)) > 1000 else m for m in request_params["messages"]]
111-
)
112-
113-
print("PROCESSING")
114-
115107
request_params["messages"] = process_messages(request_params["messages"])
116108

117109
# # This makes any role: tool have the ID of the last tool call
@@ -165,12 +157,6 @@ def run_tool_calling_llm(llm, request_params):
165157
# del messages[i]
166158
# request_params["messages"] = messages
167159

168-
import pprint
169-
170-
pprint.pprint(
171-
[str(m)[:600] if len(str(m)) > 1000 else m for m in request_params["messages"]]
172-
)
173-
174160
# Add OpenAI's recommended function message
175161
# request_params["messages"][0][
176162
# "content"

interpreter/terminal_interface/components/code_block.py

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,13 @@ class CodeBlock(BaseBlock):
1212
Code Blocks display code and outputs in different languages. You can also set the active_line!
1313
"""
1414

15-
def __init__(self):
15+
def __init__(self, interpreter=None):
1616
super().__init__()
1717

1818
self.type = "code"
19+
self.highlight_active_line = (
20+
interpreter.highlight_active_line if interpreter else None
21+
)
1922

2023
# Define these for IDE auto-completion
2124
self.language = ""
@@ -42,14 +45,22 @@ def refresh(self, cursor=True):
4245
)
4346
code_table.add_column()
4447

45-
# Add cursor
46-
if cursor:
48+
# Add cursor only if active line highliting is true
49+
if cursor and (
50+
self.highlight_active_line
51+
if self.highlight_active_line is not None
52+
else True
53+
):
4754
code += "●"
4855

4956
# Add each line of code to the table
5057
code_lines = code.strip().split("\n")
5158
for i, line in enumerate(code_lines, start=1):
52-
if i == self.active_line:
59+
if i == self.active_line and (
60+
self.highlight_active_line
61+
if self.highlight_active_line is not None
62+
else True
63+
):
5364
# This is the active line, print it with a white background
5465
syntax = Syntax(
5566
line, self.language, theme="bw", line_numbers=False, word_wrap=True

interpreter/terminal_interface/magic_commands.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
from ..core.utils.system_debug_info import system_info
99
from .utils.count_tokens import count_messages_tokens
1010
from .utils.display_markdown_message import display_markdown_message
11+
from .utils.export_to_markdown import export_to_markdown
1112

1213

1314
def handle_undo(self, arguments):
@@ -58,6 +59,7 @@ def handle_help(self, arguments):
5859
"%help": "Show this help message.",
5960
"%info": "Show system and interpreter information",
6061
"%jupyter": "Export the conversation to a Jupyter notebook file",
62+
"%markdown [path]": "Export the conversation to a specified Markdown path. If no path is provided, it will be saved to the Downloads folder with a generated conversation name.",
6163
}
6264

6365
base_message = ["> **Available Commands:**\n\n"]
@@ -220,6 +222,9 @@ def get_downloads_path():
220222
else:
221223
# For MacOS and Linux
222224
downloads = os.path.join(os.path.expanduser("~"), "Downloads")
225+
# For some GNU/Linux distros, there's no '~/Downloads' dir by default
226+
if not os.path.exists(downloads):
227+
os.makedirs(downloads)
223228
return downloads
224229

225230

@@ -295,6 +300,19 @@ def jupyter(self, arguments):
295300
)
296301

297302

303+
def markdown(self, export_path: str):
304+
# If it's an empty conversations
305+
if len(self.messages) == 0:
306+
print("No messages to export.")
307+
return
308+
309+
# If user doesn't specify the export path, then save the exported PDF in '~/Downloads'
310+
if not export_path:
311+
export_path = get_downloads_path() + f"/{self.conversation_filename[:-4]}md"
312+
313+
export_to_markdown(self.messages, export_path)
314+
315+
298316
def handle_magic_command(self, user_input):
299317
# Handle shell
300318
if user_input.startswith("%%"):
@@ -316,6 +334,7 @@ def handle_magic_command(self, user_input):
316334
"tokens": handle_count_tokens,
317335
"info": handle_info,
318336
"jupyter": jupyter,
337+
"markdown": markdown,
319338
}
320339

321340
user_input = user_input[1:].strip() # Capture the part after the `%`

interpreter/terminal_interface/start_terminal_interface.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,14 @@ def start_terminal_interface(interpreter):
5050
"type": bool,
5151
"attribute": {"object": interpreter, "attr_name": "auto_run"},
5252
},
53+
{
54+
"name": "no_highlight_active_line",
55+
"nickname": "nhl",
56+
"help_text": "turn off active line highlighting in code blocks",
57+
"type": bool,
58+
"action": "store_true",
59+
"default": False, # Default to False, meaning highlighting is on by default
60+
},
5361
{
5462
"name": "verbose",
5563
"nickname": "v",
@@ -381,6 +389,9 @@ def print_help(self, *args, **kwargs):
381389
print(f"Open Interpreter {version} {update_name}")
382390
return
383391

392+
if args.no_highlight_active_line:
393+
interpreter.highlight_active_line = False
394+
384395
# if safe_mode and auto_run are enabled, safe_mode disables auto_run
385396
if interpreter.auto_run and (
386397
interpreter.safe_mode == "ask" or interpreter.safe_mode == "auto"

interpreter/terminal_interface/terminal_interface.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -221,7 +221,7 @@ def terminal_interface(interpreter, message):
221221
if response.strip().lower() == "y":
222222
# Create a new, identical block where the code will actually be run
223223
# Conveniently, the chunk includes everything we need to do this:
224-
active_block = CodeBlock()
224+
active_block = CodeBlock(interpreter)
225225
active_block.margin_top = False # <- Aesthetic choice
226226
active_block.language = language
227227
active_block.code = code

0 commit comments

Comments
 (0)