Merge remote-tracking branch 'origin/main'

This commit is contained in:
kithib 2024-04-19 17:56:36 +08:00
parent d2e461a1e8
commit d0e898dcfa
7 changed files with 91 additions and 111 deletions

View file

@ -219,7 +219,7 @@ class OutputParser:
if start_index != -1 and end_index != -1:
# Extract the structure part
structure_text = text[start_index : end_index + 1]
structure_text = text[start_index: end_index + 1]
try:
# Attempt to convert the text to a Python data type using ast.literal_eval
@ -841,3 +841,21 @@ def get_markdown_codeblock_type(filename: str) -> str:
"application/sql": "sql",
}
return mappings.get(mime_type, "text")
def download_model(file_url: str, target_folder: Path) -> Path:
file_name = file_url.split('/')[-1]
file_path = target_folder.joinpath(f"{file_name}")
if not file_path.exists():
file_path.mkdir(parents=True, exist_ok=True)
try:
response = requests.get(file_url, stream=True)
response.raise_for_status() # 检查请求是否成功
# 保存文件
with open(file_path, 'wb') as f:
for chunk in response.iter_content(chunk_size=8192):
f.write(chunk)
logger.info(f'权重文件已下载并保存至 {file_path}')
except requests.exceptions.HTTPError as err:
logger.info(f'权重文件下载过程中发生错误: {err}')
return file_path

View file

@ -1,22 +0,0 @@
import os
import requests
from pathlib import Path
def download_model(file_url: str, target_folder: str) -> str:
file_name = file_url.split('/')[-1] # 文件名从URL中提取
file_path = os.path.join(target_folder, file_name) # 完整的文件路径
if not os.path.exists(target_folder):
os.makedirs(target_folder)
# 发起GET请求下载文件
try:
response = requests.get(file_url, stream=True)
response.raise_for_status() # 检查请求是否成功
# 保存文件
with open(file_path, 'wb') as f:
for chunk in response.iter_content(chunk_size=8192):
f.write(chunk)
print(f'权重文件已下载并保存至 {file_path}')
except requests.exceptions.HTTPError as err:
print(f'权重文件下载过程中发生错误: {err}')
return file_path