mirror of
https://github.com/Hopiu/llm.git
synced 2026-05-05 04:14:53 +00:00
llm aliases list --json option, refs #151
This commit is contained in:
parent
4db949bae8
commit
b8f8869778
3 changed files with 41 additions and 1 deletions
|
|
@ -3,6 +3,8 @@
|
|||
|
||||
LLM supports model aliases, which allow you to refer to a model by a short name instead of its full ID.
|
||||
|
||||
## Listing aliases
|
||||
|
||||
To list current aliases, run this:
|
||||
|
||||
```bash
|
||||
|
|
@ -26,3 +28,21 @@ gpt4 : gpt-4
|
|||
4-32k : gpt-4-32k
|
||||
```
|
||||
<!-- [[[end]]] -->
|
||||
|
||||
Add `--json` to get that list back as JSON:
|
||||
|
||||
```bash
|
||||
llm aliases list --json
|
||||
```
|
||||
Example output:
|
||||
```json
|
||||
{
|
||||
"3.5": "gpt-3.5-turbo",
|
||||
"chatgpt": "gpt-3.5-turbo",
|
||||
"chatgpt-16k": "gpt-3.5-turbo-16k",
|
||||
"3.5-16k": "gpt-3.5-turbo-16k",
|
||||
"4": "gpt-4",
|
||||
"gpt4": "gpt-4",
|
||||
"4-32k": "gpt-4-32k"
|
||||
}
|
||||
```
|
||||
|
|
|
|||
|
|
@ -560,12 +560,16 @@ def aliases():
|
|||
|
||||
|
||||
@aliases.command(name="list")
|
||||
def aliases_list():
|
||||
@click.option("json_", "--json", is_flag=True, help="Output as JSON")
|
||||
def aliases_list(json_):
|
||||
"List current aliases"
|
||||
to_output = []
|
||||
for alias, model in get_model_aliases().items():
|
||||
if alias != model.model_id:
|
||||
to_output.append((alias, model.model_id))
|
||||
if json_:
|
||||
click.echo(json.dumps({key: value for key, value in to_output}, indent=4))
|
||||
return
|
||||
max_alias_length = max(len(a) for a, _ in to_output)
|
||||
fmt = "{alias:<" + str(max_alias_length) + "} : {model_id}"
|
||||
for alias, model_id in to_output:
|
||||
|
|
|
|||
|
|
@ -1,5 +1,6 @@
|
|||
from click.testing import CliRunner
|
||||
from llm.cli import cli
|
||||
import json
|
||||
|
||||
|
||||
def test_aliases_list():
|
||||
|
|
@ -15,3 +16,18 @@ def test_aliases_list():
|
|||
"gpt4 : gpt-4\n"
|
||||
"4-32k : gpt-4-32k\n"
|
||||
)
|
||||
|
||||
|
||||
def test_aliases_list_json():
|
||||
runner = CliRunner()
|
||||
result = runner.invoke(cli, ["aliases", "list", "--json"])
|
||||
assert result.exit_code == 0
|
||||
assert json.loads(result.output) == {
|
||||
"3.5": "gpt-3.5-turbo",
|
||||
"chatgpt": "gpt-3.5-turbo",
|
||||
"chatgpt-16k": "gpt-3.5-turbo-16k",
|
||||
"3.5-16k": "gpt-3.5-turbo-16k",
|
||||
"4": "gpt-4",
|
||||
"gpt4": "gpt-4",
|
||||
"4-32k": "gpt-4-32k",
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue