file-netai 0.1.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,18 @@
1
+ Metadata-Version: 2.4
2
+ Name: file_netai
3
+ Version: 0.1.0
4
+ Summary: AI 生成文件工具
5
+ Author: shiroko
6
+ Author-email: 3207774253@qq.com
7
+ Requires-Python: >=3.6
8
+ Description-Content-Type: text/markdown
9
+ Requires-Dist: shiroko_netai
10
+ Dynamic: author
11
+ Dynamic: author-email
12
+ Dynamic: description
13
+ Dynamic: description-content-type
14
+ Dynamic: requires-dist
15
+ Dynamic: requires-python
16
+ Dynamic: summary
17
+
18
+ AI 生成文件工具,根据用户需求自动决定文件名、路径和内容。
@@ -0,0 +1,37 @@
1
+ # file_netai
2
+
3
+ ## 免责声明
4
+
5
+ 1. **本工具生成的所有代码均由 AI 自动生成,未经人工逐行审查。**
6
+ 2. **作者不对生成代码的正确性、安全性、可靠性作任何明示或暗示的保证。**
7
+ 3. **使用者必须自行审查、测试、修改生成代码,确认无误后方可使用。**
8
+ 4. **因使用生成代码导致的任何直接或间接损失(包括但不限于数据丢失、系统损坏、法律纠纷),作者不承担任何责任。**
9
+ 5. **禁止使用本工具生成恶意代码、病毒、木马等危害性内容。**
10
+ 6. **继续使用本工具即代表您已阅读、理解并同意上述条款。**
11
+
12
+ **⚠️ 安装、下载、使用本工具即视为已阅读并同意以上免责声明。**
13
+ **如不同意以上条款,请立即卸载并停止使用本工具。**
14
+
15
+
16
+ AI 文件生成工具 —— 根据自然语言需求直接生成代码文件,带短时记忆
17
+
18
+ ## 安装
19
+
20
+ ```bash
21
+ pip install file_netai
22
+ ```
23
+
24
+ 依赖
25
+
26
+ · Python >= 3.6
27
+ · shiroko_netai
28
+
29
+ 使用
30
+
31
+ ```bash
32
+ # 生成文件
33
+ file_netai "生成一个 Flask 登录页面"
34
+
35
+ # 查询上一次生成的内容
36
+ file_netai "刚才生成的代码是什么"
37
+ ```
@@ -0,0 +1,5 @@
1
+ from .cli import main
2
+ from .core import generate_from_prompt
3
+
4
+ __version__ = "0.2.0"
5
+ __all__ = ["main", "generate_from_prompt"]
@@ -0,0 +1,31 @@
1
+ #!/usr/bin/env python3
2
+ import sys
3
+ import argparse
4
+ import json
5
+ from .core import generate_from_prompt
6
+
7
+ def main():
8
+ parser = argparse.ArgumentParser(description="AI 文件生成工具")
9
+ parser.add_argument("prompts", nargs="*", help="需求描述(可多个)")
10
+ parser.add_argument("--batch", help="批量生成配置文件 (JSON 数组)")
11
+ parser.add_argument("--url", default="http://127.0.0.1:11434/api/chat", help="AI API 地址")
12
+ parser.add_argument("--model", default="deepseek-r1:1.5b", help="模型名称")
13
+ parser.add_argument("--no-memory", action="store_true", help="不保存记忆")
14
+
15
+ args = parser.parse_args()
16
+
17
+ if args.batch:
18
+ with open(args.batch, "r", encoding="utf-8") as f:
19
+ prompts = json.load(f)
20
+ for prompt in prompts:
21
+ print(f"\n--- 处理: {prompt} ---")
22
+ generate_from_prompt(prompt, url=args.url, model=args.model, memory=not args.no_memory)
23
+ elif args.prompts:
24
+ for prompt in args.prompts:
25
+ print(f"\n--- 处理: {prompt} ---")
26
+ generate_from_prompt(prompt, url=args.url, model=args.model, memory=not args.no_memory)
27
+ else:
28
+ parser.print_help()
29
+
30
+ if __name__ == "__main__":
31
+ main()
@@ -0,0 +1,77 @@
1
+ import json
2
+ import os
3
+ from shiroko_netai import TCC
4
+
5
+ _last_generated = None
6
+
7
+ def parse_null(val):
8
+ return None if val == "<[null]>" else val
9
+
10
+ def generate_from_prompt(user_prompt, url=None, model=None, memory=True):
11
+ global _last_generated
12
+
13
+ if url is None:
14
+ url = "http://127.0.0.1:11434/api/chat"
15
+ if model is None:
16
+ model = "deepseek-r1:1.5b"
17
+
18
+ ai = TCC(url=url, model=model)
19
+
20
+ if memory and "刚才" in user_prompt and ("代码" in user_prompt or "生成" in user_prompt):
21
+ if _last_generated:
22
+ print("你刚才生成的代码是:")
23
+ print(_last_generated.get("file_content", "无内容"))
24
+ return _last_generated.get("file_content")
25
+ else:
26
+ print("还没有生成过任何代码。")
27
+ return None
28
+
29
+ system_prompt = (
30
+ "你是一个文件生成助手。根据用户的需求,返回一个 JSON 对象,不要输出任何解释。\n"
31
+ "JSON 格式如下:\n"
32
+ "{\n"
33
+ " \"file_name\": \"文件名\",\n"
34
+ " \"file_path\": \"目录路径或<[null]>\",\n"
35
+ " \"file_content\": \"文件内容\",\n"
36
+ " \"FOLDER_path\": \"附加目录或<[null]>\"\n"
37
+ "}\n"
38
+ "如果不需要目录,请使用 <[null]> 表示。"
39
+ )
40
+ full_prompt = f"{system_prompt}\n用户需求:{user_prompt}"
41
+ response = ai.send(full_prompt)
42
+
43
+ try:
44
+ data = json.loads(response)
45
+ file_name = data.get("file_name")
46
+ file_path = parse_null(data.get("file_path"))
47
+ file_content = data.get("file_content", "")
48
+ folder_path = parse_null(data.get("FOLDER_path"))
49
+
50
+ if not file_name:
51
+ print("AI 未返回文件名")
52
+ return None
53
+
54
+ if memory:
55
+ _last_generated = data
56
+
57
+ if file_path:
58
+ os.makedirs(file_path, exist_ok=True)
59
+ save_path = os.path.join(file_path, file_name)
60
+ else:
61
+ save_path = file_name
62
+
63
+ if folder_path:
64
+ os.makedirs(folder_path, exist_ok=True)
65
+ print(f"已创建附加目录: {folder_path}")
66
+
67
+ with open(save_path, "w", encoding="utf-8") as f:
68
+ f.write(file_content)
69
+ print(f"已生成文件: {save_path}")
70
+ return save_path
71
+ except json.JSONDecodeError as e:
72
+ print(f"AI 返回的不是有效 JSON: {e}")
73
+ print(f"原始响应: {response[:200]}...")
74
+ return None
75
+ except Exception as e:
76
+ print(f"生成失败: {e}")
77
+ return None
@@ -0,0 +1,18 @@
1
+ Metadata-Version: 2.4
2
+ Name: file_netai
3
+ Version: 0.1.0
4
+ Summary: AI 生成文件工具
5
+ Author: shiroko
6
+ Author-email: 3207774253@qq.com
7
+ Requires-Python: >=3.6
8
+ Description-Content-Type: text/markdown
9
+ Requires-Dist: shiroko_netai
10
+ Dynamic: author
11
+ Dynamic: author-email
12
+ Dynamic: description
13
+ Dynamic: description-content-type
14
+ Dynamic: requires-dist
15
+ Dynamic: requires-python
16
+ Dynamic: summary
17
+
18
+ AI 生成文件工具,根据用户需求自动决定文件名、路径和内容。
@@ -0,0 +1,11 @@
1
+ README.md
2
+ setup.py
3
+ file_netai/__init__.py
4
+ file_netai/cli.py
5
+ file_netai/core.py
6
+ file_netai.egg-info/PKG-INFO
7
+ file_netai.egg-info/SOURCES.txt
8
+ file_netai.egg-info/dependency_links.txt
9
+ file_netai.egg-info/entry_points.txt
10
+ file_netai.egg-info/requires.txt
11
+ file_netai.egg-info/top_level.txt
@@ -0,0 +1,2 @@
1
+ [console_scripts]
2
+ file_netai = file_netai.cli:main
@@ -0,0 +1 @@
1
+ shiroko_netai
@@ -0,0 +1 @@
1
+ file_netai
@@ -0,0 +1,4 @@
1
+ [egg_info]
2
+ tag_build =
3
+ tag_date = 0
4
+
@@ -0,0 +1,19 @@
1
+ from setuptools import setup, find_packages
2
+
3
+ setup(
4
+ name="file_netai",
5
+ version="0.1.0",
6
+ author="shiroko",
7
+ author_email="3207774253@qq.com",
8
+ description="AI 生成文件工具",
9
+ long_description="AI 生成文件工具,根据用户需求自动决定文件名、路径和内容。",
10
+ long_description_content_type="text/markdown",
11
+ packages=find_packages(),
12
+ install_requires=["shiroko_netai"],
13
+ entry_points={
14
+ "console_scripts": [
15
+ "file_netai = file_netai.cli:main",
16
+ ]
17
+ },
18
+ python_requires=">=3.6",
19
+ )