parent
4f39f4fe0a
commit
466f27a714
@ -1,75 +1,53 @@
|
||||
import argparse
|
||||
import sys
|
||||
from swarms.agents.simple_agent import SimpleAgent, get_llm_by_name
|
||||
|
||||
|
||||
def cli():
|
||||
parser = argparse.ArgumentParser(description="Swarms CLI")
|
||||
parser.add_argument(
|
||||
"file_name", help="Python file containing Swarms code to run"
|
||||
)
|
||||
# Help message for the -h flag is automatically generated by argparse
|
||||
parser.add_argument(
|
||||
"-v", "--version", action="version", version="%(prog)s 0.1.0"
|
||||
def main():
|
||||
parser = argparse.ArgumentParser(
|
||||
prog="swarms",
|
||||
description=(
|
||||
"Run the SimpleAgent with a specified language model."
|
||||
),
|
||||
)
|
||||
subparsers = parser.add_subparsers(dest="command")
|
||||
|
||||
# Check deployments for a given model
|
||||
parser.add_argument(
|
||||
"-c", "--check", help="Check deployments for a given agent"
|
||||
run_parser = subparsers.add_parser(
|
||||
"run", help="Run the SimpleAgent."
|
||||
)
|
||||
|
||||
# Generate an API key for a given agent
|
||||
parser.add_argument(
|
||||
"-g",
|
||||
"--generate",
|
||||
help="Generate an API key for a given agent",
|
||||
run_parser.add_argument(
|
||||
"modelname",
|
||||
type=str,
|
||||
help="The name of the language model to use.",
|
||||
)
|
||||
|
||||
# Signin to swarms with a given API key
|
||||
parser.add_argument(
|
||||
"-s", "--signin", help="Signin to swarms with a given API key"
|
||||
run_parser.add_argument(
|
||||
"--iters",
|
||||
type=int,
|
||||
default="automatic",
|
||||
help=(
|
||||
'Number of iterations or "automatic" for infinite loop.'
|
||||
' Defaults to "automatic".'
|
||||
),
|
||||
)
|
||||
|
||||
# Signout of swarms
|
||||
parser.add_argument("-o", "--signout", help="Signout of swarms")
|
||||
|
||||
# List all agents
|
||||
parser.add_argument("-l", "--list", help="List all agents")
|
||||
|
||||
# List all deployments
|
||||
parser.add_argument(
|
||||
"-d", "--deployments", help="List all deployments"
|
||||
# Add a help command
|
||||
help_parser = subparsers.add_parser(
|
||||
"help", help="Show this help message and exit."
|
||||
)
|
||||
help_parser.set_defaults(func=lambda args: parser.print_help())
|
||||
|
||||
# Pricing information
|
||||
parser.add_argument("-p", "--pricing", help="Pricing information")
|
||||
|
||||
# Run a deployment
|
||||
parser.add_argument("-r", "--run", help="Run a deployment")
|
||||
|
||||
# Stop a deployment
|
||||
parser.add_argument("-t", "--stop", help="Stop a deployment")
|
||||
|
||||
# Delete a deployment
|
||||
parser.add_argument("-x", "--delete", help="Delete a deployment")
|
||||
|
||||
# Get a deployment
|
||||
parser.add_argument("-e", "--get", help="Get a deployment")
|
||||
args = parser.parse_args()
|
||||
|
||||
# Get a deployment's logs
|
||||
parser.add_argument(
|
||||
"-z", "--logs", help="Get a deployment's logs"
|
||||
)
|
||||
if hasattr(args, "func"):
|
||||
args.func(args)
|
||||
elif args.command == "run":
|
||||
llm = get_llm_by_name(args.modelname)
|
||||
if llm is None:
|
||||
raise ValueError(
|
||||
"No language model found with name"
|
||||
f" '{args.modelname}'"
|
||||
)
|
||||
SimpleAgent(llm, iters=args.iters)
|
||||
|
||||
# Parse the arguments
|
||||
args = parser.parse_args()
|
||||
|
||||
# Execute the specified file
|
||||
try:
|
||||
with open(args.file_name, "r") as file:
|
||||
exec(file.read(), globals())
|
||||
except FileNotFoundError:
|
||||
print(f"Error: File '{args.file_name}' not found.")
|
||||
sys.exit(1)
|
||||
except Exception as e:
|
||||
print(f"Error executing file '{args.file_name}': {e}")
|
||||
sys.exit(1)
|
||||
# if __name__ == "__main__":
|
||||
# main()
|
||||
|
@ -0,0 +1,12 @@
|
||||
from swarms.tokenizers.r_tokenizers import (
|
||||
SentencePieceTokenizer,
|
||||
HuggingFaceTokenizer,
|
||||
Tokenizer,
|
||||
)
|
||||
|
||||
|
||||
__all__ = [
|
||||
"SentencePieceTokenizer",
|
||||
"HuggingFaceTokenizer",
|
||||
"Tokenizer",
|
||||
]
|
Loading…
Reference in new issue