12.12 豆包测试
This commit is contained in:
parent
dc30de3087
commit
7f11b3ad34
@ -57,6 +57,8 @@ def read_file_ids(output_folder):
|
|||||||
return file_ids
|
return file_ids
|
||||||
|
|
||||||
|
|
||||||
|
from concurrent.futures import ThreadPoolExecutor, as_completed
|
||||||
|
|
||||||
def delete_file_by_ids(file_ids):
|
def delete_file_by_ids(file_ids):
|
||||||
"""
|
"""
|
||||||
根据传入的 file_id 列表删除指定的文件。
|
根据传入的 file_id 列表删除指定的文件。
|
||||||
@ -79,17 +81,25 @@ def delete_file_by_ids(file_ids):
|
|||||||
else:
|
else:
|
||||||
valid_file_ids = file_ids
|
valid_file_ids = file_ids
|
||||||
|
|
||||||
try:
|
def delete_file(file_id):
|
||||||
# 删除指定文件
|
|
||||||
for file_id in valid_file_ids:
|
|
||||||
try:
|
try:
|
||||||
# 假设 openai.File.delete 会返回一个文件对象
|
# 假设 openai.File.delete 会返回一个文件对象
|
||||||
file_object = client.files.delete(file_id)
|
file_object = client.files.delete(file_id)
|
||||||
# print(f"Deleted file with id: {file_id} - {file_object}")
|
return None # 成功返回 None
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
# 处理删除单个文件时的异常
|
|
||||||
print(f"Failed to delete file with id {file_id}: {e}")
|
print(f"Failed to delete file with id {file_id}: {e}")
|
||||||
failed_file_ids.append(file_id)
|
return file_id # 返回失败的 file_id
|
||||||
|
|
||||||
|
try:
|
||||||
|
with ThreadPoolExecutor(max_workers=len(valid_file_ids)) as executor:
|
||||||
|
# 提交所有删除任务
|
||||||
|
futures = {executor.submit(delete_file, file_id): file_id for file_id in valid_file_ids}
|
||||||
|
|
||||||
|
# 收集结果
|
||||||
|
for future in as_completed(futures):
|
||||||
|
result = future.result()
|
||||||
|
if result is not None: # 如果返回值不是 None,表示删除失败
|
||||||
|
failed_file_ids.append(result)
|
||||||
|
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
print(f"An error occurred while processing the file_ids: {e}")
|
print(f"An error occurred while processing the file_ids: {e}")
|
||||||
@ -99,5 +109,8 @@ def delete_file_by_ids(file_ids):
|
|||||||
return failed_file_ids
|
return failed_file_ids
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
delete_all_files()
|
# delete_all_files()
|
||||||
|
file_ids=["file-fe-Lu6GKmTR1NjimC2tOebRAIYT"]
|
||||||
|
delete_file_by_ids(file_ids)
|
@ -4,6 +4,7 @@ from functools import wraps
|
|||||||
|
|
||||||
from flask import request, jsonify, current_app, g
|
from flask import request, jsonify, current_app, g
|
||||||
|
|
||||||
|
from flask_app.general.清除file_id import read_file_ids, delete_file_by_ids
|
||||||
from flask_app.logger_setup import create_logger
|
from flask_app.logger_setup import create_logger
|
||||||
|
|
||||||
|
|
||||||
@ -113,3 +114,19 @@ def validate_and_setup_logger(f):
|
|||||||
# 验证失败,返回错误响应
|
# 验证失败,返回错误响应
|
||||||
return validation_result
|
return validation_result
|
||||||
return decorated_function
|
return decorated_function
|
||||||
|
|
||||||
|
def perform_cleanup(output_folder, logger):
|
||||||
|
"""
|
||||||
|
清理逻辑:删除临时文件或其他资源。
|
||||||
|
"""
|
||||||
|
try:
|
||||||
|
if output_folder:
|
||||||
|
logger.info(f"正在清理输出文件夹: {output_folder}")
|
||||||
|
file_ids = read_file_ids(output_folder)
|
||||||
|
failed_file_ids = delete_file_by_ids(file_ids)
|
||||||
|
if failed_file_ids:
|
||||||
|
logger.error(f"以下文件删除失败: {failed_file_ids}")
|
||||||
|
else:
|
||||||
|
logger.info("清理完毕!")
|
||||||
|
except Exception as e:
|
||||||
|
logger.error(f"清理过程中发生异常: {str(e)}")
|
Loading…
x
Reference in New Issue
Block a user