Refactor: reformat all code for lefthook using ruff and gofmt (#16585)

This commit is contained in:
Wang Qi
2026-07-03 12:53:39 +08:00
committed by GitHub
parent 19fcb4a981
commit 6a4b9be426
588 changed files with 11123 additions and 15412 deletions

View File

@@ -113,12 +113,7 @@ def add_model_instance(auth):
pytest.exit(f"Critical error in add model provider: {add_provider_res.get('message')}")
add_instance_api = HOST_ADDRESS + "/api/v1/providers/ZHIPU-AI/instances"
add_instance_response = requests.post(url=add_instance_api, headers=authorization, json={
"instance_name": "CI",
"api_key": ZHIPU_AI_API_KEY,
"region": "default",
"base_url": ""
})
add_instance_response = requests.post(url=add_instance_api, headers=authorization, json={"instance_name": "CI", "api_key": ZHIPU_AI_API_KEY, "region": "default", "base_url": ""})
add_instance_res = add_instance_response.json()
if add_instance_res.get("code") != 0:
pytest.exit(f"Critical error in add model instance: {add_instance_res.get('message')}")
@@ -139,41 +134,19 @@ def set_tenant_info(get_auth):
url = HOST_ADDRESS + "/api/v1/models/default"
authorization = {"Authorization": get_auth}
# set chat model
set_default_llm_response = requests.patch(
url=url,
headers=authorization,
json={
"model_provider": "ZHIPU-AI",
"model_instance": "CI",
"model_type": "chat",
"model_name": "glm-4-flash"
})
set_default_llm_response = requests.patch(url=url, headers=authorization, json={"model_provider": "ZHIPU-AI", "model_instance": "CI", "model_type": "chat", "model_name": "glm-4-flash"})
llm_res = set_default_llm_response.json()
if llm_res.get("code") != 0:
raise Exception(llm_res.get("message"))
# set embedding model
set_default_embedding_response = requests.patch(
url=url,
headers=authorization,
json={
"model_provider": "Builtin",
"model_instance": "Local",
"model_type": "embedding",
"model_name": "BAAI/bge-small-en-v1.5"
})
url=url, headers=authorization, json={"model_provider": "Builtin", "model_instance": "Local", "model_type": "embedding", "model_name": "BAAI/bge-small-en-v1.5"}
)
embd_res = set_default_embedding_response.json()
if embd_res.get("code") != 0:
raise Exception(embd_res.get("message"))
# set image to text model
set_default_img2txt_response = requests.patch(
url=url,
headers=authorization,
json={
"model_provider": "ZHIPU-AI",
"model_instance": "CI",
"model_type": "vision",
"model_name": "glm-4v"
})
set_default_img2txt_response = requests.patch(url=url, headers=authorization, json={"model_provider": "ZHIPU-AI", "model_instance": "CI", "model_type": "vision", "model_name": "glm-4v"})
img2txt_res = set_default_img2txt_response.json()
if img2txt_res.get("code") != 0:
raise Exception(img2txt_res.get("message"))

View File

@@ -73,20 +73,20 @@ def list_document(auth, dataset_id):
def get_docs_info(auth, dataset_id, doc_ids=None, doc_id=None):
"""
Get document information by IDs.
Args:
auth: Authorization header
dataset_id: Dataset ID
doc_ids: List of document IDs (use for multiple) - exclusive with doc_id
doc_id: Single document ID (use for one) - exclusive with doc_ids
Raises:
ValueError: If both doc_id and doc_ids are provided
"""
# Validate that id and ids are not used together
if doc_id and doc_ids:
raise ValueError("Cannot use both 'id' and 'ids' parameters at the same time.")
authorization = {"Authorization": auth}
params = {}
if doc_ids:
@@ -96,7 +96,7 @@ def get_docs_info(auth, dataset_id, doc_ids=None, doc_id=None):
elif doc_id:
# Single ID
params["id"] = doc_id
# Use /api/v1 prefix for dataset API
url = f"{HOST_ADDRESS}/api/v1/datasets/{dataset_id}/documents"
res = requests.get(url=url, headers=authorization, params=params)
@@ -113,4 +113,3 @@ def parse_docs(auth, doc_ids):
def parse_file(auth, document_id):
pass

View File

@@ -14,6 +14,7 @@
# limitations under the License.
#
def test_get_email(get_email):
print("\nEmail account:",flush=True)
print(f"{get_email}\n",flush=True)
print("\nEmail account:", flush=True)
print(f"{get_email}\n", flush=True)

View File

@@ -40,15 +40,15 @@ def test_parse_txt_document(get_auth):
break
page_number += 1
filename = 'ragflow_test.txt'
filename = "ragflow_test.txt"
res = upload_file(get_auth, dataset_id, f"../test_sdk_api/test_data/{filename}")
assert res.get("code") == 0, f"{res.get('message')}"
res = list_document(get_auth, dataset_id)
doc_id_list = []
for doc in res['data']['docs']:
doc_id_list.append(doc['id'])
for doc in res["data"]["docs"]:
doc_id_list.append(doc["id"])
res = get_docs_info(get_auth, dataset_id, doc_ids=doc_id_list)
print(doc_id_list)
@@ -59,13 +59,13 @@ def test_parse_txt_document(get_auth):
while True:
res = get_docs_info(get_auth, dataset_id, doc_ids=doc_id_list)
finished_count = 0
for doc_info in res['data']:
if doc_info['progress'] == 1:
for doc_info in res["data"]:
if doc_info["progress"] == 1:
finished_count += 1
if finished_count == doc_count:
break
sleep(1)
print('time cost {:.1f}s'.format(timer() - start_ts))
print("time cost {:.1f}s".format(timer() - start_ts))
# delete dataset
if dataset_list:

View File

@@ -89,7 +89,7 @@ def test_duplicated_name_dataset(get_auth):
if isinstance(data, dict):
data = data.get("kbs", [])
dataset_list = []
pattern = r'^test_create_dataset.*'
pattern = r"^test_create_dataset.*"
for item in data:
dataset_name = item.get("name")
dataset_id = item.get("id")
@@ -106,10 +106,10 @@ def test_duplicated_name_dataset(get_auth):
def test_invalid_name_dataset(get_auth):
# create dataset
res = create_dataset(get_auth, {"name": 0})
assert res['code'] != 0
assert res["code"] != 0
res = create_dataset(get_auth, {"name": ""})
assert res['code'] != 0
assert res["code"] != 0
long_string = ""
@@ -117,7 +117,7 @@ def test_invalid_name_dataset(get_auth):
long_string += random.choice(string.ascii_letters + string.digits)
res = create_dataset(get_auth, {"name": long_string})
assert res['code'] != 0
assert res["code"] != 0
print(res)
@@ -144,13 +144,17 @@ def test_update_different_params_dataset_success(get_auth):
print(f"found {len(dataset_list)} datasets")
dataset_id = dataset_list[0]
res = update_dataset(get_auth, dataset_id, {
"name": "test_update_dataset",
"description": "test",
"permission": "me",
"chunk_method": "presentation",
"language": "spanish",
})
res = update_dataset(
get_auth,
dataset_id,
{
"name": "test_update_dataset",
"description": "test",
"permission": "me",
"chunk_method": "presentation",
"language": "spanish",
},
)
assert res.get("code") == 0, f"{res.get('message')}"
# delete dataset