Coverage for src/qdrant_loader_mcp_server/config.py: 100%

36 statements  

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

1"""Configuration settings for the RAG MCP Server.""" 

2 

3import os 

4 

5from dotenv import load_dotenv 

6from pydantic import BaseModel 

7 

8# Load environment variables from .env file 

9load_dotenv() 

10 

11 

12class ServerConfig(BaseModel): 

13 """Server configuration settings.""" 

14 

15 host: str = "0.0.0.0" 

16 port: int = 8000 

17 log_level: str = "INFO" 

18 

19 

20class QdrantConfig(BaseModel): 

21 """Qdrant configuration settings.""" 

22 

23 url: str = "http://localhost:6333" 

24 api_key: str | None = None 

25 collection_name: str = "documents" 

26 

27 def __init__(self, **data): 

28 """Initialize with environment variables if not provided.""" 

29 if "url" not in data: 

30 data["url"] = os.getenv("QDRANT_URL", "http://localhost:6333") 

31 if "api_key" not in data: 

32 data["api_key"] = os.getenv("QDRANT_API_KEY") 

33 if "collection_name" not in data: 

34 data["collection_name"] = os.getenv("QDRANT_COLLECTION_NAME", "documents") 

35 super().__init__(**data) 

36 

37 

38class OpenAIConfig(BaseModel): 

39 """OpenAI configuration settings.""" 

40 

41 api_key: str 

42 model: str = "text-embedding-3-small" 

43 chat_model: str = "gpt-3.5-turbo" 

44 

45 

46class Config(BaseModel): 

47 """Main configuration class.""" 

48 

49 server: ServerConfig 

50 qdrant: QdrantConfig 

51 openai: OpenAIConfig 

52 

53 def __init__(self, **data): 

54 """Initialize configuration with environment variables.""" 

55 # Initialize sub-configs if not provided 

56 if "server" not in data: 

57 data["server"] = ServerConfig() 

58 if "qdrant" not in data: 

59 data["qdrant"] = QdrantConfig() 

60 if "openai" not in data: 

61 data["openai"] = {"api_key": os.getenv("OPENAI_API_KEY")} 

62 super().__init__(**data)