Skip to content

Memos

初始化文件。

MemosReader #

Bases: BaseReader

备忘录阅读器。

从备忘录中读取内容。

Source code in llama_index/readers/memos/base.py
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
class MemosReader(BaseReader):
    """备忘录阅读器。

从备忘录中读取内容。"""

    def __init__(self, host: str = "https://demo.usememos.com/") -> None:
        """初始化参数。"""
        self._memoUrl = urljoin(host, "api/memo")

    def load_data(self, params: Dict = {}) -> List[Document]:
        """从RSS订阅源加载数据。

Args:
    params (Dict): 过滤参数。

Returns:
    List[Document]: 文档列表。
"""
        import requests

        documents = []
        realUrl = self._memoUrl

        if not params:
            realUrl = urljoin(self._memoUrl, "all", False)

        try:
            req = requests.get(realUrl, params)
            res = req.json()
        except ValueError:
            raise ValueError("Your Memo URL is not valid")

        if "data" not in res:
            raise ValueError("Invalid Memo response")

        memos = res["data"]
        for memo in memos:
            content = memo["content"]
            extra_info = {
                "creator": memo["creator"],
                "resource_list": memo["resourceList"],
                id: memo["id"],
            }
            documents.append(Document(text=content, extra_info=extra_info))

        return documents

load_data #

load_data(params: Dict = {}) -> List[Document]

从RSS订阅源加载数据。

Parameters:

Name Type Description Default
params Dict

过滤参数。

{}

Returns:

Type Description
List[Document]

List[Document]: 文档列表。

Source code in llama_index/readers/memos/base.py
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
    def load_data(self, params: Dict = {}) -> List[Document]:
        """从RSS订阅源加载数据。

Args:
    params (Dict): 过滤参数。

Returns:
    List[Document]: 文档列表。
"""
        import requests

        documents = []
        realUrl = self._memoUrl

        if not params:
            realUrl = urljoin(self._memoUrl, "all", False)

        try:
            req = requests.get(realUrl, params)
            res = req.json()
        except ValueError:
            raise ValueError("Your Memo URL is not valid")

        if "data" not in res:
            raise ValueError("Invalid Memo response")

        memos = res["data"]
        for memo in memos:
            content = memo["content"]
            extra_info = {
                "creator": memo["creator"],
                "resource_list": memo["resourceList"],
                id: memo["id"],
            }
            documents.append(Document(text=content, extra_info=extra_info))

        return documents