Skip to content

Commit

Permalink
cancel core changes
Browse files Browse the repository at this point in the history
watch interpreter messages state, we can check the message is loaded or not
  • Loading branch information
funwarioisii committed Mar 21, 2024
1 parent 57aeea6 commit cac6528
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 11 deletions.
10 changes: 5 additions & 5 deletions interpreter/core/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ def wait(self):
# Return new messages
return self.messages[self.last_messages_count :]

def chat(self, message=None, display=True, stream=False, blocking=True, loaded_message=None):
def chat(self, message=None, display=True, stream=False, blocking=True):
try:
self.responding = True
if self.anonymous_telemetry and not self.offline:
Expand All @@ -161,10 +161,10 @@ def chat(self, message=None, display=True, stream=False, blocking=True, loaded_m
return

if stream:
return self._streaming_chat(message=message, display=display, loaded_message=loaded_message)
return self._streaming_chat(message=message, display=display)

# If stream=False, *pull* from the stream.
for _ in self._streaming_chat(message=message, display=display, loaded_message=loaded_message):
for _ in self._streaming_chat(message=message, display=display):
pass

# Return new messages
Expand All @@ -187,13 +187,13 @@ def chat(self, message=None, display=True, stream=False, blocking=True, loaded_m

raise

def _streaming_chat(self, message=None, display=True, loaded_message=None):
def _streaming_chat(self, message=None, display=True):
# Sometimes a little more code -> a much better experience!
# Display mode actually runs interpreter.chat(display=False, stream=True) from within the terminal_interface.
# wraps the vanilla .chat(display=False) generator in a display.
# Quite different from the plain generator stuff. So redirect to that
if display:
yield from terminal_interface(self, message, loaded_message)
yield from terminal_interface(self, message)
return

# One-off message
Expand Down
3 changes: 1 addition & 2 deletions interpreter/terminal_interface/start_terminal_interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -400,8 +400,7 @@ def start_terminal_interface(interpreter):
validate_llm_settings(interpreter)

interpreter.in_terminal_interface = True

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


def set_attributes(args, arguments):
Expand Down
10 changes: 6 additions & 4 deletions interpreter/terminal_interface/terminal_interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,13 @@
# 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,
loaded_message: str = None,
):
# Auto run and offline (this.. this isnt right) don't display messages.
# Probably worth abstracting this to something like "debug_cli" at some point.
Expand All @@ -72,6 +74,8 @@ def terminal_interface(
interactive = False
else:
interactive = True
if has_loaded_message(interpreter, message):
interactive = True

active_block = None
voice_subprocess = None
Expand All @@ -80,9 +84,7 @@ def terminal_interface(
try:
if interactive:
### This is the primary input for Open Interpreter.
if loaded_message and len(interpreter.messages) == 0: # When the first chat, interpreter has no messages
message = loaded_message
else:
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:
Expand Down

0 comments on commit cac6528

Please sign in to comment.