Skip to content

Commit

Permalink
clean up/restructure code for future enhancements
Browse files Browse the repository at this point in the history
  • Loading branch information
hunterirving committed Oct 25, 2024
1 parent ddb0c5c commit 8ddab81
Show file tree
Hide file tree
Showing 15 changed files with 38 additions and 39 deletions.
6 changes: 3 additions & 3 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,14 @@ __pycache__/
venv/
current

# Ignore extensions configuration
extensions/config.py
# Ignore all instances of config.py
**/config.py

# Ignore video files
*.mp4
*.flim

# Other
extensions/youtube
cached_images/*
**/cached_images/
**/.DS_Store
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,14 @@ This fork of <a href="https://github.com/rdmark/macproxy">MacProxy</a> 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:
Expand All @@ -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"
Expand Down
13 changes: 6 additions & 7 deletions extensions/config.py.example → config.py.example
Original file line number Diff line number Diff line change
Expand Up @@ -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 = [
Expand All @@ -19,13 +19,12 @@ ENABLED_EXTENSIONS = [
#"hunterirving",
#"kagi",
#"mistral",
#"notyoutube"
#"npr",
#"override",
#"reddit",
#"waybackmachine",
#"weather",
#"websimulator",
#"wiby",
#"wikipedia",
#"notyoutube"
]
4 changes: 2 additions & 2 deletions extensions/chatgpt/chatgpt.py
Original file line number Diff line number Diff line change
@@ -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"

Expand Down
8 changes: 4 additions & 4 deletions extensions/claude/claude.py
Original file line number Diff line number Diff line change
@@ -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.
Expand All @@ -35,7 +35,7 @@
<input type="text" size="38" name="command" required autocomplete="off">
<input type="submit" value="Submit">
<select id="model" name="model">
<option value="claude-3-5-sonnet-20240620" {{ 'selected' if selected_model == 'claude-3-5-sonnet-20240620' else '' }}>Claude 3.5 Sonnet</option>
<option value="claude-3-5-sonnet-latest" {{ 'selected' if selected_model == 'claude-3-5-sonnet-latest' else '' }}>Claude 3.5 Sonnet</option>
<option value="claude-3-opus-20240229" {{ 'selected' if selected_model == 'claude-3-opus-20240229' else '' }}>Claude 3 Opus</option>
<option value="claude-3-sonnet-20240229" {{ 'selected' if selected_model == 'claude-3-sonnet-20240229' else '' }}>Claude 3 Sonnet</option>
<option value="claude-3-haiku-20240307" {{ 'selected' if selected_model == 'claude-3-haiku-20240307' else '' }}>Claude 3 Haiku</option>
Expand Down
6 changes: 3 additions & 3 deletions extensions/kagi/kagi.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
from flask import render_template_string
import requests
from bs4 import BeautifulSoup
import extensions.config as config
from image_utils import is_image_url
import config
from utils.image_utils import is_image_url
import os
import math
from urllib.parse import urlencode
Expand All @@ -29,7 +29,7 @@ def handle_request(req):
url = f"https://kagi.com/html{req.path}"

args = {
'token': config.kagi_session_token
'token': config.KAGI_SESSION_TOKEN
}

for key, value in req.args.items():
Expand Down
8 changes: 4 additions & 4 deletions extensions/mistral/mistral.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
from flask import request, render_template_string
from mistralai import Mistral
import extensions.config as config
import config

# Initialize the Mistral Client with your API key
client = Mistral(api_key=config.mistral_api_key)
client = Mistral(api_key=config.MISTRAL_API_KEY)

DOMAIN = "chat.mistral.ai"

Expand Down Expand Up @@ -32,14 +32,14 @@
</head>
<body>
<form method="post" action="/">
<input type="text" size="38" name="command" required autocomplete="off">
<input type="submit" value="Submit">
<select id="model" name="model">
<option value="mistral-large-latest" {{ 'selected' if selected_model == 'mistral-large-latest' else '' }}>Mistral Large 2407 123b</option>
<option value="mistral-small-latest" {{ 'selected' if selected_model == 'mistral-small-latest' else '' }}>Mistral Small 2409 22b</option>
<option value="open-mistral-nemo" {{ 'selected' if selected_model == 'open-mistral-nemo' else '' }}>Mistral Nemo 2407 12b</option>
<option value="ministral-8b-latest" {{ 'selected' if selected_model == 'ministral-8b-latest' else '' }}>Ministral 2410 8b</option>
</select>
<input type="text" size="64" name="command" required autocomplete="off">
<input type="submit" value="Submit">
</form>
<div id="chat">
<p>{{ output|safe }}</p>
Expand Down
3 changes: 1 addition & 2 deletions extensions/mistral/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
MistralAI
Mistral
mistralai
1 change: 1 addition & 0 deletions extensions/notyoutube/notyoutube.py
Original file line number Diff line number Diff line change
Expand Up @@ -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__))
Expand Down
4 changes: 2 additions & 2 deletions extensions/weather/weather.py
Original file line number Diff line number Diff line change
@@ -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')
Expand Down
4 changes: 2 additions & 2 deletions extensions/websimulator/websimulator.py
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down
10 changes: 5 additions & 5 deletions proxy.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@
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
from PIL import Image
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__)
Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion start_macproxy.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
File renamed without changes.
File renamed without changes.

0 comments on commit 8ddab81

Please sign in to comment.