diff --git a/.gitignore b/.gitignore index f40c47a..c0e7704 100644 --- a/.gitignore +++ b/.gitignore @@ -6,8 +6,8 @@ __pycache__/ venv/ current -# Ignore extensions configuration -extensions/config.py +# Ignore all instances of config.py +**/config.py # Ignore video files *.mp4 @@ -15,5 +15,5 @@ extensions/config.py # Other extensions/youtube -cached_images/* +**/cached_images/ **/.DS_Store \ No newline at end of file diff --git a/README.md b/README.md index 5261797..9d58008 100644 --- a/README.md +++ b/README.md @@ -10,14 +10,14 @@ This fork of MacProxy adds supp ### Extensions -Each extension has its own folder within the `extensions` directory. Extensions can be individually enabled or disabled via a `config.py` file in the root of the `extensions` directory. +Each extension has its own folder within the `extensions` directory. Extensions can be individually enabled or disabled via a `config.py` file in the root directory. To enable extensions: -1. In the ```extensions``` directory, rename ```config.py.example``` to ```config.py``` : +1. In the root directory, rename ```config.py.example``` to ```config.py``` : ```shell - mv extensions/config.py.example extensions/config.py + mv config.py.example config.py ``` 2. In ```config.py```, enable/disable extensions by uncommenting/commenting lines in the ```ENABLED_EXTENSIONS``` list: @@ -41,7 +41,7 @@ Run the ```start_macproxy.sh``` script. If an enabled extension relies on any ex A ChatGPT extension is provided as an example. This extension serves a simple web interface that lets users interact with OpenAI's GPT models. -To enable the ChatGPT extension, open ```extensions/config.py```, uncomment the ```chatgpt``` line in the ```ENABLED_EXTENSIONS``` list, and replace ```YOUR_OPENAI_API_KEY_HERE``` with your actual OpenAI API key. +To enable the ChatGPT extension, open ```config.py```, uncomment the ```chatgpt``` line in the ```ENABLED_EXTENSIONS``` list, and replace ```YOUR_OPENAI_API_KEY_HERE``` with your actual OpenAI API key. ```python open_ai_api_key = "YOUR_OPENAI_API_KEY_HERE" diff --git a/extensions/config.py.example b/config.py.example similarity index 68% rename from extensions/config.py.example rename to config.py.example index 126209e..866592d 100644 --- a/extensions/config.py.example +++ b/config.py.example @@ -2,13 +2,13 @@ # and fill in the necessary API keys and other details. # Store API keys and other configuration details here: -# open_ai_api_key = "YOUR_OPENAI_API_KEY_HERE" -# anthropic_api_key = "YOUR_ANTHROPIC_API_KEY_HERE" -# mistral_api_key = "YOUR_MISTRAL_API_KEY_HERE" -# kagi_session_token = "YOUR_KAGI_SESSION_TOKEN_HERE" +# OPEN_AI_API_KEY = "YOUR_OPENAI_API_KEY_HERE" +# ANTHROPIC_API_KEY = "YOUR_ANTHROPIC_API_KEY_HERE" +# MISTRAL_API_KEY = "YOUR_MISTRAL_API_KEY_HERE" +# KAGI_SESSION_TOKEN = "YOUR_KAGI_SESSION_TOKEN_HERE" # Used by weather extension (which currently only works for United States) -# zip_code = "YOUR_ZIP_CODE" +# ZIP_CODE = "YOUR_ZIP_CODE" # Uncomment lines to enable desired extensions: ENABLED_EXTENSIONS = [ @@ -19,13 +19,12 @@ ENABLED_EXTENSIONS = [ #"hunterirving", #"kagi", #"mistral", + #"notyoutube" #"npr", - #"override", #"reddit", #"waybackmachine", #"weather", #"websimulator", #"wiby", #"wikipedia", - #"notyoutube" ] diff --git a/extensions/chatgpt/chatgpt.py b/extensions/chatgpt/chatgpt.py index b99c373..fb82a64 100644 --- a/extensions/chatgpt/chatgpt.py +++ b/extensions/chatgpt/chatgpt.py @@ -1,9 +1,9 @@ from flask import request, render_template_string from openai import OpenAI -import extensions.config as config +import config # Initialize the OpenAI client with your API key -client = OpenAI(api_key=config.open_ai_api_key) +client = OpenAI(api_key=config.OPEN_AI_API_KEY) DOMAIN = "chatgpt.com" diff --git a/extensions/claude/claude.py b/extensions/claude/claude.py index 9617eb1..5636116 100644 --- a/extensions/claude/claude.py +++ b/extensions/claude/claude.py @@ -1,14 +1,14 @@ from flask import request, render_template_string import anthropic -import extensions.config as config +import config # Initialize the Anthropic client with your API key -client = anthropic.Anthropic(api_key=config.anthropic_api_key) +client = anthropic.Anthropic(api_key=config.ANTHROPIC_API_KEY) DOMAIN = "claude.ai" messages = [] -selected_model = "claude-3-5-sonnet-20240620" +selected_model = "claude-3-5-sonnet-latest" previous_model = selected_model system_prompt = """Please provide your response in plain text using only ASCII characters. @@ -35,7 +35,7 @@ - + +

