Files
2026-05-18 09:28:15 +08:00

87 lines
2.2 KiB
Python
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
"""AIBridge - JNPF 低代码平台 Python 接口包
通过 AI 对话快速完成产品设计、应用开发和验证。
使用方法:
# 方式一:在项目根目录运行
cd /path/to/project
python3 -m aibridge.examples.example_name
# 方式二:在 examples 目录运行
cd /path/to/project/aibridge/examples
python3 example_name.py
# 方式三:使用统一入口(自动设置路径)
import sys
from aibridge import setup_path
setup_path() # 自动添加项目根目录到 sys.path
from aibridge import JNPFClient, JNPFConfig
# ...
"""
__version__ = "1.0.0"
__author__ = "AIBridge"
import os
import sys
def setup_path() -> None:
"""统一设置 sys.path,确保能正确导入 aibridge 模块。
调用此函数会自动将项目根目录添加到 sys.path。
项目根目录 = aibridge 包所在目录的父目录。
推荐在所有示例脚本开头调用此函数:
from aibridge import setup_path
setup_path()
from aibridge import JNPFClient, JNPFConfig
# ...
"""
# 获取 aibridge 包所在目录
aibridge_dir = os.path.dirname(os.path.abspath(__file__))
# 项目根目录 = aibridge 的父目录
project_root = os.path.dirname(aibridge_dir)
# 如果项目根目录还不在 sys.path 中,则添加
if project_root not in sys.path:
sys.path.insert(0, project_root)
def check_python_version() -> bool:
"""检查 Python 版本,确保是 python3。
Returns:
True 如果是 python3,False 否则
"""
version = sys.version_info
if version.major < 3:
print(f"错误:需要 Python 3.x,当前版本是 {version.major}.{version.minor}")
print("请使用 python3 命令运行此脚本")
return False
return True
# 导出公共接口
from aibridge.client import JNPFClient
from aibridge.config import JNPFConfig
from aibridge.exceptions import JNPFError, AuthError, APIError
from aibridge.models import APIResponse
__all__ = [
# 核心
"JNPFClient",
"JNPFConfig",
"APIResponse",
# 异常
"JNPFError",
"AuthError",
"APIError",
# 工具函数
"setup_path",
"check_python_version",
]