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

pre-commit autoupdate && pre-commit run --all-files #1544

Open
wants to merge 1 commit 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
4 changes: 2 additions & 2 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
repos:
# Using this mirror lets us use mypyc-compiled black, which is 2x faster
- repo: https://github.com/psf/black-pre-commit-mirror
rev: 23.10.1
rev: 24.10.0
hooks:
- id: black
# It is recommended to specify the latest version of Python
Expand All @@ -10,6 +10,6 @@ repos:
# https://pre-commit.com/#top_level-default_language_version
language_version: python3.11
- repo: https://github.com/PyCQA/isort
rev: 5.12.0
rev: 5.13.2
hooks:
- id: isort
4 changes: 3 additions & 1 deletion interpreter/computer_use/tools/computer.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,9 @@ class ComputerTool(BaseAnthropicTool):
api_type: Literal["computer_20241022"] = "computer_20241022"
width: int
height: int
display_num: None # Simplified to always be None since we're only using primary display
display_num: (
None # Simplified to always be None since we're only using primary display
)

_screenshot_delay = 2.0
_scaling_enabled = True
Expand Down
4 changes: 3 additions & 1 deletion interpreter/computer_use/tools/run.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@

import asyncio

TRUNCATED_MESSAGE: str = "<response clipped><NOTE>To save on context only part of this file has been shown to you. You should retry this tool after you have searched inside the file with `grep -n` in order to find the line numbers of what you are looking for.</NOTE>"
TRUNCATED_MESSAGE: str = (
"<response clipped><NOTE>To save on context only part of this file has been shown to you. You should retry this tool after you have searched inside the file with `grep -n` in order to find the line numbers of what you are looking for.</NOTE>"
)
MAX_RESPONSE_LEN: int = 16000


Expand Down
2 changes: 1 addition & 1 deletion interpreter/core/computer/calendar/calendar.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

from ..utils.run_applescript import run_applescript, run_applescript_capture


makeDateFunction = """
on makeDate(yr, mon, day, hour, min, sec)
set theDate to current date
Expand All @@ -20,6 +19,7 @@
end makeDate
"""


class Calendar:
def __init__(self, computer):
self.computer = computer
Expand Down
4 changes: 3 additions & 1 deletion interpreter/core/computer/clipboard/clipboard.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
import platform

from ...utils.lazy_import import lazy_import

# Lazy import of optional packages
pyperclip = lazy_import('pyperclip')
pyperclip = lazy_import("pyperclip")


class Clipboard:
def __init__(self, computer):
Expand Down
8 changes: 5 additions & 3 deletions interpreter/core/computer/computer.py
Original file line number Diff line number Diff line change
Expand Up @@ -164,9 +164,11 @@ def _extract_tool_info(self, tool):
method_signature = inspect.signature(method)
# Construct the signature string without *args and **kwargs
param_str = ", ".join(
f"{param.name}"
if param.default == param.empty
else f"{param.name}={param.default!r}"
(
f"{param.name}"
if param.default == param.empty
else f"{param.name}={param.default!r}"
)
for param in method_signature.parameters.values()
if param.kind not in (param.VAR_POSITIONAL, param.VAR_KEYWORD)
)
Expand Down
3 changes: 2 additions & 1 deletion interpreter/core/computer/docs/docs.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@
from ...utils.lazy_import import lazy_import

# Lazy import of aifs, imported when needed to speed up start time
aifs = lazy_import('aifs')
aifs = lazy_import("aifs")


class Docs:
def __init__(self, computer):
Expand Down
3 changes: 2 additions & 1 deletion interpreter/core/computer/files/files.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
from ...utils.lazy_import import lazy_import

# Lazy import of aifs, imported when needed
aifs = lazy_import('aifs')
aifs = lazy_import("aifs")


class Files:
def __init__(self, computer):
Expand Down
17 changes: 10 additions & 7 deletions interpreter/core/computer/terminal/languages/java.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,10 @@
import threading
import time
import traceback

from .subprocess_language import SubprocessLanguage


class Java(SubprocessLanguage):
file_extension = "java"
name = "Java"
Expand All @@ -33,28 +35,28 @@ def detect_end_of_execution(self, line):
def run(self, code):
try:
# Extract the class name from the code
match = re.search(r'class\s+(\w+)', code)
match = re.search(r"class\s+(\w+)", code)
if not match:
yield {
"type": "console",
"format": "output",
"content": "Error: No class definition found in the provided code."
"content": "Error: No class definition found in the provided code.",
}
return

class_name = match.group(1)
file_name = f"{class_name}.java"

# Write the Java code to a file, preserving newlines
with open(file_name, "w", newline='\n') as file:
with open(file_name, "w", newline="\n") as file:
file.write(code)

# Compile the Java code
compile_process = subprocess.Popen(
["javac", file_name],
stdout=subprocess.PIPE,
stderr=subprocess.PIPE,
text=True
text=True,
)

stdout, stderr = compile_process.communicate()
Expand All @@ -63,7 +65,7 @@ def run(self, code):
yield {
"type": "console",
"format": "output",
"content": f"Compilation Error:\n{stderr}"
"content": f"Compilation Error:\n{stderr}",
}
return

Expand All @@ -72,7 +74,7 @@ def run(self, code):
["java", class_name],
stdout=subprocess.PIPE,
stderr=subprocess.PIPE,
text=True
text=True,
)

