From 9d67bfce97636ab37f79c6ebfb58ac61fb95d0de Mon Sep 17 00:00:00 2001 From: jonmatthis Date: Tue, 15 Oct 2024 06:37:59 -0400 Subject: [PATCH] uv package --- .env.discord.example | 2 +- .env.openai.example | 2 +- .github/workflows/google-cloudrun-docker.yml | 1 + src_python/{main.py => __main__.py} | 6 +++--- src_python/requirements.txt | 6 ------ src_python/src/ai/analyze_directory.py | 8 ++++---- src_python/src/ai/analyze_text.py | 8 ++++---- src_python/src/ai/construct_prompt.py | 2 +- src_python/src/models/extract_text_data.py | 4 ++-- src_python/src/models/server_data_model.py | 4 ++-- src_python/src/models/student_info.py | 2 +- src_python/src/scrape_server/build_couplet_list.py | 2 +- src_python/src/scrape_server/save_to_disk.py | 6 +++--- src_python/src/scrape_server/scrape_server.py | 4 ++-- src_python/src/utilities/load_env_variables.py | 7 +++++++ 15 files changed, 33 insertions(+), 31 deletions(-) rename src_python/{main.py => __main__.py} (87%) delete mode 100644 src_python/requirements.txt diff --git a/.env.discord.example b/.env.discord.example index b1d5efd..c6b245a 100644 --- a/.env.discord.example +++ b/.env.discord.example @@ -1 +1 @@ -DISCORD_BOT_TOKEN= \ No newline at end of file +DISCORD_BOT_TOKEN= diff --git a/.env.openai.example b/.env.openai.example index fff3e69..b56f74d 100644 --- a/.env.openai.example +++ b/.env.openai.example @@ -1 +1 @@ -OPENAI_API_KEY = \ No newline at end of file +OPENAI_API_KEY = diff --git a/.github/workflows/google-cloudrun-docker.yml b/.github/workflows/google-cloudrun-docker.yml index 544bd06..518d41b 100644 --- a/.github/workflows/google-cloudrun-docker.yml +++ b/.github/workflows/google-cloudrun-docker.yml @@ -49,6 +49,7 @@ on: branches: [ "main" ] paths-ignore: - 'Writerside/**' #don't build if changes are only to docs + - 'src_python/**' #don't build if changes are only to python analysis code env: PROJECT_ID: mocap-test-project # TODO: update Google Cloud project id diff --git a/src_python/main.py b/src_python/__main__.py similarity index 87% rename from src_python/main.py rename to src_python/__main__.py index bf12312..764ef6e 100644 --- a/src_python/main.py +++ b/src_python/__main__.py @@ -7,9 +7,9 @@ from src.configure_logging import configure_logging -from src_python.src.scrape_server.save_to_disk import save_server_data_to_disk -from src_python.src.scrape_server.scrape_server import process_server -from src_python.src.utilities.load_env_variables import DISCORD_DEV_BOT_ID, OUTPUT_DIRECTORY, TARGET_SERVER_ID, \ +from src.scrape_server.save_to_disk import save_server_data_to_disk +from src.scrape_server.scrape_server import process_server +from src.utilities.load_env_variables import DISCORD_DEV_BOT_ID, OUTPUT_DIRECTORY, TARGET_SERVER_ID, \ STUDENT_IDENTIFIERS_CSV_PATH, DISCORD_DEV_BOT_TOKEN configure_logging() diff --git a/src_python/requirements.txt b/src_python/requirements.txt deleted file mode 100644 index 53607ef..0000000 --- a/src_python/requirements.txt +++ /dev/null @@ -1,6 +0,0 @@ -discord -openai -python-dotenv -pandas -pydantic[email] -tiktoken \ No newline at end of file diff --git a/src_python/src/ai/analyze_directory.py b/src_python/src/ai/analyze_directory.py index a4cd818..96fa233 100644 --- a/src_python/src/ai/analyze_directory.py +++ b/src_python/src/ai/analyze_directory.py @@ -4,9 +4,9 @@ from pydantic import BaseModel -from src_python.src.ai.analyze_text import analyze_text -from src_python.src.configure_logging import configure_logging -from src_python.src.models.extract_text_data import ExtractedTextData +from src.ai.analyze_text import analyze_text +from src.configure_logging import configure_logging +from src.models.extract_text_data import ExtractedTextData configure_logging() import logging @@ -80,7 +80,7 @@ async def analyze_markdown_file(base_prompt_text: str, if __name__ == "__main__": - from src_python.src.utilities.load_env_variables import OUTPUT_DIRECTORY + from src.utilities.load_env_variables import OUTPUT_DIRECTORY in_server_name = "HMN_Fall24" classbot_prompt_file_name = f"{in_server_name}-prompt.txt" diff --git a/src_python/src/ai/analyze_text.py b/src_python/src/ai/analyze_text.py index c6a3869..004cd21 100644 --- a/src_python/src/ai/analyze_text.py +++ b/src_python/src/ai/analyze_text.py @@ -9,10 +9,10 @@ from openai import AsyncOpenAI from pydantic import BaseModel -from src_python.src.ai.construct_prompt import construct_analyzer_prompt -from src_python.src.configure_logging import configure_logging +from src.ai.construct_prompt import construct_analyzer_prompt +from src.configure_logging import configure_logging -from src_python.src.models.extract_text_data import ExtractedTextData +from src.models.extract_text_data import ExtractedTextData configure_logging() logger = logging.getLogger(__name__) @@ -105,7 +105,7 @@ async def get_ai_response(analyzer_prompt, llm_model, openai_client): if __name__ == "__main__": - from src_python.src.tests.test_extraction import TEST_STRING + from src.tests.test_extraction import TEST_STRING test_string = TEST_STRING constructed_pydantic_model_out = analyze_text(test_string, ExtractedTextData) diff --git a/src_python/src/ai/construct_prompt.py b/src_python/src/ai/construct_prompt.py index 42b3d6c..7355326 100644 --- a/src_python/src/ai/construct_prompt.py +++ b/src_python/src/ai/construct_prompt.py @@ -3,7 +3,7 @@ from pydantic import BaseModel, Field -from src_python.src.models.extract_text_data import ExtractedTextData +from src.models.extract_text_data import ExtractedTextData logger = logging.getLogger(__name__) diff --git a/src_python/src/models/extract_text_data.py b/src_python/src/models/extract_text_data.py index 8bddaed..c47efae 100644 --- a/src_python/src/models/extract_text_data.py +++ b/src_python/src/models/extract_text_data.py @@ -1,6 +1,6 @@ from pydantic import BaseModel, Field -from src_python.src.utilities.sanitize_filename import sanitize_name +from src.utilities.sanitize_filename import sanitize_name class ExtractedTextData(BaseModel): @@ -52,7 +52,7 @@ def __str__(self): if __name__ == "__main__": - from src_python.src.ai.construct_prompt import construct_analyzer_prompt + from src.ai.construct_prompt import construct_analyzer_prompt data = ExtractedTextData( detailed_summary="This is a detailed summary of the text", diff --git a/src_python/src/models/server_data_model.py b/src_python/src/models/server_data_model.py index 4f0a5c9..6d1833a 100644 --- a/src_python/src/models/server_data_model.py +++ b/src_python/src/models/server_data_model.py @@ -5,8 +5,8 @@ from pydantic import BaseModel -from src_python.src.models.content_message_models import ContentMessage -from src_python.src.utilities.sanitize_filename import sanitize_name +from src.models.content_message_models import ContentMessage +from src.utilities.sanitize_filename import sanitize_name class ChatThread(BaseModel): diff --git a/src_python/src/models/student_info.py b/src_python/src/models/student_info.py index f60d0be..11d55c5 100644 --- a/src_python/src/models/student_info.py +++ b/src_python/src/models/student_info.py @@ -3,7 +3,7 @@ from pydantic import BaseModel, EmailStr, FilePath -from src_python.src.models.server_data_model import CategoryData +from src.models.server_data_model import CategoryData class StudentInfoModel(BaseModel): diff --git a/src_python/src/scrape_server/build_couplet_list.py b/src_python/src/scrape_server/build_couplet_list.py index 78ea372..a3f351a 100644 --- a/src_python/src/scrape_server/build_couplet_list.py +++ b/src_python/src/scrape_server/build_couplet_list.py @@ -1,7 +1,7 @@ import logging from typing import List -from src_python.src.models.content_message_models import ContentMessage +from src.models.content_message_models import ContentMessage logger = logging.getLogger(__name__) diff --git a/src_python/src/scrape_server/save_to_disk.py b/src_python/src/scrape_server/save_to_disk.py index a3b0db4..1c6762e 100644 --- a/src_python/src/scrape_server/save_to_disk.py +++ b/src_python/src/scrape_server/save_to_disk.py @@ -3,9 +3,9 @@ from datetime import datetime from pathlib import Path -from src_python.src.models.server_data_model import ServerData, save_as_markdown_directory, save_as_json -from src_python.src.models.student_info import ClassRosterModel -from src_python.src.utilities.sanitize_filename import sanitize_name +from src.models.server_data_model import ServerData, save_as_markdown_directory, save_as_json +from src.models.student_info import ClassRosterModel +from src.utilities.sanitize_filename import sanitize_name logger = logging.getLogger(__name__) diff --git a/src_python/src/scrape_server/scrape_server.py b/src_python/src/scrape_server/scrape_server.py index 57ad538..f734e66 100644 --- a/src_python/src/scrape_server/scrape_server.py +++ b/src_python/src/scrape_server/scrape_server.py @@ -3,8 +3,8 @@ import discord -from src_python.src.models.content_message_models import ContentMessage -from src_python.src.models.server_data_model import ChannelData, CategoryData, ServerData, ChatThread +from src.models.content_message_models import ContentMessage +from src.models.server_data_model import ChannelData, CategoryData, ServerData, ChatThread logger = logging.getLogger(__name__) diff --git a/src_python/src/utilities/load_env_variables.py b/src_python/src/utilities/load_env_variables.py index 7085e6c..ef4eed2 100644 --- a/src_python/src/utilities/load_env_variables.py +++ b/src_python/src/utilities/load_env_variables.py @@ -8,6 +8,11 @@ raise FileNotFoundError(f".env.analysis file not found at: {env_analysis_path}") load_dotenv(str(env_analysis_path)) +env_discord_path = Path(__file__).parent.parent.parent.parent / ".env.discord" +if not os.path.exists(env_discord_path): + raise FileNotFoundError(f".env.discord file not found at: {env_discord_path}") +load_dotenv(str(env_discord_path)) + DISCORD_DEV_BOT_TOKEN = os.getenv('DISCORD_DEV_BOT_TOKEN') DISCORD_DEV_BOT_ID = os.getenv('DISCORD_DEV_BOT_ID') @@ -15,6 +20,8 @@ OUTPUT_DIRECTORY = os.getenv('OUTPUT_DIRECTORY') STUDENT_IDENTIFIERS_CSV_PATH = os.getenv('STUDENT_IDENTIFIERS_CSV_PATH') +OUTPUT_DIRECTORY = OUTPUT_DIRECTORY.replace("~", str(Path.home())) + # Ensure the environment variables are set if not DISCORD_DEV_BOT_TOKEN or not OUTPUT_DIRECTORY or not OUTPUT_DIRECTORY: raise ValueError("Please set DISCORD_DEV_BOT_TOKEN and OUTPUT_DIRECTORY in your .env file")