mirror of
https://github.com/danswer-ai/danswer.git
synced 2025-09-28 12:58:41 +02:00
Workspace configs (#4202)
This commit is contained in:
@@ -642,14 +642,4 @@ MOCK_LLM_RESPONSE = (
|
|||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
# Image processing configurations
|
DEFAULT_IMAGE_ANALYSIS_MAX_SIZE_MB = 20
|
||||||
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"))
|
|
||||||
|
38
backend/onyx/configs/llm_configs.py
Normal file
38
backend/onyx/configs/llm_configs.py
Normal file
@@ -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() -> bool:
|
||||||
|
"""Get image extraction and analysis enabled setting from workspace settings or fallback to False"""
|
||||||
|
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() -> bool:
|
||||||
|
"""Get search time image analysis enabled setting from workspace settings or fallback to False"""
|
||||||
|
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() -> int:
|
||||||
|
"""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
|
@@ -1,7 +1,7 @@
|
|||||||
"""
|
"""
|
||||||
Mixin for connectors that need vision capabilities.
|
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.factory import get_default_llm_with_vision
|
||||||
from onyx.llm.interfaces import LLM
|
from onyx.llm.interfaces import LLM
|
||||||
from onyx.utils.logger import setup_logger
|
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.
|
Sets self.image_analysis_llm to the LLM instance or None if disabled.
|
||||||
"""
|
"""
|
||||||
self.image_analysis_llm: LLM | None = None
|
self.image_analysis_llm: LLM | None = None
|
||||||
if ENABLE_INDEXING_TIME_IMAGE_ANALYSIS:
|
if get_image_extraction_and_analysis_enabled():
|
||||||
try:
|
try:
|
||||||
self.image_analysis_llm = get_default_llm_with_vision()
|
self.image_analysis_llm = get_default_llm_with_vision()
|
||||||
if self.image_analysis_llm is None:
|
if self.image_analysis_llm is None:
|
||||||
|
@@ -10,8 +10,8 @@ from langchain_core.messages import SystemMessage
|
|||||||
|
|
||||||
from onyx.chat.models import SectionRelevancePiece
|
from onyx.chat.models import SectionRelevancePiece
|
||||||
from onyx.configs.app_configs import BLURB_SIZE
|
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.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_MAX
|
||||||
from onyx.configs.model_configs import CROSS_ENCODER_RANGE_MIN
|
from onyx.configs.model_configs import CROSS_ENCODER_RANGE_MIN
|
||||||
from onyx.context.search.enums import LLMEvaluationType
|
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
|
# NOTE: if we don't rerank, we can return the chunks immediately
|
||||||
# since we know this is the final order.
|
# since we know this is the final order.
|
||||||
# This way the user experience isn't delayed by the LLM step
|
# 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(
|
update_image_sections_with_query(
|
||||||
retrieved_sections, search_query.query, llm
|
retrieved_sections, search_query.query, llm
|
||||||
)
|
)
|
||||||
@@ -456,7 +456,7 @@ def search_postprocessing(
|
|||||||
_log_top_section_links(search_query.search_type.value, reranked_sections)
|
_log_top_section_links(search_query.search_type.value, reranked_sections)
|
||||||
|
|
||||||
# Add the image processing step here
|
# Add the image processing step here
|
||||||
if ENABLE_SEARCH_TIME_IMAGE_ANALYSIS:
|
if get_search_time_image_analysis_enabled():
|
||||||
update_image_sections_with_query(
|
update_image_sections_with_query(
|
||||||
reranked_sections, search_query.query, llm
|
reranked_sections, search_query.query, llm
|
||||||
)
|
)
|
||||||
|
@@ -53,6 +53,11 @@ class Settings(BaseModel):
|
|||||||
auto_scroll: bool | None = False
|
auto_scroll: bool | None = False
|
||||||
query_history_type: QueryHistoryType | None = None
|
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):
|
class UserSettings(Settings):
|
||||||
notifications: list[Notification]
|
notifications: list[Notification]
|
||||||
|
@@ -47,6 +47,7 @@ def load_settings() -> Settings:
|
|||||||
|
|
||||||
settings.anonymous_user_enabled = anonymous_user_enabled
|
settings.anonymous_user_enabled = anonymous_user_enabled
|
||||||
settings.query_history_type = ONYX_QUERY_HISTORY_TYPE
|
settings.query_history_type = ONYX_QUERY_HISTORY_TYPE
|
||||||
|
|
||||||
return settings
|
return settings
|
||||||
|
|
||||||
|
|
||||||
|
@@ -26,7 +26,7 @@ export function Checkbox({
|
|||||||
onChange: (e: React.ChangeEvent<HTMLInputElement>) => void;
|
onChange: (e: React.ChangeEvent<HTMLInputElement>) => void;
|
||||||
}) {
|
}) {
|
||||||
return (
|
return (
|
||||||
<label className="flex text-sm cursor-pointer">
|
<label className="flex text-xs cursor-pointer">
|
||||||
<input
|
<input
|
||||||
checked={checked}
|
checked={checked}
|
||||||
onChange={onChange}
|
onChange={onChange}
|
||||||
@@ -34,7 +34,7 @@ export function Checkbox({
|
|||||||
className="mr-2 w-3.5 h-3.5 my-auto"
|
className="mr-2 w-3.5 h-3.5 my-auto"
|
||||||
/>
|
/>
|
||||||
<div>
|
<div>
|
||||||
<Label>{label}</Label>
|
<Label small>{label}</Label>
|
||||||
{sublabel && <SubLabel>{sublabel}</SubLabel>}
|
{sublabel && <SubLabel>{sublabel}</SubLabel>}
|
||||||
</div>
|
</div>
|
||||||
</label>
|
</label>
|
||||||
@@ -208,7 +208,7 @@ export function SettingsForm() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div>
|
<div className="flex flex-col pb-8">
|
||||||
{popup}
|
{popup}
|
||||||
<Title className="mb-4">Workspace Settings</Title>
|
<Title className="mb-4">Workspace Settings</Title>
|
||||||
<Checkbox
|
<Checkbox
|
||||||
@@ -307,6 +307,51 @@ export function SettingsForm() {
|
|||||||
</Button>
|
</Button>
|
||||||
</>
|
</>
|
||||||
)}
|
)}
|
||||||
|
|
||||||
|
{/* Image Processing Settings */}
|
||||||
|
<Title className="mt-8 mb-4">Image Processing</Title>
|
||||||
|
|
||||||
|
<div className="flex flex-col gap-2">
|
||||||
|
<Checkbox
|
||||||
|
label="Enable Image Extraction and Analysis"
|
||||||
|
sublabel="Extract and analyze images from documents during indexing. This allows the system to process images and create searchable descriptions of them."
|
||||||
|
checked={settings.image_extraction_and_analysis_enabled ?? false}
|
||||||
|
onChange={(e) =>
|
||||||
|
handleToggleSettingsField(
|
||||||
|
"image_extraction_and_analysis_enabled",
|
||||||
|
e.target.checked
|
||||||
|
)
|
||||||
|
}
|
||||||
|
/>
|
||||||
|
|
||||||
|
<Checkbox
|
||||||
|
label="Enable Search-time Image Analysis"
|
||||||
|
sublabel="Analyze images at search time when a user asks about images. This provides more detailed and query-specific image analysis but may increase search-time latency."
|
||||||
|
checked={settings.search_time_image_analysis_enabled ?? false}
|
||||||
|
onChange={(e) =>
|
||||||
|
handleToggleSettingsField(
|
||||||
|
"search_time_image_analysis_enabled",
|
||||||
|
e.target.checked
|
||||||
|
)
|
||||||
|
}
|
||||||
|
/>
|
||||||
|
|
||||||
|
<IntegerInput
|
||||||
|
label="Maximum Image Size for Analysis (MB)"
|
||||||
|
sublabel="Images larger than this size will not be analyzed to prevent excessive resource usage."
|
||||||
|
value={settings.image_analysis_max_size_mb ?? null}
|
||||||
|
onChange={(e) => {
|
||||||
|
const value = e.target.value ? parseInt(e.target.value) : null;
|
||||||
|
if (value !== null && !isNaN(value) && value > 0) {
|
||||||
|
updateSettingField([
|
||||||
|
{ fieldName: "image_analysis_max_size_mb", newValue: value },
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
}}
|
||||||
|
id="image-analysis-max-size"
|
||||||
|
placeholder="Enter maximum size in MB"
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@@ -21,6 +21,11 @@ export interface Settings {
|
|||||||
auto_scroll: boolean;
|
auto_scroll: boolean;
|
||||||
temperature_override_enabled: boolean;
|
temperature_override_enabled: boolean;
|
||||||
query_history_type: QueryHistoryType;
|
query_history_type: QueryHistoryType;
|
||||||
|
|
||||||
|
// Image processing settings
|
||||||
|
image_extraction_and_analysis_enabled?: boolean;
|
||||||
|
search_time_image_analysis_enabled?: boolean;
|
||||||
|
image_analysis_max_size_mb?: number;
|
||||||
}
|
}
|
||||||
|
|
||||||
export enum NotificationType {
|
export enum NotificationType {
|
||||||
|
Reference in New Issue
Block a user