ragflow-cli-myfbee-test 0.27.2.dev0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,150 @@
1
+ Metadata-Version: 2.4
2
+ Name: ragflow-cli-myfbee-test
3
+ Version: 0.27.2.dev0
4
+ Summary: Admin Service's client of [RAGFlow](https://github.com/infiniflow/ragflow). The Admin Service provides user management and system monitoring.
5
+ Author-email: Lynn <lynn_inf@hotmail.com>
6
+ License: Apache License, Version 2.0
7
+ Requires-Python: <3.14,>=3.13
8
+ Description-Content-Type: text/markdown
9
+ Requires-Dist: requests<3.0.0,>=2.30.0
10
+ Requires-Dist: beartype<1.0.0,>=0.22.9
11
+ Requires-Dist: pycryptodomex>=3.10.0
12
+ Requires-Dist: lark>=1.1.0
13
+ Requires-Dist: requests-toolbelt>=1.0.0
14
+
15
+ # RAGFlow Admin Service & CLI
16
+
17
+ ### Introduction
18
+
19
+ Admin Service is a dedicated management component designed to monitor, maintain, and administrate the RAGFlow system. It provides comprehensive tools for ensuring system stability, performing operational tasks, and managing users and permissions efficiently.
20
+
21
+ The service offers real-time monitoring of critical components, including the RAGFlow server, Task Executor processes, and dependent services such as MySQL, Infinity, Elasticsearch, Redis, and MinIO. It automatically checks their health status, resource usage, and uptime, and performs restarts in case of failures to minimize downtime.
22
+
23
+ For user and system management, it supports listing, creating, modifying, and deleting users and their associated resources like knowledge bases and Agents.
24
+
25
+ Built with scalability and reliability in mind, the Admin Service ensures smooth system operation and simplifies maintenance workflows.
26
+
27
+ It consists of a server-side Service and a command-line client (CLI), both implemented in Python. User commands are parsed using the Lark parsing toolkit.
28
+
29
+ - **Admin Service**: A backend service that interfaces with the RAGFlow system to execute administrative operations and monitor its status.
30
+ - **Admin CLI**: A command-line interface that allows users to connect to the Admin Service and issue commands for system management.
31
+
32
+
33
+
34
+ ### Starting the Admin Service
35
+
36
+ #### Launching from source code
37
+
38
+ 1. Before start Admin Service, please make sure RAGFlow system is already started.
39
+
40
+ 2. Launch from source code:
41
+
42
+ ```bash
43
+ python admin/server/admin_server.py
44
+ ```
45
+ The service will start and listen for incoming connections from the CLI on the configured port.
46
+
47
+ #### Using docker image
48
+
49
+ 1. Before startup, please configure the `docker_compose.yml` file to enable admin server:
50
+
51
+ ```bash
52
+ command:
53
+ - --enable-adminserver
54
+ ```
55
+
56
+ 2. Start the containers, the service will start and listen for incoming connections from the CLI on the configured port.
57
+
58
+
59
+
60
+ ### Using the Admin CLI
61
+
62
+ 1. Ensure the Admin Service is running.
63
+ 2. Install ragflow-cli.
64
+ ```bash
65
+ pip install ragflow-cli==0.27.2
66
+ ```
67
+ 3. Launch the CLI client:
68
+ ```bash
69
+ ragflow-cli -h 127.0.0.1 -p 9381
70
+ ```
71
+ You will be prompted to enter the superuser's password to log in.
72
+ The default password is admin.
73
+
74
+ **Parameters:**
75
+
76
+ - -h: RAGFlow admin server host address
77
+
78
+ - -p: RAGFlow admin server port
79
+
80
+
81
+
82
+ ## Supported Commands
83
+
84
+ Commands are case-insensitive and must be terminated with a semicolon (`;`).
85
+
86
+ ### Service Management Commands
87
+
88
+ - `LIST SERVICES;`
89
+ - Lists all available services within the RAGFlow system.
90
+ - `SHOW SERVICE <id>;`
91
+ - Shows detailed status information for the service identified by `<id>`.
92
+
93
+
94
+ ### User Management Commands
95
+
96
+ - `LIST USERS;`
97
+ - Lists all users known to the system.
98
+ - `SHOW USER '<username>';`
99
+ - Shows details and permissions for the specified user. The username must be enclosed in single or double quotes.
100
+
101
+ - `CREATE USER <username> <password>;`
102
+ - Create user by username and password. The username and password must be enclosed in single or double quotes.
103
+
104
+ - `DROP USER '<username>';`
105
+ - Removes the specified user from the system. Use with caution.
106
+ - `ALTER USER PASSWORD '<username>' '<new_password>';`
107
+ - Changes the password for the specified user.
108
+ - `ALTER USER ACTIVE <username> <on/off>;`
109
+ - Changes the user to active or inactive.
110
+
111
+
112
+ ### Data and Agent Commands
113
+
114
+ - `LIST DATASETS OF '<username>';`
115
+ - Lists the datasets associated with the specified user.
116
+ - `LIST AGENTS OF '<username>';`
117
+ - Lists the agents associated with the specified user.
118
+
119
+ ### Meta-Commands
120
+
121
+ Meta-commands are prefixed with a backslash (`\`).
122
+
123
+ - `\?` or `\help`
124
+ - Shows help information for the available commands.
125
+ - `\q` or `\quit`
126
+ - Exits the CLI application.
127
+
128
+ ## Examples
129
+
130
+ ```commandline
131
+ admin> list users;
132
+ +-------------------------------+------------------------+-----------+-------------+
133
+ | create_date | email | is_active | nickname |
134
+ +-------------------------------+------------------------+-----------+-------------+
135
+ | Fri, 22 Nov 2024 16:03:41 GMT | jeffery@infiniflow.org | 1 | Jeffery |
136
+ | Fri, 22 Nov 2024 16:10:55 GMT | aya@infiniflow.org | 1 | Waterdancer |
137
+ +-------------------------------+------------------------+-----------+-------------+
138
+
139
+ admin> list services;
140
+ +-------------------------------------------------------------------------------------------+-----------+----+---------------+-------+----------------+
141
+ | extra | host | id | name | port | service_type |
142
+ +-------------------------------------------------------------------------------------------+-----------+----+---------------+-------+----------------+
143
+ | {} | 0.0.0.0 | 0 | ragflow_0 | 9380 | ragflow_server |
144
+ | {'meta_type': 'mysql', 'password': 'infini_rag_flow', 'username': 'root'} | localhost | 1 | mysql | 5455 | meta_data |
145
+ | {'password': 'infini_rag_flow', 'store_type': 'minio', 'user': 'rag_flow'} | localhost | 2 | minio | 9000 | file_store |
146
+ | {'password': 'infini_rag_flow', 'retrieval_type': 'elasticsearch', 'username': 'elastic'} | localhost | 3 | elasticsearch | 1200 | retrieval |
147
+ | {'db_name': 'default_db', 'retrieval_type': 'infinity'} | localhost | 4 | infinity | 23817 | retrieval |
148
+ | {'database': 1, 'mq_type': 'redis', 'password': 'infini_rag_flow'} | localhost | 5 | redis | 6379 | message_queue |
149
+ +-------------------------------------------------------------------------------------------+-----------+----+---------------+-------+----------------+
150
+ ```
@@ -0,0 +1,136 @@
1
+ # RAGFlow Admin Service & CLI
2
+
3
+ ### Introduction
4
+
5
+ Admin Service is a dedicated management component designed to monitor, maintain, and administrate the RAGFlow system. It provides comprehensive tools for ensuring system stability, performing operational tasks, and managing users and permissions efficiently.
6
+
7
+ The service offers real-time monitoring of critical components, including the RAGFlow server, Task Executor processes, and dependent services such as MySQL, Infinity, Elasticsearch, Redis, and MinIO. It automatically checks their health status, resource usage, and uptime, and performs restarts in case of failures to minimize downtime.
8
+
9
+ For user and system management, it supports listing, creating, modifying, and deleting users and their associated resources like knowledge bases and Agents.
10
+
11
+ Built with scalability and reliability in mind, the Admin Service ensures smooth system operation and simplifies maintenance workflows.
12
+
13
+ It consists of a server-side Service and a command-line client (CLI), both implemented in Python. User commands are parsed using the Lark parsing toolkit.
14
+
15
+ - **Admin Service**: A backend service that interfaces with the RAGFlow system to execute administrative operations and monitor its status.
16
+ - **Admin CLI**: A command-line interface that allows users to connect to the Admin Service and issue commands for system management.
17
+
18
+
19
+
20
+ ### Starting the Admin Service
21
+
22
+ #### Launching from source code
23
+
24
+ 1. Before start Admin Service, please make sure RAGFlow system is already started.
25
+
26
+ 2. Launch from source code:
27
+
28
+ ```bash
29
+ python admin/server/admin_server.py
30
+ ```
31
+ The service will start and listen for incoming connections from the CLI on the configured port.
32
+
33
+ #### Using docker image
34
+
35
+ 1. Before startup, please configure the `docker_compose.yml` file to enable admin server:
36
+
37
+ ```bash
38
+ command:
39
+ - --enable-adminserver
40
+ ```
41
+
42
+ 2. Start the containers, the service will start and listen for incoming connections from the CLI on the configured port.
43
+
44
+
45
+
46
+ ### Using the Admin CLI
47
+
48
+ 1. Ensure the Admin Service is running.
49
+ 2. Install ragflow-cli.
50
+ ```bash
51
+ pip install ragflow-cli==0.27.2
52
+ ```
53
+ 3. Launch the CLI client:
54
+ ```bash
55
+ ragflow-cli -h 127.0.0.1 -p 9381
56
+ ```
57
+ You will be prompted to enter the superuser's password to log in.
58
+ The default password is admin.
59
+
60
+ **Parameters:**
61
+
62
+ - -h: RAGFlow admin server host address
63
+
64
+ - -p: RAGFlow admin server port
65
+
66
+
67
+
68
+ ## Supported Commands
69
+
70
+ Commands are case-insensitive and must be terminated with a semicolon (`;`).
71
+
72
+ ### Service Management Commands
73
+
74
+ - `LIST SERVICES;`
75
+ - Lists all available services within the RAGFlow system.
76
+ - `SHOW SERVICE <id>;`
77
+ - Shows detailed status information for the service identified by `<id>`.
78
+
79
+
80
+ ### User Management Commands
81
+
82
+ - `LIST USERS;`
83
+ - Lists all users known to the system.
84
+ - `SHOW USER '<username>';`
85
+ - Shows details and permissions for the specified user. The username must be enclosed in single or double quotes.
86
+
87
+ - `CREATE USER <username> <password>;`
88
+ - Create user by username and password. The username and password must be enclosed in single or double quotes.
89
+
90
+ - `DROP USER '<username>';`
91
+ - Removes the specified user from the system. Use with caution.
92
+ - `ALTER USER PASSWORD '<username>' '<new_password>';`
93
+ - Changes the password for the specified user.
94
+ - `ALTER USER ACTIVE <username> <on/off>;`
95
+ - Changes the user to active or inactive.
96
+
97
+
98
+ ### Data and Agent Commands
99
+
100
+ - `LIST DATASETS OF '<username>';`
101
+ - Lists the datasets associated with the specified user.
102
+ - `LIST AGENTS OF '<username>';`
103
+ - Lists the agents associated with the specified user.
104
+
105
+ ### Meta-Commands
106
+
107
+ Meta-commands are prefixed with a backslash (`\`).
108
+
109
+ - `\?` or `\help`
110
+ - Shows help information for the available commands.
111
+ - `\q` or `\quit`
112
+ - Exits the CLI application.
113
+
114
+ ## Examples
115
+
116
+ ```commandline
117
+ admin> list users;
118
+ +-------------------------------+------------------------+-----------+-------------+
119
+ | create_date | email | is_active | nickname |
120
+ +-------------------------------+------------------------+-----------+-------------+
121
+ | Fri, 22 Nov 2024 16:03:41 GMT | jeffery@infiniflow.org | 1 | Jeffery |
122
+ | Fri, 22 Nov 2024 16:10:55 GMT | aya@infiniflow.org | 1 | Waterdancer |
123
+ +-------------------------------+------------------------+-----------+-------------+
124
+
125
+ admin> list services;
126
+ +-------------------------------------------------------------------------------------------+-----------+----+---------------+-------+----------------+
127
+ | extra | host | id | name | port | service_type |
128
+ +-------------------------------------------------------------------------------------------+-----------+----+---------------+-------+----------------+
129
+ | {} | 0.0.0.0 | 0 | ragflow_0 | 9380 | ragflow_server |
130
+ | {'meta_type': 'mysql', 'password': 'infini_rag_flow', 'username': 'root'} | localhost | 1 | mysql | 5455 | meta_data |
131
+ | {'password': 'infini_rag_flow', 'store_type': 'minio', 'user': 'rag_flow'} | localhost | 2 | minio | 9000 | file_store |
132
+ | {'password': 'infini_rag_flow', 'retrieval_type': 'elasticsearch', 'username': 'elastic'} | localhost | 3 | elasticsearch | 1200 | retrieval |
133
+ | {'db_name': 'default_db', 'retrieval_type': 'infinity'} | localhost | 4 | infinity | 23817 | retrieval |
134
+ | {'database': 1, 'mq_type': 'redis', 'password': 'infini_rag_flow'} | localhost | 5 | redis | 6379 | message_queue |
135
+ +-------------------------------------------------------------------------------------------+-----------+----+---------------+-------+----------------+
136
+ ```
@@ -0,0 +1,182 @@
1
+ #
2
+ # Copyright 2026 The InfiniFlow Authors. All Rights Reserved.
3
+ #
4
+ # Licensed under the Apache License, Version 2.0 (the "License");
5
+ # you may not use this file except in compliance with the License.
6
+ # You may obtain a copy of the License at
7
+ #
8
+ # http://www.apache.org/licenses/LICENSE-2.0
9
+ #
10
+ # Unless required by applicable law or agreed to in writing, software
11
+ # distributed under the License is distributed on an "AS IS" BASIS,
12
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ # See the License for the specific language governing permissions and
14
+ # limitations under the License.
15
+ #
16
+
17
+ import time
18
+ import json
19
+ import typing
20
+ from typing import Any, Dict, Optional
21
+
22
+ import requests
23
+ # from requests.sessions import HTTPAdapter
24
+
25
+
26
+ class HttpClient:
27
+ def __init__(
28
+ self,
29
+ host: str = "127.0.0.1",
30
+ port: int = 9381,
31
+ api_version: str = "v1",
32
+ api_key: Optional[str] = None,
33
+ connect_timeout: float = 5.0,
34
+ read_timeout: float = 60.0,
35
+ verify_ssl: bool = False,
36
+ ) -> None:
37
+ self.host = host
38
+ self.port = port
39
+ self.api_version = api_version
40
+ self.api_key = api_key
41
+ self.login_token: str | None = None
42
+ self.connect_timeout = connect_timeout
43
+ self.read_timeout = read_timeout
44
+ self.verify_ssl = verify_ssl
45
+
46
+ def api_base(self) -> str:
47
+ return f"{self.host}:{self.port}/api/{self.api_version}"
48
+
49
+ def non_api_base(self) -> str:
50
+ return f"{self.host}:{self.port}/{self.api_version}"
51
+
52
+ def build_url(self, path: str, use_api_base: bool = True) -> str:
53
+ base = self.api_base() if use_api_base else self.non_api_base()
54
+ if self.verify_ssl:
55
+ return f"https://{base}/{path.lstrip('/')}"
56
+ else:
57
+ return f"http://{base}/{path.lstrip('/')}"
58
+
59
+ def _headers(self, auth_kind: Optional[str], extra: Optional[Dict[str, str]]) -> Dict[str, str]:
60
+ headers = {}
61
+ if auth_kind == "api" and self.api_key:
62
+ headers["Authorization"] = f"Bearer {self.api_key}"
63
+ elif auth_kind == "web" and self.login_token:
64
+ headers["Authorization"] = self.login_token
65
+ elif auth_kind == "admin" and self.login_token:
66
+ headers["Authorization"] = self.login_token
67
+ else:
68
+ pass
69
+ if extra:
70
+ headers.update(extra)
71
+ return headers
72
+
73
+ def request(
74
+ self,
75
+ method: str,
76
+ path: str,
77
+ *,
78
+ use_api_base: bool = True,
79
+ auth_kind: Optional[str] = "api",
80
+ headers: Optional[Dict[str, str]] = None,
81
+ json_body: Optional[Dict[str, Any]] = None,
82
+ data: Any = None,
83
+ files: Any = None,
84
+ params: Optional[Dict[str, Any]] = None,
85
+ stream: bool = False,
86
+ iterations: int = 1,
87
+ ) -> requests.Response | dict:
88
+ url = self.build_url(path, use_api_base=use_api_base)
89
+ merged_headers = self._headers(auth_kind, headers)
90
+ # timeout: Tuple[float, float] = (self.connect_timeout, self.read_timeout)
91
+ session = requests.Session()
92
+ # adapter = HTTPAdapter(pool_connections=100, pool_maxsize=100)
93
+ # session.mount("http://", adapter)
94
+ http_function = typing.Any
95
+ match method:
96
+ case "GET":
97
+ http_function = session.get
98
+ case "POST":
99
+ http_function = session.post
100
+ case "PUT":
101
+ http_function = session.put
102
+ case "DELETE":
103
+ http_function = session.delete
104
+ case "PATCH":
105
+ http_function = session.patch
106
+ case _:
107
+ raise ValueError(f"Invalid HTTP method: {method}")
108
+
109
+ if iterations > 1:
110
+ response_list = []
111
+ total_duration = 0.0
112
+ for _ in range(iterations):
113
+ start_time = time.perf_counter()
114
+ response = http_function(url, headers=merged_headers, json=json_body, data=data, stream=stream)
115
+ # response = session.get(url, headers=merged_headers, json=json_body, data=data, stream=stream)
116
+ # response = requests.request(
117
+ # method=method,
118
+ # url=url,
119
+ # headers=merged_headers,
120
+ # json=json_body,
121
+ # data=data,
122
+ # files=files,
123
+ # params=params,
124
+ # stream=stream,
125
+ # verify=self.verify_ssl,
126
+ # )
127
+ end_time = time.perf_counter()
128
+ total_duration += end_time - start_time
129
+ response_list.append(response)
130
+ return {"duration": total_duration, "response_list": response_list}
131
+ else:
132
+ return http_function(url, headers=merged_headers, json=json_body, data=data, stream=stream)
133
+ # return session.get(url, headers=merged_headers, json=json_body, data=data, stream=stream)
134
+ # return requests.request(
135
+ # method=method,
136
+ # url=url,
137
+ # headers=merged_headers,
138
+ # json=json_body,
139
+ # data=data,
140
+ # files=files,
141
+ # params=params,
142
+ # stream=stream,
143
+ # verify=self.verify_ssl,
144
+ # )
145
+
146
+ def request_json(
147
+ self,
148
+ method: str,
149
+ path: str,
150
+ *,
151
+ use_api_base: bool = True,
152
+ auth_kind: Optional[str] = "api",
153
+ headers: Optional[Dict[str, str]] = None,
154
+ json_body: Optional[Dict[str, Any]] = None,
155
+ data: Any = None,
156
+ files: Any = None,
157
+ params: Optional[Dict[str, Any]] = None,
158
+ stream: bool = False,
159
+ ) -> Dict[str, Any]:
160
+ response = self.request(
161
+ method,
162
+ path,
163
+ use_api_base=use_api_base,
164
+ auth_kind=auth_kind,
165
+ headers=headers,
166
+ json_body=json_body,
167
+ data=data,
168
+ files=files,
169
+ params=params,
170
+ stream=stream,
171
+ )
172
+ try:
173
+ return response.json()
174
+ except Exception as exc:
175
+ raise ValueError(f"Non-JSON response from {path}: {exc}") from exc
176
+
177
+ @staticmethod
178
+ def parse_json_bytes(raw: bytes) -> Dict[str, Any]:
179
+ try:
180
+ return json.loads(raw.decode("utf-8"))
181
+ except Exception as exc:
182
+ raise ValueError(f"Invalid JSON payload: {exc}") from exc