File size: 1,977 Bytes
d60732b
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
"""
SCP - Viet Nam | Self-Correcting Pipeline
Copyright (c) 2026 SCP Vietnam Project. All Rights Reserved.




License: See LICENSE file
Contact: scp-vietnam@example.com
"""

"""
IDataSource Interface - Base interface cho tất cả data sources
"""
from abc import ABC, abstractmethod
from typing import Any, Optional


class IDataSource(ABC):
    """
    Interface chuẩn cho tất cả data sources.
    Mỗi lĩnh vực mới cần implement interface này.
    """

    @property
    @abstractmethod
    def name(self) -> str:
        """Tên của data source."""
        pass

    @property
    @abstractmethod
    def priority(self) -> int:
        """Độ ưu tiên (1 = cao nhất)."""
        pass

    @property
    @abstractmethod
    def ttl(self) -> int:
        """Cache TTL tính bằng giây."""
        pass

    @abstractmethod
    def get_supported_intents(self) -> list[str]:
        """Trả về danh sách intents mà source này hỗ trợ."""
        pass

    @abstractmethod
    def can_handle(self, intent: str, entity: Optional[str] = None) -> bool:
        """Kiểm tra xem source này có xử lý được intent không."""
        pass

    @abstractmethod
    def fetch(self, intent: str, entity: str, **kwargs) -> Optional[dict[str, Any]]:
        """
        Lấy dữ liệu thực để xác minh.

        Args:
            intent: Loại câu hỏi (ví dụ: 'molecular_weight', 'exchange_rate')
            entity: Thực thể cần tra cứu (ví dụ: 'water', 'USD/EUR')
            **kwargs: Các tham số bổ sung

        Returns:
            Dict với keys:
                - value: Giá trị thực
                - source: Tên nguồn dữ liệu
                - metadata: Thông tin bổ sung (optional)
            None nếu không tìm thấy
        """
        pass

    @abstractmethod
    def health_check(self) -> bool:
        """Kiểm tra xem data source có hoạt động không."""
        pass