Coverage for src/qdrant_loader/core/file_conversion/conversion_config.py: 100%
19 statements
« prev ^ index » next coverage.py v7.10.6, created at 2025-09-08 06:05 +0000
« prev ^ index » next coverage.py v7.10.6, created at 2025-09-08 06:05 +0000
1"""Configuration models for file conversion settings."""
3from pydantic import BaseModel, Field
6class MarkItDownConfig(BaseModel):
7 """Configuration for MarkItDown-specific settings."""
9 enable_llm_descriptions: bool = Field(
10 default=False, description="Enable LLM integration for image descriptions"
11 )
13 llm_model: str = Field(
14 default="gpt-4o", description="LLM model for image descriptions (when enabled)"
15 )
17 llm_endpoint: str = Field(
18 default="https://api.openai.com/v1", description="LLM endpoint (when enabled)"
19 )
21 llm_api_key: str | None = Field(
22 default=None,
23 description="API key for LLM service (required when enable_llm_descriptions is True)",
24 )
27class FileConversionConfig(BaseModel):
28 """Configuration for file conversion operations."""
30 max_file_size: int = Field(
31 default=52428800, # 50MB
32 description="Maximum file size for conversion (in bytes)",
33 gt=0,
34 le=104857600, # 100MB
35 )
37 conversion_timeout: int = Field(
38 default=300, # 5 minutes
39 description="Timeout for conversion operations (in seconds)",
40 gt=0,
41 le=3600, # 1 hour
42 )
44 markitdown: MarkItDownConfig = Field(
45 default_factory=MarkItDownConfig, description="MarkItDown specific settings"
46 )
48 def get_max_file_size_mb(self) -> float:
49 """Get maximum file size in megabytes.
51 Returns:
52 Maximum file size in MB
53 """
54 return self.max_file_size / (1024 * 1024)
56 def is_file_size_allowed(self, file_size: int) -> bool:
57 """Check if file size is within allowed limits.
59 Args:
60 file_size: File size in bytes
62 Returns:
63 True if file size is allowed, False otherwise
64 """
65 return file_size <= self.max_file_size
68class ConnectorFileConversionConfig(BaseModel):
69 """Configuration for file conversion at the connector level."""
71 enable_file_conversion: bool = Field(
72 default=False, description="Enable file conversion for this connector"
73 )
75 download_attachments: bool | None = Field(
76 default=None,
77 description="Download and process attachments (for Confluence/JIRA/PublicDocs)",
78 )
80 def should_download_attachments(self) -> bool:
81 """Check if attachments should be downloaded.
83 Returns:
84 True if attachments should be downloaded, False otherwise
85 """
86 # Default to False if not specified
87 return self.download_attachments is True