Coverage for src / platform_adapter / base_adapter.py: 91%

23 statements  

« prev     ^ index     » next       coverage.py v7.13.4, created at 2026-02-13 20:29 +0800

1# Base Adapter 

2from __future__ import annotations 

3 

4from abc import ABC, abstractmethod 

5from dataclasses import dataclass 

6from typing import Any 

7 

8 

9@dataclass 

10class PlatformContent: 

11 title: str | None 

12 body: str 

13 metadata: dict[str, Any] 

14 

15 

16class BaseAdapter(ABC): 

17 def __init__(self, config: dict[str, Any] | None = None): 

18 self.config = config or {} 

19 

20 @abstractmethod 

21 def get_max_length(self) -> int: 

22 pass 

23 

24 @abstractmethod 

25 def format_content(self, content: str, **kwargs: Any) -> PlatformContent: 

26 pass 

27 

28 def truncate_content(self, content: str, max_length: int | None = None) -> str: 

29 max_len = max_length or self.get_max_length() 

30 if len(content) <= max_len: 

31 return content 

32 return content[: max_len - 3] + "..."