RAGFlow is an agent-native database: a Retrieval-Augmented Generation (RAG) engine that grew into context infrastructure.
Go agent-harnessagent-native-databaseagentic-aiagentic-retrievalagentic-searchaiai-agentscontext-enginecontext-engineeringcontext-managementharness-engineeringknowledge-compilationragretrieval-augmented-generationretrieval-harnesssearch-harness
Refactor: migrate the function to specific file (#10201)
Jin Hai62b7c655c511
diff --git a/admin/admin_client.py b/admin/admin_client.pyindex 9c63c07ca4..e0c29fb7f3 100644--- a/admin/admin_client.py+++ b/admin/admin_client.py@@ -1,11 +1,13 @@import argparseimport base64+from Cryptodome.PublicKey import RSAfrom Cryptodome.Cipher import PKCS1_v1_5 as Cipher_pkcs1_v1_5from typing import Dict, List, Anyfrom lark import Lark, Transformer, Treeimport requestsfrom requests.auth import HTTPBasicAuth+from api.common.base64 import encode_to_base64GRAMMAR = r"""start: command@@ -166,11 +168,6 @@ class AdminTransformer(Transformer):return items-def encode_to_base64(input_string):- base64_encoded = base64.b64encode(input_string.encode('utf-8'))- return base64_encoded.decode('utf-8')--def encrypt(input_string):pub = '-----BEGIN PUBLIC KEY-----\nMIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEArq9XTUSeYr2+N1h3Afl/z8Dse/2yD0ZGrKwx+EEEcdsBLca9Ynmx3nIB5obmLlSfmskLpBo0UACBmB5rEjBp2Q2f3AG3Hjd4B+gNCG6BDaawuDlgANIhGnaTLrIqWrrcm4EMzJOnAOI1fgzJRsOOUEfaS318Eq9OVO3apEyCCt0lOQK6PuksduOjVxtltDav+guVAA068NrPYmRNabVKRNLJpL8w4D44sfth5RvZ3q9t+6RTArpEtc5sh5ChzvqPOzKGMXW83C95TxmXqpbK6olN4RevSfVjEAgCydH6HN6OhtOQEcnrU97r9H0iZOWwbw3pVrZiUkuRD1R56Wzs2wIDAQAB\n-----END PUBLIC KEY-----'pub_key = RSA.importKey(pub)@@ -440,7 +437,8 @@ class AdminCLI:password: str = password_tree.children[0].strip("'\"")print(f"Alter user: {username}, password: {password}")url = f'http://{self.host}:{self.port}/api/v1/admin/users/{username}/password'- response = requests.put(url, auth=HTTPBasicAuth(self.admin_account, self.admin_password), json={'new_password': encrypt(password)})+ response = requests.put(url, auth=HTTPBasicAuth(self.admin_account, self.admin_password),+ json={'new_password': encrypt(password)})res_json = response.json()if response.status_code == 200:print(res_json["message"])@@ -474,7 +472,8 @@ class AdminCLI:if activate_status.lower() in ['on', 'off']:print(f"Alter user {username} activate status, turn {activate_status.lower()}.")url = f'http://{self.host}:{self.port}/api/v1/admin/users/{username}/activate'- response = requests.put(url, auth=HTTPBasicAuth(self.admin_account, self.admin_password), json={'activate_status': activate_status})+ response = requests.put(url, auth=HTTPBasicAuth(self.admin_account, self.admin_password),+ json={'activate_status': activate_status})res_json = response.json()if response.status_code == 200:print(res_json["message"])diff --git a/admin/config.py b/admin/config.pyindex c09ef63920..5708077372 100644--- a/admin/config.py+++ b/admin/config.py@@ -4,7 +4,7 @@ from enum import Enumfrom pydantic import BaseModelfrom typing import Any-from api.utils import read_config+from api.utils.configs import read_configfrom urllib.parse import urlparsediff --git a/api/common/README.md b/api/common/README.mdnew file mode 100644index 0000000000..02f6302169--- /dev/null+++ b/api/common/README.md@@ -0,0 +1,2 @@+The python files in this directory are shared between service. They contain common utilities, models, and functions that can be used across various+services to ensure consistency and reduce code duplication.\ No newline at end of filediff --git a/api/common/base64.py b/api/common/base64.pynew file mode 100644index 0000000000..2b37dd2819--- /dev/null+++ b/api/common/base64.py@@ -0,0 +1,21 @@+#+# Copyright 2025 The InfiniFlow Authors. All Rights Reserved.+#+# Licensed under the Apache License, Version 2.0 (the "License");+# you may not use this file except in compliance with the License.+# You may obtain a copy of the License at+#+# http://www.apache.org/licenses/LICENSE-2.0+#+# Unless required by applicable law or agreed to in writing, software+# distributed under the License is distributed on an "AS IS" BASIS,+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.+# See the License for the specific language governing permissions and+# limitations under the License.+#++import base64++def encode_to_base64(input_string):+ base64_encoded = base64.b64encode(input_string.encode('utf-8'))+ return base64_encoded.decode('utf-8')\ No newline at end of filediff --git a/api/db/init_data.py b/api/db/init_data.pyindex 166cf3bacc..39b87d06f0 100644--- a/api/db/init_data.py+++ b/api/db/init_data.py@@ -14,7 +14,6 @@# limitations under the License.#import logging-import base64import jsonimport osimport time@@ -32,11 +31,7 @@ from api.db.services.llm_service import LLMService, LLMBundle, get_init_tenant_lfrom api.db.services.user_service import TenantService, UserTenantServicefrom api import settingsfrom api.utils.file_utils import get_project_base_directory---def encode_to_base64(input_string):- base64_encoded = base64.b64encode(input_string.encode('utf-8'))- return base64_encoded.decode('utf-8')+from api.common.base64 import encode_to_base64def init_superuser():