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

20 statements  

« prev     ^ index     » next       coverage.py v7.8.2, created at 2025-06-04 05:50 +0000

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

2 

3from typing import Optional 

4 

5from pydantic import BaseModel, Field 

6 

7 

8class MarkItDownConfig(BaseModel): 

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

10 

11 enable_llm_descriptions: bool = Field( 

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

13 ) 

14 

15 llm_model: str = Field( 

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

17 ) 

18 

19 llm_endpoint: str = Field( 

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

21 ) 

22 

23 llm_api_key: Optional[str] = Field( 

24 default=None, 

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

26 ) 

27 

28 

29class FileConversionConfig(BaseModel): 

30 """Configuration for file conversion operations.""" 

31 

32 max_file_size: int = Field( 

33 default=52428800, # 50MB 

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

35 gt=0, 

36 ) 

37 

38 conversion_timeout: int = Field( 

39 default=300, # 5 minutes 

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

41 gt=0, 

42 ) 

43 

44 markitdown: MarkItDownConfig = Field( 

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

46 ) 

47 

48 def get_max_file_size_mb(self) -> float: 

49 """Get maximum file size in megabytes. 

50 

51 Returns: 

52 Maximum file size in MB 

53 """ 

54 return self.max_file_size / (1024 * 1024) 

55 

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

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

58 

59 Args: 

60 file_size: File size in bytes 

61 

62 Returns: 

63 True if file size is allowed, False otherwise 

64 """ 

65 return file_size <= self.max_file_size 

66 

67 

68class ConnectorFileConversionConfig(BaseModel): 

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

70 

71 enable_file_conversion: bool = Field( 

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

73 ) 

74 

75 download_attachments: Optional[bool] = Field( 

76 default=None, 

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

78 ) 

79 

80 def should_download_attachments(self) -> bool: 

81 """Check if attachments should be downloaded. 

82 

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