-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
12 changed files
with
577 additions
and
59 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
# ONE API URL | ||
ONE_API_BASE_URL= | ||
|
||
# ACCESS TOKEN at https://{one-api-url}/panel/profile | ||
ONE_API_ACCESS_TOKEN= | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,171 @@ | ||
{ | ||
"cells": [ | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"# 导入变量,或者从环境变量中加载\n", | ||
"from dotenv import load_dotenv\n", | ||
"load_dotenv(override=True)" | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"metadata": {}, | ||
"source": [ | ||
"## 用户管理" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"from one_api_cli import get_users, get_user, update_user, delete_user, create_user" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"# 查看用户\n", | ||
"users = get_users()\n", | ||
"for user in users:\n", | ||
" print(user['id'], user['username'])\n", | ||
"print(get_user(1))\n", | ||
"print(get_user(100)) # 不存在的用户" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"# 新增用户\n", | ||
"username = \"test2\"\n", | ||
"display_name = \"test\"\n", | ||
"password = \"complicated_password\"\n", | ||
"create_user(username, display_name, password)" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"# 修改用户信息\n", | ||
"username = \"test2\"\n", | ||
"new_password = \"new_password_233\"\n", | ||
"update_user(username, password=new_password) # 也可以指定 ID" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"# 删除用户\n", | ||
"delete_user(username) # 或使用 ID" | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"metadata": {}, | ||
"source": [ | ||
"## 渠道管理" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"from one_api_cli import get_channels, get_channel, create_channel, update_channel, delete_channel" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"# 查看频道\n", | ||
"channels = get_channels()\n", | ||
"for channel in channels:\n", | ||
" print(channel['id'], channel['name'])\n", | ||
"print(get_channel(1))\n", | ||
"print(get_channel(100)) # 不存在的频道" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"# 新增频道\n", | ||
"name = \"test_channel\"\n", | ||
"create_channel(name, 'sk-123', 'https://api.openai.com', 'gpt-test')" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"# 修改频道信息\n", | ||
"channel_id = [channel['id'] for channel in channels if channel['name'] == name][0]\n", | ||
"new_name = \"new_channel\"\n", | ||
"update_channel(channel_id, name=new_name)" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"# 删除频道\n", | ||
"delete_channel(channel_id)" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [] | ||
} | ||
], | ||
"metadata": { | ||
"kernelspec": { | ||
"display_name": "base", | ||
"language": "python", | ||
"name": "python3" | ||
}, | ||
"language_info": { | ||
"codemirror_mode": { | ||
"name": "ipython", | ||
"version": 3 | ||
}, | ||
"file_extension": ".py", | ||
"mimetype": "text/x-python", | ||
"name": "python", | ||
"nbconvert_exporter": "python", | ||
"pygments_lexer": "ipython3", | ||
"version": "3.9.13" | ||
} | ||
}, | ||
"nbformat": 4, | ||
"nbformat_minor": 2 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
[project] | ||
name = "one-api-cli" | ||
version = "0.1.0" | ||
authors = [ | ||
{ name="Rex Wang", email="[email protected]" }, | ||
] | ||
description = "A CLI tool for the One API project." | ||
keywords = ["oneapi", "cli", "tool"] | ||
readme = "README.md" | ||
license = { file = "LICENSE" } | ||
requires-python = ">=3.9,<3.12" | ||
classifiers = [ | ||
"Programming Language :: Python :: 3", | ||
"License :: OSI Approved :: MIT License", | ||
"Operating System :: MacOS", | ||
"Operating System :: POSIX :: Linux", | ||
] | ||
dependencies = [ | ||
"loguru", | ||
"click", | ||
"requests" | ||
] | ||
|
||
[project.optional-dependencies] | ||
dev = [ | ||
"ipython", | ||
"notebook", | ||
] | ||
test = [ | ||
"pytest", | ||
] | ||
docs = [ | ||
"sphinx", | ||
"sphinx-rtd-theme", | ||
] | ||
lint = [ | ||
"mypy", | ||
] | ||
all = [ | ||
"ipython", | ||
"notebook", | ||
"pytest", | ||
"sphinx", | ||
"sphinx-rtd-theme", | ||
"mypy", | ||
] | ||
|
||
[project.urls] | ||
"Bug Tracker" = "https://github.com/rexwzh/one-api-cli/issues" | ||
|
||
[tool.pytest.ini_options] | ||
addopts = [ | ||
"--import-mode=importlib", | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,9 @@ | ||
pip==19.2.3 | ||
bump2version==0.5.11 | ||
wheel==0.33.6 | ||
watchdog==0.9.0 | ||
flake8==3.7.8 | ||
tox==3.14.0 | ||
coverage==4.5.4 | ||
coverage | ||
Sphinx==1.8.5 | ||
twine==1.14.0 | ||
pytest==6.2.4 |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
"""Top-level package for one-api-cli.""" | ||
|
||
__author__ = """Rex Wang""" | ||
__email__ = '[email protected]' | ||
__version__ = '0.1.0' | ||
|
||
from .account import get_users, update_user, get_user, create_user, delete_user | ||
from .channel import get_channels, update_channel, delete_channel, create_channel, get_channel |
Oops, something went wrong.