From 5d931a0e963869ca89f8017dba53ec967512b35d Mon Sep 17 00:00:00 2001 From: "Victor A." <52110451+cs50victor@users.noreply.github.com> Date: Mon, 1 Apr 2024 13:19:43 -0400 Subject: [PATCH] ruff --- core/source/clients/base_device.py | 6 ------ core/source/server/conftest.py | 3 --- core/source/server/i.py | 3 --- core/source/server/server.py | 5 +---- core/source/server/services/stt/local-whisper/stt.py | 3 --- core/source/server/services/tts/openai/tts.py | 4 +--- core/source/server/skills/schedule.py | 1 - core/source/server/tests/test_run.py | 5 ----- core/source/server/tunnel.py | 4 +--- core/source/server/utils/get_system_info.py | 1 - core/source/server/utils/local_mode.py | 8 +++----- core/source/server/utils/process_utils.py | 2 +- 12 files changed, 7 insertions(+), 38 deletions(-) diff --git a/core/source/clients/base_device.py b/core/source/clients/base_device.py index 43b491f..553b5b1 100644 --- a/core/source/clients/base_device.py +++ b/core/source/clients/base_device.py @@ -4,20 +4,14 @@ import os import asyncio import threading -import os import pyaudio -from starlette.websockets import WebSocket -from queue import Queue from pynput import keyboard import json import traceback import websockets import queue -import pydub -import ast from pydub import AudioSegment from pydub.playback import play -import io import time import wave import tempfile diff --git a/core/source/server/conftest.py b/core/source/server/conftest.py index 4684194..6ca7ddd 100644 --- a/core/source/server/conftest.py +++ b/core/source/server/conftest.py @@ -1,8 +1,5 @@ -import os -import sys import pytest from source.server.i import configure_interpreter -from unittest.mock import Mock from interpreter import OpenInterpreter from fastapi.testclient import TestClient from .server import app diff --git a/core/source/server/i.py b/core/source/server/i.py index 89deb5e..bb73917 100644 --- a/core/source/server/i.py +++ b/core/source/server/i.py @@ -1,11 +1,9 @@ from dotenv import load_dotenv load_dotenv() # take environment variables from .env. -import os import glob import time import json -from pathlib import Path from interpreter import OpenInterpreter import shutil @@ -295,7 +293,6 @@ def configure_interpreter(interpreter: OpenInterpreter): # if chunk.get("format") != "active_line": # print(chunk.get("content")) - import os from platformdirs import user_data_dir diff --git a/core/source/server/server.py b/core/source/server/server.py index 1934890..f575a3c 100644 --- a/core/source/server/server.py +++ b/core/source/server/server.py @@ -3,7 +3,6 @@ import traceback from platformdirs import user_data_dir -import ast import json import queue import os @@ -13,9 +12,7 @@ from fastapi import FastAPI, Request from fastapi.responses import PlainTextResponse from starlette.websockets import WebSocket, WebSocketDisconnect -from pathlib import Path import asyncio -import urllib.parse from .utils.kernel import put_kernel_messages_into_queue from .i import configure_interpreter from interpreter import interpreter @@ -362,7 +359,7 @@ def stream_tts(sentence): async def startup_event(): server_url = f"{HOST}:{PORT}" print("") - print_markdown(f"\n*Ready.*\n") + print_markdown("\n*Ready.*\n") print("") @app.on_event("shutdown") diff --git a/core/source/server/services/stt/local-whisper/stt.py b/core/source/server/services/stt/local-whisper/stt.py index cb53953..9ba9ad5 100644 --- a/core/source/server/services/stt/local-whisper/stt.py +++ b/core/source/server/services/stt/local-whisper/stt.py @@ -10,9 +10,6 @@ import ffmpeg import subprocess -import os -import subprocess -import platform import urllib.request diff --git a/core/source/server/services/tts/openai/tts.py b/core/source/server/services/tts/openai/tts.py index 8b15b22..a4e2902 100644 --- a/core/source/server/services/tts/openai/tts.py +++ b/core/source/server/services/tts/openai/tts.py @@ -2,8 +2,6 @@ import tempfile from openai import OpenAI import os -import subprocess -import tempfile from source.server.utils.logs import logger from source.server.utils.logs import setup_logging @@ -12,7 +10,7 @@ # If this TTS service is used, the OPENAI_API_KEY environment variable must be set if not os.getenv('OPENAI_API_KEY'): logger.error("") - logger.error(f"OpenAI API key not found. Please set the OPENAI_API_KEY environment variable, or run 01 with the --local option.") + logger.error("OpenAI API key not found. Please set the OPENAI_API_KEY environment variable, or run 01 with the --local option.") logger.error("Aborting...") logger.error("") os._exit(1) diff --git a/core/source/server/skills/schedule.py b/core/source/server/skills/schedule.py index f351c59..e3ae1c4 100644 --- a/core/source/server/skills/schedule.py +++ b/core/source/server/skills/schedule.py @@ -3,7 +3,6 @@ from pytimeparse import parse from crontab import CronTab from uuid import uuid4 -from datetime import datetime from platformdirs import user_data_dir def schedule(message="", start=None, interval=None) -> None: diff --git a/core/source/server/tests/test_run.py b/core/source/server/tests/test_run.py index ce04932..ac07d59 100644 --- a/core/source/server/tests/test_run.py +++ b/core/source/server/tests/test_run.py @@ -1,10 +1,5 @@ # test_main.py -import subprocess -import uuid import pytest -from source.server.i import configure_interpreter -from unittest.mock import Mock -from fastapi.testclient import TestClient diff --git a/core/source/server/tunnel.py b/core/source/server/tunnel.py index 5d55a97..8d74f0d 100644 --- a/core/source/server/tunnel.py +++ b/core/source/server/tunnel.py @@ -1,12 +1,10 @@ -import os import subprocess import re -import shutil import time from ..utils.print_markdown import print_markdown def create_tunnel(tunnel_method='ngrok', server_host='localhost', server_port=10001): - print_markdown(f"Exposing server to the internet...") + print_markdown("Exposing server to the internet...") if tunnel_method == "bore": try: diff --git a/core/source/server/utils/get_system_info.py b/core/source/server/utils/get_system_info.py index 8989d44..9faae2d 100644 --- a/core/source/server/utils/get_system_info.py +++ b/core/source/server/utils/get_system_info.py @@ -1,4 +1,3 @@ -import os import platform def get_system_info(): diff --git a/core/source/server/utils/local_mode.py b/core/source/server/utils/local_mode.py index 6d7113c..4536819 100644 --- a/core/source/server/utils/local_mode.py +++ b/core/source/server/utils/local_mode.py @@ -1,6 +1,4 @@ import sys -import os -import platform import subprocess import time import inquirer @@ -67,7 +65,7 @@ def select_local_model(): if not names: time.sleep(1) - interpreter.display_message(f"\nYou don't have any Ollama models downloaded. To download a new model, run `ollama run `, then start a new 01 session. \n\n For a full list of downloadable models, check out [https://ollama.com/library](https://ollama.com/library) \n") + interpreter.display_message("\nYou don't have any Ollama models downloaded. To download a new model, run `ollama run `, then start a new 01 session. \n\n For a full list of downloadable models, check out [https://ollama.com/library](https://ollama.com/library) \n") print("Please download a model then try again\n") time.sleep(2) @@ -91,10 +89,10 @@ def select_local_model(): time.sleep(1) # If Ollama is not installed or not recognized as a command, prompt the user to download Ollama and try again - except (subprocess.CalledProcessError, FileNotFoundError) as e: + except (subprocess.CalledProcessError, FileNotFoundError): print("Ollama is not installed or not recognized as a command.") time.sleep(1) - interpreter.display_message(f"\nPlease visit [https://ollama.com/](https://ollama.com/) to download Ollama and try again\n") + interpreter.display_message("\nPlease visit [https://ollama.com/](https://ollama.com/) to download Ollama and try again\n") time.sleep(2) sys.exit(1) diff --git a/core/source/server/utils/process_utils.py b/core/source/server/utils/process_utils.py index adcf028..ebcd08c 100644 --- a/core/source/server/utils/process_utils.py +++ b/core/source/server/utils/process_utils.py @@ -25,4 +25,4 @@ def kill_process_tree(): except psutil.NoSuchProcess: print(f"Process {pid} does not exist or is already terminated") except psutil.AccessDenied: - print(f"Permission denied to terminate some processes") + print("Permission denied to terminate some processes")