{{ output|safe }}

diff --git a/extensions/mistral/requirements.txt b/extensions/mistral/requirements.txt index c3c47fe..a4dba8a 100644 --- a/extensions/mistral/requirements.txt +++ b/extensions/mistral/requirements.txt @@ -1,2 +1 @@ -MistralAI -Mistral \ No newline at end of file +mistralai \ No newline at end of file diff --git a/extensions/notyoutube/notyoutube.py b/extensions/notyoutube/notyoutube.py index f9b0416..610f44e 100644 --- a/extensions/notyoutube/notyoutube.py +++ b/extensions/notyoutube/notyoutube.py @@ -7,6 +7,7 @@ import subprocess from flask import request, send_file, render_template_string from urllib.parse import urlparse, parse_qs +import config DOMAIN = "notyoutube.com" EXTENSION_DIR = os.path.dirname(os.path.abspath(__file__)) diff --git a/extensions/weather/weather.py b/extensions/weather/weather.py index 0d77558..ee26f1b 100644 --- a/extensions/weather/weather.py +++ b/extensions/weather/weather.py @@ -1,11 +1,11 @@ from flask import request, redirect import requests from bs4 import BeautifulSoup -import extensions.config as config +import config import urllib.parse DOMAIN = "weather.gov" -DEFAULT_LOCATION = config.zip_code +DEFAULT_LOCATION = config.ZIP_CODE def process_html(content): soup = BeautifulSoup(content, 'html.parser') diff --git a/extensions/websimulator/websimulator.py b/extensions/websimulator/websimulator.py index 1a47328..9805615 100644 --- a/extensions/websimulator/websimulator.py +++ b/extensions/websimulator/websimulator.py @@ -3,10 +3,10 @@ from flask import request, render_template_string import anthropic -import extensions.config as config +import config from urllib.parse import urlparse, parse_qs -client = anthropic.Anthropic(api_key=config.anthropic_api_key) +client = anthropic.Anthropic(api_key=config.ANTHROPIC_API_KEY) RED = '\033[91m' diff --git a/proxy.py b/proxy.py index b410177..585a1e1 100644 --- a/proxy.py +++ b/proxy.py @@ -2,7 +2,7 @@ import requests import argparse from flask import Flask, request, session, g, abort, Response, send_from_directory -from html_utils import transcode_html +from utils.html_utils import transcode_html from urllib.parse import urlparse, urljoin from bs4 import BeautifulSoup import io @@ -10,7 +10,7 @@ import hashlib import shutil import mimetypes -from image_utils import is_image_url, fetch_and_cache_image, CACHE_DIR +from utils.image_utils import is_image_url, fetch_and_cache_image, CACHE_DIR os.environ['FLASK_ENV'] = 'development' app = Flask(__name__) @@ -33,12 +33,12 @@ def clear_image_cache(): clear_image_cache() -# Try to import config.py from the extensions folder and enable extensions +# Try to import config.py and enable extensions try: - import extensions.config as config + import config ENABLED_EXTENSIONS = config.ENABLED_EXTENSIONS except ModuleNotFoundError: - print("config.py not found in extensions folder, running without extensions") + print("config.py not found, running without extensions") ENABLED_EXTENSIONS = [] # Load extensions diff --git a/start_macproxy.sh b/start_macproxy.sh index ca1ed99..73fe6ab 100755 --- a/start_macproxy.sh +++ b/start_macproxy.sh @@ -53,7 +53,7 @@ source venv/bin/activate # Gather all requirements from enabled extensions ALL_REQUIREMENTS="" -for ext in $(python3 -c "import extensions.config as config; print(' '.join(config.ENABLED_EXTENSIONS))"); do +for ext in $(python3 -c "import config; print(' '.join(config.ENABLED_EXTENSIONS))"); do if test -e "extensions/$ext/requirements.txt"; then ALL_REQUIREMENTS+=" -r extensions/$ext/requirements.txt" fi diff --git a/html_utils.py b/utils/html_utils.py similarity index 100% rename from html_utils.py rename to utils/html_utils.py diff --git a/image_utils.py b/utils/image_utils.py similarity index 100% rename from image_utils.py rename to utils/image_utils.py