A unified wrapper for various AI API services
Project description
ai-api-wrapper
ai-api-wrapper/ │ ├── src/ │ └── ai_api_wrapper/ │ ├── init.py │ ├── services/ │ │ ├── init.py │ │ ├── ai_service.py │ │ ├── openai_service.py │ │ ├── message_types.py │ │ └── ... (其他AI服务实现) │ ├── utils/ │ │ ├── init.py │ │ ├── config_manager.py │ │ └── logger.py │ └── config/ │ ├── init.py │ ├── default_config.yaml │ └── ... (默认配置文件) │ ├── examples/ │ ├── config/ │ │ └── example_config.yaml │ ├── basic_usage.py │ └── streaming_example.py │ ├── tests/ │ ├── init.py │ ├── test_openai_service.py │ └── ... (其他测试) │ ├── docs/ │ └── ... (文档文件) │ ├── .gitignore ├── LICENSE ├── MANIFEST.in ├── pyproject.toml ├── README.md └── setup.py
配置系统说明
配置文件结构
项目使用分层的JSON配置文件系统:
-
default.json:默认配置文件- 包含所有可能的配置项
- 定义默认值和基本结构
- 可以提交到版本控制
- 不应包含任何敏感信息(API密钥、密码等)
-
local.json:本地配置文件- 包含敏感信息(API密钥、密码等)
- 覆盖默认配置
- 不应提交到版本控制
- 应添加到
.gitignore文件中
安全最佳实践
-
敏感信息仅存储在
local.json中- API 密钥
- 数据库凭据
- JWT 密钥
- 任何其他密码或密钥
-
禁止在
default.json中存储任何真实的敏感信息- 在
default.json中,将所有密钥字段设置为空字符串"" - 仅使用
default.json定义配置结构
- 在
-
版本控制注意事项
- 始终将
local.json添加到.gitignore - 仅提交
default.json到仓库 - 提供
local.json.template文件,用于新开发人员设置
- 始终将
配置项说明
AI服务配置
{
"ai_services": {
"service_name": {
"enabled": true,
"default_provider": "official",
"default_model": "model-name",
"providers": {
"provider_name": {
"name": "显示名称",
"enabled": true,
"api_key": "", // 在 default.json 中留空,在 local.json 中填写实际值
"base_url": "API基础URL",
"models": {
"model_name": {
"internal_name": "提供商特定的模型名称",
"max_tokens": 4000,
"temperature": 0.7
}
}
}
}
}
}
}
其他配置
database:数据库配置(密码仅存储在 local.json)redis:Redis配置(密码仅存储在 local.json)jwt_secret:JWT密钥(仅存储在 local.json)logging:日志配置
使用方法
- 复制
local.json.template为local.json - 在
local.json中填入实际的配置值(API密钥等) - 不要修改
default.json中的默认值(除非添加新功能) - 使用
ConfigManager类访问配置:
from utils.config_manager import ConfigManager
config = ConfigManager()
# 获取服务配置
service_config = config.get_service_config('deepseek')
# 获取提供商配置
provider_config = config.get_provider_config('deepseek', 'siliconflow')
# 获取模型配置
model_config = config.get_model_config('deepseek', 'siliconflow', 'deepseek-chat')
# 获取已启用的服务
enabled_services = config.get_enabled_services()
注意事项
- 不要在代码中硬编码任何敏感信息
- 不要提交
local.json到版本控制 - 保持配置文件的结构与
default.json一致 - 使用有意义的配置项名称
- 及时更新文档
# 安装必要的工具
pip install build twine pytest
# 运行测试,确保一切正常
pytest
# 检查 README.md 在渲染后是否正确
python -m readme_renderer README.md
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file ai_api_wrapper-0.1.0.tar.gz.
File metadata
- Download URL: ai_api_wrapper-0.1.0.tar.gz
- Upload date:
- Size: 25.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.12.8
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
c711b86e4abd046e90cfeac991c52a23c67549030c75804b995e7cb2459ff0ee
|
|
| MD5 |
56649d23712107a3a5323d8e541b17bf
|
|
| BLAKE2b-256 |
e41859783efa925923754e06a1d65bed204893ea6307346fce57ffaad98e9bfe
|
File details
Details for the file ai_api_wrapper-0.1.0-py3-none-any.whl.
File metadata
- Download URL: ai_api_wrapper-0.1.0-py3-none-any.whl
- Upload date:
- Size: 16.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.12.8
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
eb84bf2d4a267fc22f2420db3072f90be0537d8ced2e7b57f8fa1519e5f677eb
|
|
| MD5 |
f64177a8e06e9e61ca05ed876701527d
|
|
| BLAKE2b-256 |
1c4f4a876d858cc116eee327237384cd38b34ce18419fcea1866fde439e55877
|