Merge branch 'release/v0.2.3' into develop
This commit is contained in:
@@ -4,16 +4,19 @@
|
|||||||
从文件系统加载预定义的工作流模板
|
从文件系统加载预定义的工作流模板
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
import os
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
from typing import Optional
|
from typing import Optional
|
||||||
|
|
||||||
import yaml
|
import yaml
|
||||||
|
|
||||||
|
TEMPLATE_DIR = os.path.join(os.path.dirname(os.path.abspath(__file__)), 'templates')
|
||||||
|
|
||||||
|
|
||||||
class TemplateLoader:
|
class TemplateLoader:
|
||||||
"""工作流模板加载器"""
|
"""工作流模板加载器"""
|
||||||
|
|
||||||
def __init__(self, templates_dir: str = "app/templates/workflows"):
|
def __init__(self, templates_dir: str = TEMPLATE_DIR):
|
||||||
"""初始化模板加载器
|
"""初始化模板加载器
|
||||||
|
|
||||||
Args:
|
Args:
|
||||||
@@ -22,7 +25,7 @@ class TemplateLoader:
|
|||||||
self.templates_dir = Path(templates_dir)
|
self.templates_dir = Path(templates_dir)
|
||||||
if not self.templates_dir.exists():
|
if not self.templates_dir.exists():
|
||||||
raise ValueError(f"模板目录不存在: {templates_dir}")
|
raise ValueError(f"模板目录不存在: {templates_dir}")
|
||||||
|
|
||||||
def list_templates(self) -> list[dict]:
|
def list_templates(self) -> list[dict]:
|
||||||
"""列出所有可用的模板
|
"""列出所有可用的模板
|
||||||
|
|
||||||
@@ -30,22 +33,22 @@ class TemplateLoader:
|
|||||||
模板列表,每个模板包含 id, name, description 等信息
|
模板列表,每个模板包含 id, name, description 等信息
|
||||||
"""
|
"""
|
||||||
templates = []
|
templates = []
|
||||||
|
|
||||||
# 遍历模板目录
|
# 遍历模板目录
|
||||||
for template_dir in self.templates_dir.iterdir():
|
for template_dir in self.templates_dir.iterdir():
|
||||||
if not template_dir.is_dir():
|
if not template_dir.is_dir():
|
||||||
continue
|
continue
|
||||||
|
|
||||||
# 检查是否有 template.yml 文件
|
# 检查是否有 template.yml 文件
|
||||||
template_file = template_dir / "template.yml"
|
template_file = template_dir / "template.yml"
|
||||||
if not template_file.exists():
|
if not template_file.exists():
|
||||||
continue
|
continue
|
||||||
|
|
||||||
try:
|
try:
|
||||||
# 读取模板配置
|
# 读取模板配置
|
||||||
with open(template_file, 'r', encoding='utf-8') as f:
|
with open(template_file, 'r', encoding='utf-8') as f:
|
||||||
template_data = yaml.safe_load(f)
|
template_data = yaml.safe_load(f)
|
||||||
|
|
||||||
# 提取模板信息
|
# 提取模板信息
|
||||||
templates.append({
|
templates.append({
|
||||||
"id": template_dir.name,
|
"id": template_dir.name,
|
||||||
@@ -59,9 +62,9 @@ class TemplateLoader:
|
|||||||
except Exception as e:
|
except Exception as e:
|
||||||
print(f"加载模板 {template_dir.name} 失败: {e}")
|
print(f"加载模板 {template_dir.name} 失败: {e}")
|
||||||
continue
|
continue
|
||||||
|
|
||||||
return templates
|
return templates
|
||||||
|
|
||||||
def load_template(self, template_id: str) -> Optional[dict]:
|
def load_template(self, template_id: str) -> Optional[dict]:
|
||||||
"""加载指定的模板
|
"""加载指定的模板
|
||||||
|
|
||||||
@@ -73,14 +76,14 @@ class TemplateLoader:
|
|||||||
"""
|
"""
|
||||||
template_dir = self.templates_dir / template_id
|
template_dir = self.templates_dir / template_id
|
||||||
template_file = template_dir / "template.yml"
|
template_file = template_dir / "template.yml"
|
||||||
|
|
||||||
if not template_file.exists():
|
if not template_file.exists():
|
||||||
return None
|
return None
|
||||||
|
|
||||||
try:
|
try:
|
||||||
with open(template_file, 'r', encoding='utf-8') as f:
|
with open(template_file, 'r', encoding='utf-8') as f:
|
||||||
template_data = yaml.safe_load(f)
|
template_data = yaml.safe_load(f)
|
||||||
|
|
||||||
# 返回工作流配置部分
|
# 返回工作流配置部分
|
||||||
return {
|
return {
|
||||||
"name": template_data.get("name", template_id),
|
"name": template_data.get("name", template_id),
|
||||||
@@ -94,7 +97,7 @@ class TemplateLoader:
|
|||||||
except Exception as e:
|
except Exception as e:
|
||||||
print(f"加载模板 {template_id} 失败: {e}")
|
print(f"加载模板 {template_id} 失败: {e}")
|
||||||
return None
|
return None
|
||||||
|
|
||||||
def get_template_readme(self, template_id: str) -> Optional[str]:
|
def get_template_readme(self, template_id: str) -> Optional[str]:
|
||||||
"""获取模板的 README 文档
|
"""获取模板的 README 文档
|
||||||
|
|
||||||
@@ -106,10 +109,10 @@ class TemplateLoader:
|
|||||||
"""
|
"""
|
||||||
template_dir = self.templates_dir / template_id
|
template_dir = self.templates_dir / template_id
|
||||||
readme_file = template_dir / "README.md"
|
readme_file = template_dir / "README.md"
|
||||||
|
|
||||||
if not readme_file.exists():
|
if not readme_file.exists():
|
||||||
return None
|
return None
|
||||||
|
|
||||||
try:
|
try:
|
||||||
with open(readme_file, 'r', encoding='utf-8') as f:
|
with open(readme_file, 'r', encoding='utf-8') as f:
|
||||||
return f.read()
|
return f.read()
|
||||||
|
|||||||
@@ -27,7 +27,6 @@ const ModelImplement: FC<ModelImplementProps> = ({ type, value, onChange }) => {
|
|||||||
const handleDelete = (vo: any) => {
|
const handleDelete = (vo: any) => {
|
||||||
modal.confirm({
|
modal.confirm({
|
||||||
title: t('common.confirmDeleteDesc', { name: [vo.model_name, vo.api_key].join(' / ') }),
|
title: t('common.confirmDeleteDesc', { name: [vo.model_name, vo.api_key].join(' / ') }),
|
||||||
content: t('application.apiKeyDeleteContent'),
|
|
||||||
okText: t('common.delete'),
|
okText: t('common.delete'),
|
||||||
cancelText: t('common.cancel'),
|
cancelText: t('common.cancel'),
|
||||||
okType: 'danger',
|
okType: 'danger',
|
||||||
|
|||||||
@@ -25,7 +25,6 @@ const History: React.FC<{ query: HistoryQuery; edit: (item: HistoryItem) => void
|
|||||||
e?.stopPropagation();
|
e?.stopPropagation();
|
||||||
modal.confirm({
|
modal.confirm({
|
||||||
title: t('common.confirmDeleteDesc', { name: item.title }),
|
title: t('common.confirmDeleteDesc', { name: item.title }),
|
||||||
content: t('application.apiKeyDeleteContent'),
|
|
||||||
okText: t('common.delete'),
|
okText: t('common.delete'),
|
||||||
cancelText: t('common.cancel'),
|
cancelText: t('common.cancel'),
|
||||||
okType: 'danger',
|
okType: 'danger',
|
||||||
|
|||||||
Reference in New Issue
Block a user