Skip to content

Commit

Permalink
feat:updated pyapp tray with check_for_updates (WIP)
Browse files Browse the repository at this point in the history
  • Loading branch information
jonnyjohnson1 committed Nov 9, 2024
1 parent 248a11c commit 1e04876
Show file tree
Hide file tree
Showing 19 changed files with 2,069 additions and 1,371 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -139,5 +139,5 @@ Insert this url into the field under settings-> "Api Endpoints" -> "Custom API"


## Future Setup
[ ] Theme the TUI [docs](https://f1bonacc1.github.io/process-compose/tui/)
[ ] Theme the TUI [docs](https://f1bonacc1.github.io/process-compose/tui/)
[ ] Remotely connect to TUI [docs](https://f1bonacc1.github.io/process-compose/client/)
14 changes: 13 additions & 1 deletion default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,21 @@ in pkgs.mkShell {
# Wait for PostgreSQL to start
sleep 2
set -x
# Set up the test database, role, and tables
echo "Setting up the test database..."
# psql -U $POSTGRES_USER -c "CREATE DATABASE $POSTGRES_DB;" || echo "Database $POSTGRES_DB already exists."
echo "POSTGRES_DB=$POSTGRES_DB"
echo "POSTGRES_USER=$POSTGRES_USER"
echo "POSTGRES_PASSWORD=$POSTGRES_PASSWORD"
echo "POSTGRES_HOST=$POSTGRES_HOST"
echo "POSTGRES_PORT=$POSTGRES_PORT"
psql -U dialogues -d postgres -c "ALTER USER $POSTGRES_USER WITH SUPERUSER;"
# Check if the database exists, create if not
psql -U "$POSTGRES_USER" -d postgres -tc "SELECT 1 FROM pg_database WHERE datname = '$POSTGRES_DB'" | grep -q 1 || \
psql -U "$POSTGRES_USER" -d postgres -c "CREATE DATABASE $POSTGRES_DB;"
psql -d $POSTGRES_DB <<SQL | tee -a $LOGFILE
-- Create the conversation table
Expand Down
3,290 changes: 1,935 additions & 1,355 deletions poetry.lock

Large diffs are not rendered by default.

13 changes: 13 additions & 0 deletions scripts/update_topos.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#!/bin/bash

# Shutdown the current topos process
pkill -f topos # Replace this with a specific shutdown command if needed

# Wait a moment for the shutdown to complete
sleep 2

# Get the latest release (you could fetch this in Python and pass it here)
LATEST_RELEASE=$(poetry run python -c "from topos.utils.check_for_update import get_latest_release_tag; print(get_latest_release_tag('jonnyjohnson1', 'topos-cli'))")

# Start the latest release
nix run github:repo_owner/repo_name/$LATEST_RELEASE
2 changes: 1 addition & 1 deletion topos/api/routers/analyze/graph.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
from topos.services.database.conversation_cache_manager import ConversationCacheManager

from ....services.generations_service.chat_gens import LLMController
from ....utilities.utils import create_conversation_string
from ....utils.utils import create_conversation_string
from ....services.ontology_service.mermaid_chart import MermaidCreator
from ....models.models import MermaidChartPayload

Expand Down
2 changes: 1 addition & 1 deletion topos/api/routers/analyze/summarize.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import os

from ....services.generations_service.chat_gens import LLMController
from ....utilities.utils import create_conversation_string
from ....utils.utils import create_conversation_string

# cache database
from topos.services.database.conversation_cache_manager import ConversationCacheManager
Expand Down
2 changes: 1 addition & 1 deletion topos/api/routers/analyze/topics.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
from topos.services.database.conversation_cache_manager import ConversationCacheManager

from ....services.generations_service.chat_gens import LLMController
from ....utilities.utils import create_conversation_string
from ....utils.utils import create_conversation_string
from ....models.models import ConversationTopicsRequest

import logging
Expand Down
2 changes: 1 addition & 1 deletion topos/api/routers/image/image.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
router = APIRouter()

from ....services.generations_service.chat_gens import LLMController
from ....utilities.utils import create_conversation_string
from ....utils.utils import create_conversation_string
from ....models.models import ConversationIDRequest

db_config = {
Expand Down
33 changes: 31 additions & 2 deletions topos/app/menu_bar_app.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
from ..api import api
from ..downloaders.spacy_loader import download_spacy_model
from topos.utilities.utils import get_root_directory
from topos.utils.utils import get_root_directory
from ..config import get_ssl_certificates
from ..utils.check_for_update import check_for_update, update_topos

import requests
import threading
Expand Down Expand Up @@ -50,13 +51,41 @@ def check_health(icon):
update_status(icon, f"Error: {str(e)}", "red")
time.sleep(5)

def check_for_update():
# Check the latest release status from the GitHub API
# Returns True if an update is available, else False
update_is_available = check_for_update("jonnyjohnson1", "topos-cli")
return update_is_available

def check_update_available(icon):
while icon.visible:
if check_for_update():
update_status(icon, "Update available", (255, 165, 0, 255)) # Orange indicator
# Add "Check for Update" option if update is available
icon.menu = pystray.Menu(
pystray.MenuItem("Open API Docs", open_docs),
pystray.MenuItem("Update your Topos", pull_latest_release),
pystray.MenuItem("Exit", on_exit)
)
else:
# Set the menu back to its default state without "Check for Update"
icon.menu = pystray.Menu(
pystray.MenuItem("Open API Docs", open_docs),
pystray.MenuItem("Exit", on_exit)
)
update_status(icon, "Service is running", (170, 255, 0, 255)) # Normal green status
time.sleep(60) # Check every minute

def pull_latest_release():
print("Pulling latest release...")
update_topos()

def update_status(icon, text, color):
icon.icon = create_image(color)

def open_docs():
webbrowser.open_new(DOCS_URL)


def create_image(color):
# Load the external image
external_image = Image.open(ASSETS_PATH).convert("RGBA")
Expand Down
2 changes: 1 addition & 1 deletion topos/chat_api/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
from fastapi.concurrency import asynccontextmanager
from topos.services.messages.group_management_service import GroupManagementService
from topos.services.messages.missed_message_service import MissedMessageService
from topos.utilities.utils import generate_deci_code, generate_group_name
from topos.utils.utils import generate_deci_code, generate_group_name
from pydantic import BaseModel
# MissedMessageRequest model // subject to change
class MissedMessagesRequest(BaseModel):
Expand Down
2 changes: 1 addition & 1 deletion topos/config.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from dotenv import load_dotenv
import os
from fastapi.middleware.cors import CORSMiddleware
from topos.utilities.utils import get_root_directory
from topos.utils.utils import get_root_directory


def get_openai_api_key():
Expand Down
2 changes: 1 addition & 1 deletion topos/downloaders/spacy_loader.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import yaml
import os
from ..utilities.utils import get_config_path
from ..utils.utils import get_config_path

def download_spacy_model(model_selection):
if model_selection == 'small':
Expand Down
2 changes: 1 addition & 1 deletion topos/services/basic_analytics/token_classifiers.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
from spacy.tokens import Token
import yaml

from topos.utilities.utils import get_config_path
from topos.utils.utils import get_config_path

# Assuming the config.yaml is in ./topos/ relative to setup.py directory
config_path = get_config_path()
Expand Down
2 changes: 1 addition & 1 deletion topos/services/classification_service/base_analysis.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from ..basic_analytics.token_classifiers import get_ner
from ..basic_analytics.text_classifiers import get_text_moderation_levels, get_text_sentiment_ternary, get_text_sentiment_27
from ...utilities.utils import is_connected
from ...utils.utils import is_connected

def base_token_classifier(last_message):
"""
Expand Down
2 changes: 1 addition & 1 deletion topos/services/messages/group_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
from psycopg2.extras import DictCursor
from datetime import datetime
from typing import List, Optional, Dict
from topos.utilities.utils import generate_deci_code
from topos.utils.utils import generate_deci_code
import os
from dotenv import load_dotenv

Expand Down
2 changes: 1 addition & 1 deletion topos/services/messages/missed_message_service.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from topos.services.messages.missed_message_manager import MissedMessageManager
from topos.services.messages.group_management_service import GroupManagementService
from topos.utilities.utils import sqlite_timestamp_to_ms
from topos.utils.utils import sqlite_timestamp_to_ms

KAFKA_TOPIC = 'chat_topic'

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
from datetime import datetime

from topos.services.database.app_state import AppState
from topos.utilities.utils import get_config_path
from topos.utils.utils import get_config_path
import os
import yaml

Expand Down
64 changes: 64 additions & 0 deletions topos/utils/check_for_update.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
import subprocess
import requests
import logging

# Configure logging
# logging.basicConfig(level=logging.DEBUG)
logger = logging.getLogger(__name__)


repo_owner = "jonnyjohnson1"
repo_name = "topos-cli"

def get_local_version_with_poetry():
"""
Uses Poetry CLI to get the local version from pyproject.toml.
"""
result = subprocess.run(["poetry", "version", "--short"], capture_output=True, text=True, check=True)
local_version = "v" + result.stdout.strip()
# logger.debug(f"Local version from Poetry: {local_version}")
return local_version

def get_latest_release_tag(repo_owner, repo_name):
"""
Fetches the latest release tag from a GitHub repository.
"""
url = f"https://api.github.com/repos/{repo_owner}/{repo_name}/releases/latest"
try:
response = requests.get(url)
response.raise_for_status()
latest_release = response.json()["tag_name"]
# logger.debug(f"Latest release from GitHub: {latest_release}")
return latest_release
except requests.ConnectionError:
logger.debug("No internet connection. Cannot check for the latest release.")
return None

def check_for_update(repo_owner, repo_name) -> bool:
"""
Checks if a new release is available by comparing the local version
obtained from Poetry with the latest GitHub release.
Returns False if no update is needed or if there is no internet connection.
"""
try:
local_version = get_local_version_with_poetry()
latest_release = get_latest_release_tag(repo_owner, repo_name)

# If we couldn't fetch the latest release (e.g., no internet), assume no update
if latest_release is None:
return False

if local_version == latest_release:
logger.debug("You have the latest release.")
return False
else:
logger.debug(f"New release available: {latest_release} (current version: {local_version})")
logger.debug("Consider updating to the latest release.")
return True

except Exception as e:
logger.debug(f"An error occurred: {e}")
return False

def update_topos():
subprocess.run(["./update_topos.sh"])
File renamed without changes.

0 comments on commit 1e04876

Please sign in to comment.