stdout_thread = threading.Thread(
Expand Down Expand Up @@ -115,7 +117,7 @@ def run(self, code):
yield {
"type": "console",
"format": "output",
"content": f"{traceback.format_exc()}"
"content": f"{traceback.format_exc()}",
}
finally:
# Clean up the generated Java files
Expand All @@ -125,6 +127,7 @@ def run(self, code):
if os.path.exists(class_file):
os.remove(class_file)


def preprocess_java(code):
"""
Add active line markers
Expand Down
11 changes: 6 additions & 5 deletions interpreter/core/computer/terminal/languages/ruby.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import re
from pathlib import Path

from .subprocess_language import SubprocessLanguage


Expand All @@ -9,12 +10,12 @@ class Ruby(SubprocessLanguage):

def __init__(self):
super().__init__()
self.start_cmd = ["irb"]
self.start_cmd = ["irb"]

def preprocess_code(self, code):
"""
Add active line markers
Wrap in a tryCatch for better error handling
Wrap in a tryCatch for better error handling
Add end of execution marker
"""

Expand All @@ -39,7 +40,7 @@ def preprocess_code(self, code):
end
"""
self.code_line_count = len(processed_code.split("\n"))
#print(processed_code)
# print(processed_code)
return processed_code

def line_postprocessor(self, line):
Expand All @@ -48,7 +49,7 @@ def line_postprocessor(self, line):
self.code_line_count -= 1
return None
if "nil" in line:
return None
return None
return line

def detect_active_line(self, line):
Expand All @@ -57,4 +58,4 @@ def detect_active_line(self, line):
return None

def detect_end_of_execution(self, line):
return "##end_of_execution##" in line or "##execution_error##" in line
return "##end_of_execution##" in line or "##execution_error##" in line
26 changes: 19 additions & 7 deletions interpreter/core/computer/terminal/terminal.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import getpass
import json
import os
import time
import subprocess
import getpass
import time

from ..utils.recipient_utils import parse_for_recipient
from .languages.applescript import AppleScript
Expand Down Expand Up @@ -50,7 +50,7 @@ def __init__(self, computer):
def sudo_install(self, package):
try:
# First, try to install without sudo
subprocess.run(['apt', 'install', '-y', package], check=True)
subprocess.run(["apt", "install", "-y", package], check=True)
except subprocess.CalledProcessError:
# If it fails, try with sudo
print(f"Installation of {package} requires sudo privileges.")
Expand All @@ -59,9 +59,9 @@ def sudo_install(self, package):
try:
# Use sudo with password
subprocess.run(
['sudo', '-S', 'apt', 'install', '-y', package],
["sudo", "-S", "apt", "install", "-y", package],
input=sudo_password.encode(),
check=True
check=True,
)
print(f"Successfully installed {package}")
except subprocess.CalledProcessError as e:
Expand All @@ -84,9 +84,21 @@ def run(self, language, code, stream=False, display=False):
if language == "shell" and code.strip().startswith("apt install"):
package = code.split()[-1]
if self.sudo_install(package):
return [{"type": "console", "format": "output", "content": f"Package {package} installed successfully."}]
return [
{
"type": "console",
"format": "output",
"content": f"Package {package} installed successfully.",
}
]
else:
return [{"type": "console", "format": "output", "content": f"Failed to install package {package}."}]
return [
{
"type": "console",
"format": "output",
"content": f"Failed to install package {package}.",
}
]

if language == "python":
if (
Expand Down
7 changes: 4 additions & 3 deletions interpreter/core/computer/vision/vision.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,10 @@ def __init__(self, computer):
def load(self, load_moondream=True, load_easyocr=True):
# print("Loading vision models (Moondream, EasyOCR)...\n")

with contextlib.redirect_stdout(
open(os.devnull, "w")
), contextlib.redirect_stderr(open(os.devnull, "w")):
with (
contextlib.redirect_stdout(open(os.devnull, "w")),
contextlib.redirect_stderr(open(os.devnull, "w")),
):
if self.easyocr == None and load_easyocr:
import easyocr

Expand Down
1 change: 1 addition & 0 deletions interpreter/core/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
This file defines the Interpreter class.
It's the main file. `from interpreter import interpreter` will import an instance of this class.
"""

import json
import os
import threading
Expand Down
4 changes: 1 addition & 3 deletions interpreter/core/llm/run_text_llm.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,7 @@ def run_text_llm(llm, params):
if llm.execution_instructions:
try:
# Add the system message
params["messages"][0][
"content"
] += "\n" + llm.execution_instructions
params["messages"][0]["content"] += "\n" + llm.execution_instructions
except:
print('params["messages"][0]', params["messages"][0])
raise
Expand Down
12 changes: 6 additions & 6 deletions interpreter/core/llm/utils/convert_to_openai_messages.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,9 +73,9 @@ def convert_to_openai_messages(
# especially for the OpenAI service hosted on Azure
new_message["content"] = ""
else:
new_message[
"content"
] = f"""```{message["format"]}\n{message["content"]}\n```"""
new_message["content"] = (
f"""```{message["format"]}\n{message["content"]}\n```"""
)

elif message["type"] == "console" and message["format"] == "output":
if function_calling:
Expand All @@ -88,9 +88,9 @@ def convert_to_openai_messages(
print("\n\n\nStrange chunk found:", message, "\n\n\n")
message["content"] = str(message["content"])
if message["content"].strip() == "":
new_message[
"content"
] = "No output" # I think it's best to be explicit, but we should test this.
new_message["content"] = (
"No output" # I think it's best to be explicit, but we should test this.
)
else:
new_message["content"] = message["content"]

Expand Down
1 change: 1 addition & 0 deletions interpreter/core/utils/lazy_import.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import importlib.util
import sys


def lazy_import(name, optional=True):
"""Lazily import a module, specified by the name. Useful for optional packages, to speed up startup times."""
# Check if module is already imported
Expand Down
3 changes: 2 additions & 1 deletion interpreter/terminal_interface/profiles/defaults/cerebras.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,10 @@
See https://inference-docs.cerebras.ai/introduction for more information.
"""

from interpreter import interpreter
import os

from interpreter import interpreter

# LLM settings
interpreter.llm.api_base = "https://api.cerebras.ai/v1"
interpreter.llm.model = "openai/llama3.1-70b" # or "openai/Llama-3.1-8B"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,8 @@
# Set offline for all local models
interpreter.offline = True

import os, platform
import os
import platform

# Get the current user's login name
username = os.getlogin()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@
This is an Open Interpreter profile to chat with a database.
"""

from interpreter import interpreter
from datetime import date
import os
from datetime import date

from interpreter import interpreter

# Use environment variables for database connection or update defaults with your credentials
db_user = os.environ.get("DB_USER", "user")
Expand Down
3 changes: 2 additions & 1 deletion interpreter/terminal_interface/profiles/defaults/obsidian.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@
This is an Open Interpreter profile to control an Obsidian vault.
"""

from interpreter import interpreter
import os

from interpreter import interpreter

# You can hardcode the path to the Obsidian vault or use the environment variable
obsidian_directory = os.environ.get("OBSIDIAN_VAULT_PATH")

Expand Down
Loading