Coverage for src/qdrant_loader/core/file_conversion/conversion_config.py: 100%

23 statements  

« prev     ^ index     » next       coverage.py v7.15.0, created at 2026-07-20 10:15 +0000

1"""Configuration models for file conversion settings.""" 

2 

3from pydantic import BaseModel, Field 

4 

5from qdrant_loader.core.conversion.engine import EngineKind 

6from qdrant_loader.core.conversion.settings import DoclingConversionSettings 

7 

8 

9class MarkItDownConfig(BaseModel): 

10 """Configuration for MarkItDown-specific settings.""" 

11 

12 enable_llm_descriptions: bool = Field( 

13 default=False, description="Enable LLM integration for image descriptions" 

14 ) 

15 

16 llm_model: str = Field( 

17 default="gpt-4o", description="LLM model for image descriptions (when enabled)" 

18 ) 

19 

20 llm_endpoint: str = Field( 

21 default="https://api.openai.com/v1", description="LLM endpoint (when enabled)" 

22 ) 

23 

24 llm_api_key: str | None = Field( 

25 default=None, 

26 description="API key for LLM service (required when enable_llm_descriptions is True)", 

27 ) 

28 

29 

30class FileConversionConfig(BaseModel): 

31 """Configuration for file conversion operations.""" 

32 

33 max_file_size: int = Field( 

34 default=52428800, # 50MB 

35 description="Maximum file size for conversion (in bytes)", 

36 gt=0, 

37 le=104857600, # 100MB 

38 ) 

39 

40 conversion_timeout: int = Field( 

41 default=300, # 5 minutes 

42 description="Timeout for conversion operations (in seconds)", 

43 gt=0, 

44 le=3600, # 1 hour 

45 ) 

46 

47 engine: EngineKind = Field( 

48 default=EngineKind.MARKITDOWN, 

49 description=( 

50 "Which conversion engine to use: 'markitdown' (legacy, markdown-string " 

51 "path) or 'docling' (structure-aware, full Option B). Config-driven, not a " 

52 "feature flag." 

53 ), 

54 ) 

55 

56 markitdown: MarkItDownConfig = Field( 

57 default_factory=MarkItDownConfig, description="MarkItDown specific settings" 

58 ) 

59 

60 docling: DoclingConversionSettings = Field( 

61 default_factory=DoclingConversionSettings, 

62 description="Docling engine settings (used when engine='docling')", 

63 ) 

64 

65 def get_max_file_size_mb(self) -> float: 

66 """Get maximum file size in megabytes. 

67 

68 Returns: 

69 Maximum file size in MB 

70 """ 

71 return self.max_file_size / (1024 * 1024) 

72 

73 def is_file_size_allowed(self, file_size: int) -> bool: 

74 """Check if file size is within allowed limits. 

75 

76 Args: 

77 file_size: File size in bytes 

78 

79 Returns: 

80 True if file size is allowed, False otherwise 

81 """ 

82 return file_size <= self.max_file_size 

83 

84 

85class ConnectorFileConversionConfig(BaseModel): 

86 """Configuration for file conversion at the connector level.""" 

87 

88 enable_file_conversion: bool = Field( 

89 default=False, description="Enable file conversion for this connector" 

90 ) 

91 

92 download_attachments: bool | None = Field( 

93 default=None, 

94 description="Download and process attachments (for Confluence/JIRA/PublicDocs)", 

95 ) 

96 

97 def should_download_attachments(self) -> bool: 

98 """Check if attachments should be downloaded. 

99 

100 Returns: 

101 True if attachments should be downloaded, False otherwise 

102 """ 

103 # Default to False if not specified 

104 return self.download_attachments is True