Skip to content

Commit 37e7faf

Browse files
committed
修改init_cmd
1 parent c889b15 commit 37e7faf

File tree

1 file changed

+51
-23
lines changed

1 file changed

+51
-23
lines changed
Lines changed: 51 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,63 @@
11
from pathlib import Path
22

3-
TEMPLATE_PLUGIN = '''from fitframework.api.decorators import fitable
3+
TEMPLATE_PLUGIN = '''from fitframework.api.decorators import fitable # 引入 Fit for Python 框架核心接口
44
5-
@fitable("genericable_id_demo", "fitable_id_demo")
6-
def hello(name: str) -> str:
7-
"""一个简单的 FIT 插件示例函数"""
8-
return f"Hello, {name}!"
5+
# 修改 genericable_id_hello / fitable_id_hello 为唯一的 ID
6+
# - 建议和插件功能相关,例如:
7+
# - @fitable("genericable_id_concat", "fitable_id_concat")
8+
@fitable("genericable_id_hello", "fitable_id_hello") # 指定可供调用函数的 genericable id 和 fitable id
9+
def hello(name: str) -> str: # 定义可供调用的函数,特别注意需要提供函数类型签名,
10+
# 可参照文档https://www.modelengine-ai.com/#/docs/zh_CN/ai-framework/fit/python/function-signature
11+
"""
12+
一个简单的 FIT 插件示例函数
13+
14+
修改函数名和参数
15+
- 函数名(hello)应根据功能调整,例如 concat, multiply
16+
- 参数(name: str)可以增加多个,类型也可以是 int, float 等
17+
"""
18+
19+
return f"Hello, {name}!" # 提供函数实现逻辑
20+
21+
# 关于插件开发其他内容可参考官方文档:https://github.com/ModelEngine-Group/fit-framework/tree/main/docs/framework/fit/python
922
'''
1023

11-
def run(args):
12-
"""生成插件模板"""
13-
base_dir = "plugin" / Path(args.name)
24+
def create_directory(path: Path):
25+
"""创建目录(如果不存在)"""
26+
if not path.exists():
27+
path.mkdir(parents=True)
28+
29+
return path
30+
31+
32+
def create_file(path: Path, content: str = "", overwrite: bool = False):
33+
"""创建文件,支持写入内容"""
34+
if path.exists() and not overwrite:
35+
print(f"⚠️ 文件 {path} 已存在,未覆盖。")
36+
return
37+
path.write_text(content, encoding="utf-8") if content else path.touch()
38+
39+
40+
41+
def generate_plugin_structure(plugin_name: str):
42+
"""生成插件目录和文件结构"""
43+
base_dir = Path("plugin") / plugin_name
1444
src_dir = base_dir / "src"
1545

1646
# 创建目录
17-
if not base_dir.exists():
18-
base_dir.mkdir(parents=True)
19-
print(f"✅ 已创建目录 {base_dir}")
20-
if not src_dir.exists():
21-
src_dir.mkdir(parents=True)
47+
create_directory(base_dir)
48+
create_directory(src_dir)
2249

23-
# __init__.py
50+
# 创建 __init__.py
2451
init_file = src_dir / "__init__.py"
25-
if not init_file.exists():
26-
init_file.touch()
27-
else:
28-
print(f"⚠️ 文件 {init_file} 已存在,未覆盖。")
52+
create_file(init_file)
2953

30-
# plugin.py
54+
# 创建 plugin.py
3155
plugin_file = src_dir / "plugin.py"
32-
if not plugin_file.exists():
33-
plugin_file.write_text(TEMPLATE_PLUGIN, encoding="utf-8")
34-
else:
35-
print(f"⚠️ 文件 {plugin_file} 已存在,未覆盖。")
56+
create_file(plugin_file, TEMPLATE_PLUGIN)
57+
58+
print(f"✅ 已创建目录 {base_dir} ")
59+
60+
61+
def run(args):
62+
"""命令入口"""
63+
generate_plugin_structure(args.name)

0 commit comments

Comments
 (0)