diff --git a/backend/onyx/configs/app_configs.py b/backend/onyx/configs/app_configs.py index ceb38ca82..4de6dfdc1 100644 --- a/backend/onyx/configs/app_configs.py +++ b/backend/onyx/configs/app_configs.py @@ -642,14 +642,4 @@ MOCK_LLM_RESPONSE = ( ) -# Image processing configurations -ENABLE_IMAGE_EXTRACTION = ( - os.environ.get("ENABLE_IMAGE_EXTRACTION", "true").lower() == "true" -) -ENABLE_INDEXING_TIME_IMAGE_ANALYSIS = not ( - os.environ.get("DISABLE_INDEXING_TIME_IMAGE_ANALYSIS", "false").lower() == "true" -) -ENABLE_SEARCH_TIME_IMAGE_ANALYSIS = not ( - os.environ.get("DISABLE_SEARCH_TIME_IMAGE_ANALYSIS", "false").lower() == "true" -) -IMAGE_ANALYSIS_MAX_SIZE_MB = int(os.environ.get("IMAGE_ANALYSIS_MAX_SIZE_MB", "20")) +DEFAULT_IMAGE_ANALYSIS_MAX_SIZE_MB = 20 diff --git a/backend/onyx/configs/llm_configs.py b/backend/onyx/configs/llm_configs.py new file mode 100644 index 000000000..97332fa83 --- /dev/null +++ b/backend/onyx/configs/llm_configs.py @@ -0,0 +1,38 @@ +from onyx.configs.app_configs import DEFAULT_IMAGE_ANALYSIS_MAX_SIZE_MB +from onyx.server.settings.store import load_settings + + +def get_image_extraction_and_analysis_enabled(): + """Get image extraction and analysis enabled setting from workspace settings or fallback to environment variable""" + try: + settings = load_settings() + if settings.image_extraction_and_analysis_enabled is not None: + return settings.image_extraction_and_analysis_enabled + except Exception: + pass + + return False + + +def get_search_time_image_analysis_enabled(): + """Get search time image analysis enabled setting from workspace settings or fallback to environment variable""" + try: + settings = load_settings() + if settings.search_time_image_analysis_enabled is not None: + return settings.search_time_image_analysis_enabled + except Exception: + pass + + return False + + +def get_image_analysis_max_size_mb(): + """Get image analysis max size MB setting from workspace settings or fallback to environment variable""" + try: + settings = load_settings() + if settings.image_analysis_max_size_mb is not None: + return settings.image_analysis_max_size_mb + except Exception: + pass + + return DEFAULT_IMAGE_ANALYSIS_MAX_SIZE_MB diff --git a/backend/onyx/connectors/vision_enabled_connector.py b/backend/onyx/connectors/vision_enabled_connector.py index 385c70356..021fb759b 100644 --- a/backend/onyx/connectors/vision_enabled_connector.py +++ b/backend/onyx/connectors/vision_enabled_connector.py @@ -1,7 +1,7 @@ """ Mixin for connectors that need vision capabilities. """ -from onyx.configs.app_configs import ENABLE_INDEXING_TIME_IMAGE_ANALYSIS +from onyx.configs.llm_configs import get_image_extraction_and_analysis_enabled from onyx.llm.factory import get_default_llm_with_vision from onyx.llm.interfaces import LLM from onyx.utils.logger import setup_logger @@ -30,7 +30,7 @@ class VisionEnabledConnector: Sets self.image_analysis_llm to the LLM instance or None if disabled. """ self.image_analysis_llm: LLM | None = None - if ENABLE_INDEXING_TIME_IMAGE_ANALYSIS: + if get_image_extraction_and_analysis_enabled(): try: self.image_analysis_llm = get_default_llm_with_vision() if self.image_analysis_llm is None: diff --git a/backend/onyx/context/search/postprocessing/postprocessing.py b/backend/onyx/context/search/postprocessing/postprocessing.py index 9d3a07d93..7f88ec00e 100644 --- a/backend/onyx/context/search/postprocessing/postprocessing.py +++ b/backend/onyx/context/search/postprocessing/postprocessing.py @@ -10,8 +10,8 @@ from langchain_core.messages import SystemMessage from onyx.chat.models import SectionRelevancePiece from onyx.configs.app_configs import BLURB_SIZE -from onyx.configs.app_configs import ENABLE_SEARCH_TIME_IMAGE_ANALYSIS from onyx.configs.constants import RETURN_SEPARATOR +from onyx.configs.llm_configs import get_search_time_image_analysis_enabled from onyx.configs.model_configs import CROSS_ENCODER_RANGE_MAX from onyx.configs.model_configs import CROSS_ENCODER_RANGE_MIN from onyx.context.search.enums import LLMEvaluationType @@ -413,7 +413,7 @@ def search_postprocessing( # NOTE: if we don't rerank, we can return the chunks immediately # since we know this is the final order. # This way the user experience isn't delayed by the LLM step - if ENABLE_SEARCH_TIME_IMAGE_ANALYSIS: + if get_search_time_image_analysis_enabled(): update_image_sections_with_query( retrieved_sections, search_query.query, llm ) @@ -456,7 +456,7 @@ def search_postprocessing( _log_top_section_links(search_query.search_type.value, reranked_sections) # Add the image processing step here - if ENABLE_SEARCH_TIME_IMAGE_ANALYSIS: + if get_search_time_image_analysis_enabled(): update_image_sections_with_query( reranked_sections, search_query.query, llm ) diff --git a/backend/onyx/server/settings/models.py b/backend/onyx/server/settings/models.py index 7e1e5ef74..f84c59818 100644 --- a/backend/onyx/server/settings/models.py +++ b/backend/onyx/server/settings/models.py @@ -53,6 +53,11 @@ class Settings(BaseModel): auto_scroll: bool | None = False query_history_type: QueryHistoryType | None = None + # Image processing settings + image_extraction_and_analysis_enabled: bool | None = False + search_time_image_analysis_enabled: bool | None = False + image_analysis_max_size_mb: int | None = 20 + class UserSettings(Settings): notifications: list[Notification] diff --git a/backend/onyx/server/settings/store.py b/backend/onyx/server/settings/store.py index d35b306f5..3cb15523f 100644 --- a/backend/onyx/server/settings/store.py +++ b/backend/onyx/server/settings/store.py @@ -47,6 +47,7 @@ def load_settings() -> Settings: settings.anonymous_user_enabled = anonymous_user_enabled settings.query_history_type = ONYX_QUERY_HISTORY_TYPE + return settings diff --git a/web/src/app/admin/settings/SettingsForm.tsx b/web/src/app/admin/settings/SettingsForm.tsx index 38b687797..0e32a0fc2 100644 --- a/web/src/app/admin/settings/SettingsForm.tsx +++ b/web/src/app/admin/settings/SettingsForm.tsx @@ -26,7 +26,7 @@ export function Checkbox({ onChange: (e: React.ChangeEvent) => void; }) { return ( -