mirror of
https://github.com/meta-llama/llama-stack.git
synced 2025-07-29 07:14:20 +00:00
add llama model subcommand
This commit is contained in:
parent
4417407652
commit
f0e0903270
5 changed files with 77 additions and 0 deletions
1
.gitignore
vendored
1
.gitignore
vendored
|
@ -1,3 +1,4 @@
|
||||||
__pycache__
|
__pycache__
|
||||||
dist
|
dist
|
||||||
*.egg-info
|
*.egg-info
|
||||||
|
dev_requirements.txt
|
||||||
|
|
|
@ -2,6 +2,7 @@ import argparse
|
||||||
|
|
||||||
from llama_toolchain.cli.download import Download
|
from llama_toolchain.cli.download import Download
|
||||||
from llama_toolchain.cli.inference.inference import InferenceParser
|
from llama_toolchain.cli.inference.inference import InferenceParser
|
||||||
|
from llama_toolchain.cli.model.model import ModelParser
|
||||||
|
|
||||||
|
|
||||||
class LlamaCLIParser:
|
class LlamaCLIParser:
|
||||||
|
@ -22,6 +23,7 @@ class LlamaCLIParser:
|
||||||
# Add sub-commands
|
# Add sub-commands
|
||||||
Download.create(subparsers)
|
Download.create(subparsers)
|
||||||
InferenceParser.create(subparsers)
|
InferenceParser.create(subparsers)
|
||||||
|
ModelParser.create(subparsers)
|
||||||
|
|
||||||
# Import sub-commands from agentic_system if they exist
|
# Import sub-commands from agentic_system if they exist
|
||||||
try:
|
try:
|
||||||
|
|
0
llama_toolchain/cli/model/__init__.py
Normal file
0
llama_toolchain/cli/model/__init__.py
Normal file
29
llama_toolchain/cli/model/model.py
Normal file
29
llama_toolchain/cli/model/model.py
Normal file
|
@ -0,0 +1,29 @@
|
||||||
|
import argparse
|
||||||
|
import textwrap
|
||||||
|
|
||||||
|
from llama_toolchain.cli.model.template import ModelTemplate
|
||||||
|
from llama_toolchain.cli.subcommand import Subcommand
|
||||||
|
|
||||||
|
|
||||||
|
class ModelParser(Subcommand):
|
||||||
|
"""Llama cli for model interface apis"""
|
||||||
|
|
||||||
|
def __init__(self, subparsers: argparse._SubParsersAction):
|
||||||
|
super().__init__()
|
||||||
|
self.parser = subparsers.add_parser(
|
||||||
|
"model",
|
||||||
|
prog="llama model",
|
||||||
|
description="Describe llama model interfaces",
|
||||||
|
epilog=textwrap.dedent(
|
||||||
|
"""
|
||||||
|
Example:
|
||||||
|
llama model <subcommand> <options>
|
||||||
|
"""
|
||||||
|
),
|
||||||
|
)
|
||||||
|
|
||||||
|
subparsers = self.parser.add_subparsers(title="model_subcommands")
|
||||||
|
|
||||||
|
# Add sub-commandsa
|
||||||
|
# ModelDescribe.create(subparsers)
|
||||||
|
ModelTemplate.create(subparsers)
|
45
llama_toolchain/cli/model/template.py
Normal file
45
llama_toolchain/cli/model/template.py
Normal file
|
@ -0,0 +1,45 @@
|
||||||
|
import argparse
|
||||||
|
import textwrap
|
||||||
|
|
||||||
|
from llama_toolchain.cli.subcommand import Subcommand
|
||||||
|
from llama_models.llama3_1.api.interface import render_jinja_template, list_jinja_templates
|
||||||
|
|
||||||
|
|
||||||
|
class ModelTemplate(Subcommand):
|
||||||
|
"""Llama model cli for describe a model template (message formats)"""
|
||||||
|
|
||||||
|
def __init__(self, subparsers: argparse._SubParsersAction):
|
||||||
|
super().__init__()
|
||||||
|
self.parser = subparsers.add_parser(
|
||||||
|
"template",
|
||||||
|
prog="llama model template",
|
||||||
|
description="Show llama model message formats",
|
||||||
|
epilog=textwrap.dedent(
|
||||||
|
"""
|
||||||
|
Example:
|
||||||
|
llama model template <options>
|
||||||
|
"""
|
||||||
|
),
|
||||||
|
formatter_class=argparse.RawTextHelpFormatter,
|
||||||
|
)
|
||||||
|
self._add_arguments()
|
||||||
|
self.parser.set_defaults(func=self._run_model_template_cmd)
|
||||||
|
|
||||||
|
def _add_arguments(self):
|
||||||
|
self.parser.add_argument(
|
||||||
|
"sku",
|
||||||
|
type=str,
|
||||||
|
help="Model SKU",
|
||||||
|
)
|
||||||
|
self.parser.add_argument(
|
||||||
|
"--template",
|
||||||
|
type=str,
|
||||||
|
help="Usecase template name (system_message, user_message, assistant_message, tool_message)...",
|
||||||
|
required=False,
|
||||||
|
)
|
||||||
|
|
||||||
|
def _run_model_template_cmd(self, args: argparse.Namespace) -> None:
|
||||||
|
if args.template:
|
||||||
|
render_jinja_template(args.template)
|
||||||
|
else:
|
||||||
|
list_jinja_templates()
|
Loading…
Add table
Add a link
Reference in a new issue