cometapi-cli 0.2.0__py3-none-any.whl → 0.2.1__py3-none-any.whl
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.
- cometapi_cli/__init__.py +1 -1
- cometapi_cli/commands/models.py +57 -6
- {cometapi_cli-0.2.0.dist-info → cometapi_cli-0.2.1.dist-info}/METADATA +6 -10
- {cometapi_cli-0.2.0.dist-info → cometapi_cli-0.2.1.dist-info}/RECORD +7 -7
- {cometapi_cli-0.2.0.dist-info → cometapi_cli-0.2.1.dist-info}/WHEEL +0 -0
- {cometapi_cli-0.2.0.dist-info → cometapi_cli-0.2.1.dist-info}/entry_points.txt +0 -0
- {cometapi_cli-0.2.0.dist-info → cometapi_cli-0.2.1.dist-info}/licenses/LICENSE +0 -0
cometapi_cli/__init__.py
CHANGED
cometapi_cli/commands/models.py
CHANGED
|
@@ -2,6 +2,8 @@
|
|
|
2
2
|
|
|
3
3
|
from __future__ import annotations
|
|
4
4
|
|
|
5
|
+
import re
|
|
6
|
+
from functools import cmp_to_key
|
|
5
7
|
from typing import Annotated
|
|
6
8
|
|
|
7
9
|
import typer
|
|
@@ -10,13 +12,63 @@ from ..config import get_client
|
|
|
10
12
|
from ..errors import handle_errors
|
|
11
13
|
from ..formatters import OutputFormat, output, resolve_format
|
|
12
14
|
|
|
15
|
+
_MODEL_TOKEN_RE = re.compile(r"[a-z]+|\d+")
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
def _tokenize_model_id(model_id: str) -> list[str | int]:
|
|
19
|
+
tokens: list[str | int] = []
|
|
20
|
+
for segment in re.split(r"[-.]+", model_id.lower()):
|
|
21
|
+
if not segment:
|
|
22
|
+
continue
|
|
23
|
+
for part in _MODEL_TOKEN_RE.findall(segment):
|
|
24
|
+
tokens.append(int(part) if part.isdigit() else part)
|
|
25
|
+
return tokens
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
def _compare_model_ids(left: str, right: str) -> int:
|
|
29
|
+
left_tokens = _tokenize_model_id(left)
|
|
30
|
+
right_tokens = _tokenize_model_id(right)
|
|
31
|
+
|
|
32
|
+
for left_token, right_token in zip(left_tokens, right_tokens):
|
|
33
|
+
if left_token == right_token:
|
|
34
|
+
continue
|
|
35
|
+
|
|
36
|
+
if isinstance(left_token, int) and isinstance(right_token, int):
|
|
37
|
+
return -1 if left_token > right_token else 1
|
|
38
|
+
|
|
39
|
+
if isinstance(left_token, int):
|
|
40
|
+
return -1
|
|
41
|
+
if isinstance(right_token, int):
|
|
42
|
+
return 1
|
|
43
|
+
|
|
44
|
+
return -1 if left_token > right_token else 1
|
|
45
|
+
|
|
46
|
+
if len(left_tokens) == len(right_tokens):
|
|
47
|
+
if left.lower() == right.lower():
|
|
48
|
+
return 0
|
|
49
|
+
return -1 if left.lower() > right.lower() else 1
|
|
50
|
+
|
|
51
|
+
if len(left_tokens) < len(right_tokens):
|
|
52
|
+
next_token = right_tokens[len(left_tokens)]
|
|
53
|
+
return 1 if isinstance(next_token, int) else -1
|
|
54
|
+
|
|
55
|
+
next_token = left_tokens[len(right_tokens)]
|
|
56
|
+
return -1 if isinstance(next_token, int) else 1
|
|
57
|
+
|
|
58
|
+
|
|
59
|
+
def _compare_model_rows(left: dict[str, str], right: dict[str, str]) -> int:
|
|
60
|
+
return _compare_model_ids(left["id"], right["id"])
|
|
61
|
+
|
|
13
62
|
|
|
14
63
|
@handle_errors
|
|
15
64
|
def models(
|
|
16
65
|
ctx: typer.Context,
|
|
17
66
|
search: Annotated[str | None, typer.Option("--search", "-s", help="Filter models by name.")] = None,
|
|
18
67
|
limit: Annotated[int | None, typer.Option("--limit", "-l", help="Max number of models to show.")] = None,
|
|
19
|
-
output_format: Annotated[
|
|
68
|
+
output_format: Annotated[
|
|
69
|
+
OutputFormat | None,
|
|
70
|
+
typer.Option("--format", "-f", help="Output format (table, json, yaml, csv, markdown)."),
|
|
71
|
+
] = None,
|
|
20
72
|
json_output: Annotated[bool, typer.Option("--json", help="Output as JSON.")] = False,
|
|
21
73
|
) -> None:
|
|
22
74
|
"""List available models."""
|
|
@@ -24,15 +76,14 @@ def models(
|
|
|
24
76
|
client = get_client()
|
|
25
77
|
result = client.models.list()
|
|
26
78
|
|
|
27
|
-
rows =
|
|
28
|
-
[{"id": m.id, "owned_by": m.owned_by} for m in result],
|
|
29
|
-
key=lambda r: r["id"],
|
|
30
|
-
)
|
|
79
|
+
rows = [{"id": m.id} for m in result]
|
|
31
80
|
|
|
32
81
|
if search:
|
|
33
82
|
term = search.lower()
|
|
34
83
|
rows = [r for r in rows if term in r["id"].lower()]
|
|
35
84
|
|
|
85
|
+
rows = sorted(rows, key=cmp_to_key(_compare_model_rows))
|
|
86
|
+
|
|
36
87
|
if limit and limit > 0:
|
|
37
88
|
rows = rows[:limit]
|
|
38
89
|
|
|
@@ -40,5 +91,5 @@ def models(
|
|
|
40
91
|
rows,
|
|
41
92
|
fmt,
|
|
42
93
|
title=f"Available Models ({len(rows)})",
|
|
43
|
-
columns={"id": "cyan"
|
|
94
|
+
columns={"id": "cyan"},
|
|
44
95
|
)
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: cometapi-cli
|
|
3
|
-
Version: 0.2.
|
|
3
|
+
Version: 0.2.1
|
|
4
4
|
Summary: CometAPI CLI — official command-line interface for the CometAPI AI gateway
|
|
5
5
|
Project-URL: Homepage, https://github.com/cometapi-dev/cometapi-cli
|
|
6
6
|
Project-URL: Repository, https://github.com/cometapi-dev/cometapi-cli
|
|
@@ -42,7 +42,7 @@ Description-Content-Type: text/markdown
|
|
|
42
42
|
[](https://pypi.org/project/cometapi-cli/)
|
|
43
43
|
[](LICENSE)
|
|
44
44
|
|
|
45
|
-
> **Official command-line interface for [CometAPI](https://cometapi.com)** — 500+ AI Model API, All In One API.
|
|
45
|
+
> **Official command-line interface for [CometAPI](https://www.cometapi.com/?utm_source=cometapi-cli&utm_medium=readme&utm_campaign=oss&utm_content=homepage)** — 500+ AI Model API, All In One API.
|
|
46
46
|
|
|
47
47
|
Access 500+ AI models at low cost, directly from the terminal. Chat, search models, check usage, and manage your account — all through a single API key.
|
|
48
48
|
|
|
@@ -59,7 +59,7 @@ pipx install cometapi-cli # isolated environment
|
|
|
59
59
|
uv tool install cometapi-cli # uv
|
|
60
60
|
```
|
|
61
61
|
|
|
62
|
-
**Prerequisites**: Python 3.10+ · [
|
|
62
|
+
**Prerequisites**: Python 3.10+ · [CometAPI Key](https://www.cometapi.com/console/token?utm_source=cometapi-cli&utm_medium=readme&utm_campaign=oss&utm_content=prerequisites)
|
|
63
63
|
|
|
64
64
|
## Quick Start
|
|
65
65
|
|
|
@@ -77,8 +77,8 @@ cometapi models --search gpt --limit 10
|
|
|
77
77
|
Or configure manually:
|
|
78
78
|
|
|
79
79
|
```bash
|
|
80
|
-
export COMETAPI_KEY="your-api-key" # https://www.cometapi.com/console/token
|
|
81
|
-
export COMETAPI_ACCESS_TOKEN="your-access-token" # https://www.cometapi.com/console/personal (optional)
|
|
80
|
+
export COMETAPI_KEY="your-api-key" # https://www.cometapi.com/console/token?utm_source=cometapi-cli&utm_medium=readme&utm_campaign=oss&utm_content=env-api-key
|
|
81
|
+
export COMETAPI_ACCESS_TOKEN="your-access-token" # https://www.cometapi.com/console/personal?utm_source=cometapi-cli&utm_medium=readme&utm_campaign=oss&utm_content=env-access-token (optional)
|
|
82
82
|
```
|
|
83
83
|
|
|
84
84
|
## Commands
|
|
@@ -226,7 +226,7 @@ pytest -v
|
|
|
226
226
|
- API keys and access tokens are **never** logged or displayed in full — only the last 4 characters are shown
|
|
227
227
|
- Config files are stored with restrictive permissions (`0600`)
|
|
228
228
|
- Credentials should **never** be committed to version control
|
|
229
|
-
- Create credentials at: [API Key](https://www.cometapi.com/console/token) · [Access Token](https://www.cometapi.com/console/personal)
|
|
229
|
+
- Create credentials at: [API Key](https://www.cometapi.com/console/token?utm_source=cometapi-cli&utm_medium=readme&utm_campaign=oss&utm_content=security-api-key) · [Access Token](https://www.cometapi.com/console/personal?utm_source=cometapi-cli&utm_medium=readme&utm_campaign=oss&utm_content=security-access-token)
|
|
230
230
|
- **Disclaimer**: You are responsible for all usage and charges incurred with your API keys
|
|
231
231
|
|
|
232
232
|
## Troubleshooting
|
|
@@ -244,7 +244,3 @@ Contributions are welcome! See [CONTRIBUTING.md](CONTRIBUTING.md) for guidelines
|
|
|
244
244
|
## License
|
|
245
245
|
|
|
246
246
|
This project is licensed under the [MIT License](LICENSE).
|
|
247
|
-
|
|
248
|
-
## License
|
|
249
|
-
|
|
250
|
-
MIT
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
cometapi_cli/__init__.py,sha256=
|
|
1
|
+
cometapi_cli/__init__.py,sha256=PO4EJzXB-LMrMP41BGu4Cp0YrCXOG2oWfHl8uVdCw6Q,92
|
|
2
2
|
cometapi_cli/app.py,sha256=tFrkyfVVBYkjOA9zXP72bZ1csHI9HBnGF-Z4_4EkXkE,2784
|
|
3
3
|
cometapi_cli/client.py,sha256=4JkMSrjWwAQV8tmlwplZQ75gzt3zHno8ASKLgMCpYkU,9658
|
|
4
4
|
cometapi_cli/config.py,sha256=oJXQidKCOsKNYPnE8OfLLoOfsv0MSZEDICB6VShJRSA,3307
|
|
@@ -15,13 +15,13 @@ cometapi_cli/commands/chat_repl.py,sha256=b9lkYnbbaOb0AlSpRcq3wWHmnhtTXvaqeJiUIm
|
|
|
15
15
|
cometapi_cli/commands/config_cmd.py,sha256=JU4ZS8ur2Sq1MjMZKaGLaI1TdM3CAUDE45qsKDOxD_8,8528
|
|
16
16
|
cometapi_cli/commands/doctor.py,sha256=EPcezrf64yzgYrzOdp_7tvfNM6hE2NBDzgMgO-O0Dnw,5337
|
|
17
17
|
cometapi_cli/commands/logs.py,sha256=9J7oT9KbCCGeD_zO9fwWj7g5QjaoT8qqJF_e81jGPX4,10310
|
|
18
|
-
cometapi_cli/commands/models.py,sha256=
|
|
18
|
+
cometapi_cli/commands/models.py,sha256=wtnZp0RqUE6HH2ZsZr6OYtHDwzUPIOcJBBxXWKOQ-Ig,2875
|
|
19
19
|
cometapi_cli/commands/repl.py,sha256=b5z1jmEXOsCrb6fwEUyv-IKot929NIPQQAbA1uas1D4,4283
|
|
20
20
|
cometapi_cli/commands/stats.py,sha256=6ULBb7rX5Q0yWuIxtYLataNPoJ_SkU3Y4RovgdVyROs,1388
|
|
21
21
|
cometapi_cli/commands/tasks.py,sha256=TW_Jgli7iyfIoHNyufbViAUMIieMNfsD8DMHt5mQA8Q,4625
|
|
22
22
|
cometapi_cli/commands/tokens.py,sha256=9KHer9MQOZvm_Ybxnhjb5_TtGgKyv3MtI5lqsHy-Qxg,3019
|
|
23
|
-
cometapi_cli-0.2.
|
|
24
|
-
cometapi_cli-0.2.
|
|
25
|
-
cometapi_cli-0.2.
|
|
26
|
-
cometapi_cli-0.2.
|
|
27
|
-
cometapi_cli-0.2.
|
|
23
|
+
cometapi_cli-0.2.1.dist-info/METADATA,sha256=S_Gkmso14ZIEFTdRT4Hb57UVZxTh69fintCJ0ZQDKwE,8624
|
|
24
|
+
cometapi_cli-0.2.1.dist-info/WHEEL,sha256=QccIxa26bgl1E6uMy58deGWi-0aeIkkangHcxk2kWfw,87
|
|
25
|
+
cometapi_cli-0.2.1.dist-info/entry_points.txt,sha256=xoiE2ZVNNWXTq0JRBtzC8hJ2JkdKuaBNz_fEd8OJpLs,50
|
|
26
|
+
cometapi_cli-0.2.1.dist-info/licenses/LICENSE,sha256=-rBwHQzkmLbty07abmGvQvsRrvDeEQUkPDhNJfTcjdE,1065
|
|
27
|
+
cometapi_cli-0.2.1.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|
|
File without changes
|