litellm-controller 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.
- litellm_controller-0.1.0/PKG-INFO +90 -0
- litellm_controller-0.1.0/README.md +68 -0
- litellm_controller-0.1.0/litellm_controller/__init__.py +2 -0
- litellm_controller-0.1.0/litellm_controller/client.py +88 -0
- litellm_controller-0.1.0/litellm_controller/config.py +488 -0
- litellm_controller-0.1.0/litellm_controller/examples/deepseek.py +87 -0
- litellm_controller-0.1.0/litellm_controller/examples/openrouter.py +118 -0
- litellm_controller-0.1.0/litellm_controller/examples/type_static_json.py +38 -0
- litellm_controller-0.1.0/litellm_controller/main.py +110 -0
- litellm_controller-0.1.0/litellm_controller/modules/__init__.py +1 -0
- litellm_controller-0.1.0/litellm_controller/modules/metadata.py +1284 -0
- litellm_controller-0.1.0/litellm_controller/modules/models.py +1018 -0
- litellm_controller-0.1.0/litellm_controller/modules/routing.py +785 -0
- litellm_controller-0.1.0/litellm_controller/modules/settings.py +277 -0
- litellm_controller-0.1.0/litellm_controller/ui.py +337 -0
- litellm_controller-0.1.0/litellm_controller/upstreams.py +95 -0
- litellm_controller-0.1.0/litellm_controller.egg-info/PKG-INFO +90 -0
- litellm_controller-0.1.0/litellm_controller.egg-info/SOURCES.txt +36 -0
- litellm_controller-0.1.0/litellm_controller.egg-info/dependency_links.txt +1 -0
- litellm_controller-0.1.0/litellm_controller.egg-info/entry_points.txt +2 -0
- litellm_controller-0.1.0/litellm_controller.egg-info/requires.txt +6 -0
- litellm_controller-0.1.0/litellm_controller.egg-info/top_level.txt +1 -0
- litellm_controller-0.1.0/pyproject.toml +45 -0
- litellm_controller-0.1.0/setup.cfg +4 -0
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: litellm_controller
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: A command-line tool for managing LiteLLM proxy models
|
|
5
|
+
Author-email: Moha-Master <hongkongreporter@outlook.com>
|
|
6
|
+
License-Expression: MIT
|
|
7
|
+
Classifier: Development Status :: 4 - Beta
|
|
8
|
+
Classifier: Intended Audience :: Developers
|
|
9
|
+
Classifier: Programming Language :: Python :: 3
|
|
10
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
11
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
12
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
13
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
14
|
+
Classifier: Programming Language :: Python :: 3.14
|
|
15
|
+
Requires-Python: >=3.9
|
|
16
|
+
Description-Content-Type: text/markdown
|
|
17
|
+
Requires-Dist: InquirerPy
|
|
18
|
+
Requires-Dist: PyYAML
|
|
19
|
+
Requires-Dist: requests
|
|
20
|
+
Provides-Extra: dev
|
|
21
|
+
Requires-Dist: pytest>=6.0; extra == "dev"
|
|
22
|
+
|
|
23
|
+
# LiteLLM Controller (litellmctl)
|
|
24
|
+
|
|
25
|
+
LiteLLM Controller 是一个功能强大的命令行界面(CLI)管理工具,专为 [LiteLLM Proxy](https://github.com/BerriAI/litellm) 设计,旨在简化模型管理、路由组配置以及模型元数据(定价与上下文窗口)的维护。
|
|
26
|
+
|
|
27
|
+
## 核心特性
|
|
28
|
+
|
|
29
|
+
- **模型管理**:交互式列出、添加、编辑、启用/禁用和删除 LiteLLM Proxy 中的模型。
|
|
30
|
+
- **路由管理**:管理模型路由组(Router Groups),支持批量清理失效模型。
|
|
31
|
+
- **脚本驱动的元数据管理**:
|
|
32
|
+
- **优先级合并**:支持多个 Python 脚本共同生成 `model_prices_and_context_window.json`,通过优先级(Priority)实现灵活的配置覆盖。
|
|
33
|
+
- **动态计费**:内置 DeepSeek 动态时段计费(高峰/谷价切换)等示例脚本。
|
|
34
|
+
- **可视化编辑**:内置 `default.py` 可视化编辑器,支持从 Provider、Upstream 或手动录入批量配置模型。
|
|
35
|
+
- **非交互式导出**:通过 `litellmctl metadata-gen` 子命令快速构建并导出元数据 JSON 文件,便于集成到 CI/CD 流程。
|
|
36
|
+
- **环境适配**:支持配置文件目录自定义(`-D` 参数),自动初始化默认配置与示例脚本。
|
|
37
|
+
|
|
38
|
+
## 安装
|
|
39
|
+
|
|
40
|
+
```bash
|
|
41
|
+
pip install litellm-controller
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
安装后,你可以通过 `litellmctl` 命令启动工具。
|
|
45
|
+
|
|
46
|
+
## 快速开始
|
|
47
|
+
|
|
48
|
+
### 1. 初始化配置
|
|
49
|
+
首次运行时,工具会引导你配置 LiteLLM Proxy 的 Endpoint 和 API Key。
|
|
50
|
+
|
|
51
|
+
### 2. 管理模型元数据
|
|
52
|
+
进入 `3. 设置` -> `2. 模型元数据管理`:
|
|
53
|
+
- 使用 **可视化编辑器** 修改 `default.py`。
|
|
54
|
+
- 在 **脚本管理** 中启用内置的 `openrouter.py` 或 `deepseek.py` 以获取实时计费。
|
|
55
|
+
- 点击 **构建并导出**,生成 LiteLLM 可加载的 JSON。
|
|
56
|
+
|
|
57
|
+
### 3. 非交互式构建(CLI 模式)
|
|
58
|
+
如果你只想在脚本中更新定价文件:
|
|
59
|
+
```bash
|
|
60
|
+
litellmctl metadata-gen [output_directory]
|
|
61
|
+
```
|
|
62
|
+
|
|
63
|
+
## 元数据脚本规范
|
|
64
|
+
|
|
65
|
+
每个脚本位于 `$CONFIG_DIR/model_metadata/` 下,需包含以下头部配置:
|
|
66
|
+
```python
|
|
67
|
+
# --- LITELLMCTL CONFIG ---
|
|
68
|
+
NAME = "我的自定义配置"
|
|
69
|
+
DESCRIPTION = "描述文本"
|
|
70
|
+
PRIORITY = 50
|
|
71
|
+
ENABLED = True
|
|
72
|
+
# -------------------------
|
|
73
|
+
```
|
|
74
|
+
脚本需将模型字典以 JSON 格式打印至 `stdout`。
|
|
75
|
+
|
|
76
|
+
## 贡献与开发
|
|
77
|
+
|
|
78
|
+
本项目遵循 Python 3.12+ 规范,建议在虚拟环境下开发。
|
|
79
|
+
|
|
80
|
+
```bash
|
|
81
|
+
git clone ...
|
|
82
|
+
cd litellm-controller
|
|
83
|
+
python -m venv venv
|
|
84
|
+
source venv/bin/activate
|
|
85
|
+
pip install -e .
|
|
86
|
+
```
|
|
87
|
+
|
|
88
|
+
## 许可证
|
|
89
|
+
|
|
90
|
+
MIT
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
# LiteLLM Controller (litellmctl)
|
|
2
|
+
|
|
3
|
+
LiteLLM Controller 是一个功能强大的命令行界面(CLI)管理工具,专为 [LiteLLM Proxy](https://github.com/BerriAI/litellm) 设计,旨在简化模型管理、路由组配置以及模型元数据(定价与上下文窗口)的维护。
|
|
4
|
+
|
|
5
|
+
## 核心特性
|
|
6
|
+
|
|
7
|
+
- **模型管理**:交互式列出、添加、编辑、启用/禁用和删除 LiteLLM Proxy 中的模型。
|
|
8
|
+
- **路由管理**:管理模型路由组(Router Groups),支持批量清理失效模型。
|
|
9
|
+
- **脚本驱动的元数据管理**:
|
|
10
|
+
- **优先级合并**:支持多个 Python 脚本共同生成 `model_prices_and_context_window.json`,通过优先级(Priority)实现灵活的配置覆盖。
|
|
11
|
+
- **动态计费**:内置 DeepSeek 动态时段计费(高峰/谷价切换)等示例脚本。
|
|
12
|
+
- **可视化编辑**:内置 `default.py` 可视化编辑器,支持从 Provider、Upstream 或手动录入批量配置模型。
|
|
13
|
+
- **非交互式导出**:通过 `litellmctl metadata-gen` 子命令快速构建并导出元数据 JSON 文件,便于集成到 CI/CD 流程。
|
|
14
|
+
- **环境适配**:支持配置文件目录自定义(`-D` 参数),自动初始化默认配置与示例脚本。
|
|
15
|
+
|
|
16
|
+
## 安装
|
|
17
|
+
|
|
18
|
+
```bash
|
|
19
|
+
pip install litellm-controller
|
|
20
|
+
```
|
|
21
|
+
|
|
22
|
+
安装后,你可以通过 `litellmctl` 命令启动工具。
|
|
23
|
+
|
|
24
|
+
## 快速开始
|
|
25
|
+
|
|
26
|
+
### 1. 初始化配置
|
|
27
|
+
首次运行时,工具会引导你配置 LiteLLM Proxy 的 Endpoint 和 API Key。
|
|
28
|
+
|
|
29
|
+
### 2. 管理模型元数据
|
|
30
|
+
进入 `3. 设置` -> `2. 模型元数据管理`:
|
|
31
|
+
- 使用 **可视化编辑器** 修改 `default.py`。
|
|
32
|
+
- 在 **脚本管理** 中启用内置的 `openrouter.py` 或 `deepseek.py` 以获取实时计费。
|
|
33
|
+
- 点击 **构建并导出**,生成 LiteLLM 可加载的 JSON。
|
|
34
|
+
|
|
35
|
+
### 3. 非交互式构建(CLI 模式)
|
|
36
|
+
如果你只想在脚本中更新定价文件:
|
|
37
|
+
```bash
|
|
38
|
+
litellmctl metadata-gen [output_directory]
|
|
39
|
+
```
|
|
40
|
+
|
|
41
|
+
## 元数据脚本规范
|
|
42
|
+
|
|
43
|
+
每个脚本位于 `$CONFIG_DIR/model_metadata/` 下,需包含以下头部配置:
|
|
44
|
+
```python
|
|
45
|
+
# --- LITELLMCTL CONFIG ---
|
|
46
|
+
NAME = "我的自定义配置"
|
|
47
|
+
DESCRIPTION = "描述文本"
|
|
48
|
+
PRIORITY = 50
|
|
49
|
+
ENABLED = True
|
|
50
|
+
# -------------------------
|
|
51
|
+
```
|
|
52
|
+
脚本需将模型字典以 JSON 格式打印至 `stdout`。
|
|
53
|
+
|
|
54
|
+
## 贡献与开发
|
|
55
|
+
|
|
56
|
+
本项目遵循 Python 3.12+ 规范,建议在虚拟环境下开发。
|
|
57
|
+
|
|
58
|
+
```bash
|
|
59
|
+
git clone ...
|
|
60
|
+
cd litellm-controller
|
|
61
|
+
python -m venv venv
|
|
62
|
+
source venv/bin/activate
|
|
63
|
+
pip install -e .
|
|
64
|
+
```
|
|
65
|
+
|
|
66
|
+
## 许可证
|
|
67
|
+
|
|
68
|
+
MIT
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
"""LiteLLM API 客户端封装。"""
|
|
2
|
+
import requests
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
class LiteLLMError(Exception):
|
|
6
|
+
pass
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
class LiteLLMClient:
|
|
10
|
+
def __init__(self, endpoint: str, key: str, timeout: int = 30):
|
|
11
|
+
self.base_url = endpoint.rstrip("/")
|
|
12
|
+
self.timeout = timeout
|
|
13
|
+
self.session = requests.Session()
|
|
14
|
+
self.session.headers.update(
|
|
15
|
+
{
|
|
16
|
+
"Authorization": f"Bearer {key}",
|
|
17
|
+
"Content-Type": "application/json",
|
|
18
|
+
}
|
|
19
|
+
)
|
|
20
|
+
|
|
21
|
+
def _request(self, method: str, path: str, **kwargs):
|
|
22
|
+
url = self.base_url + path
|
|
23
|
+
try:
|
|
24
|
+
resp = self.session.request(method, url, timeout=self.timeout, **kwargs)
|
|
25
|
+
except requests.RequestException as e:
|
|
26
|
+
raise LiteLLMError(f"无法连接 LiteLLM: {e}") from e
|
|
27
|
+
if resp.status_code >= 400:
|
|
28
|
+
raise LiteLLMError(f"请求失败 (HTTP {resp.status_code}): {self._extract_detail(resp)}")
|
|
29
|
+
if not resp.content:
|
|
30
|
+
return {}
|
|
31
|
+
try:
|
|
32
|
+
return resp.json()
|
|
33
|
+
except ValueError as e:
|
|
34
|
+
raise LiteLLMError("响应不是有效的 JSON") from e
|
|
35
|
+
|
|
36
|
+
@staticmethod
|
|
37
|
+
def _extract_detail(resp) -> str:
|
|
38
|
+
try:
|
|
39
|
+
data = resp.json()
|
|
40
|
+
except ValueError:
|
|
41
|
+
return resp.text[:200]
|
|
42
|
+
if isinstance(data, dict):
|
|
43
|
+
for k in ("detail", "message"):
|
|
44
|
+
v = data.get(k)
|
|
45
|
+
if isinstance(v, str):
|
|
46
|
+
return v[:300]
|
|
47
|
+
error = data.get("error")
|
|
48
|
+
if isinstance(error, dict) and isinstance(error.get("message"), str):
|
|
49
|
+
return error["message"][:300]
|
|
50
|
+
if isinstance(error, str):
|
|
51
|
+
return error[:300]
|
|
52
|
+
return str(data)[:300]
|
|
53
|
+
return str(data)[:300]
|
|
54
|
+
|
|
55
|
+
def list_models(self) -> list:
|
|
56
|
+
data = self._request("GET", "/model/info")
|
|
57
|
+
return data.get("data", [])
|
|
58
|
+
|
|
59
|
+
def create_model(self, model_name: str, litellm_params: dict, model_info: dict = None):
|
|
60
|
+
body = {
|
|
61
|
+
"model_name": model_name,
|
|
62
|
+
"litellm_params": litellm_params,
|
|
63
|
+
"model_info": model_info or {},
|
|
64
|
+
}
|
|
65
|
+
return self._request("POST", "/model/new", json=body)
|
|
66
|
+
|
|
67
|
+
def update_model(self, model_id: str, **fields):
|
|
68
|
+
body = {k: v for k, v in fields.items() if v is not None}
|
|
69
|
+
return self._request("PATCH", f"/model/{model_id}/update", json=body)
|
|
70
|
+
|
|
71
|
+
def delete_model(self, model_id: str):
|
|
72
|
+
return self._request("POST", "/model/delete", json={"id": model_id})
|
|
73
|
+
|
|
74
|
+
def list_credentials(self) -> list:
|
|
75
|
+
data = self._request("GET", "/credentials")
|
|
76
|
+
return data.get("credentials", [])
|
|
77
|
+
|
|
78
|
+
def get_router_settings(self) -> dict:
|
|
79
|
+
"""GET /router/settings:返回 fields / current_values / routing_strategy_descriptions。"""
|
|
80
|
+
return self._request("GET", "/router/settings")
|
|
81
|
+
|
|
82
|
+
def update_router_settings(self, router_settings: dict):
|
|
83
|
+
"""POST /config/update:写入 router_settings(浅合并,routing_groups 需整表提交)。"""
|
|
84
|
+
return self._request("POST", "/config/update", json={"router_settings": router_settings})
|
|
85
|
+
|
|
86
|
+
def fetch_model_cost_map(self) -> dict:
|
|
87
|
+
data = self._request("GET", "/public/litellm_model_cost_map")
|
|
88
|
+
return data.get("litellm_model_cost_map", data)
|