Skip to content

Commit

Permalink
Add models sub command to show info about models.
Browse files Browse the repository at this point in the history
Simplify settings sub command.
  • Loading branch information
yaph committed Jul 5, 2024
1 parent 3e7f601 commit 1b68bd4
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 9 deletions.
2 changes: 0 additions & 2 deletions charla/chat.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,9 +96,7 @@ def run(argv: argparse.Namespace) -> None:
chats_path = Path(argv.chats_path)
config.mkdir(chats_path, exist_ok=True, parents=True)
save(chats_path, output, argv.model)

print_fmt(HTML('<b>Exiting program.</b>'))
sys.exit()


def save(chats_path: Path, output: list[str], model_name: str) -> None:
Expand Down
20 changes: 17 additions & 3 deletions charla/cli.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,19 @@
#!/usr/bin/env python
import argparse
import json
import sys

from charla import chat, config
from charla.__about__ import __version__


def handle_models(argv):
if argv.verbose:
print(json.dumps(argv.models, indent=4))
else:
print('\n'.join(argv.model_names))


def main():
if (models := chat.available_models()) is None:
sys.exit('No language models available.')
Expand All @@ -14,19 +22,25 @@ def main():
user_settings = config.settings()
user_settings['model'] = user_settings['model'] or model_names[0]

parent = argparse.ArgumentParser(add_help=False)
parent.add_argument('--verbose', '-v', action='store_true', help='Verbose program output.')

parser = argparse.ArgumentParser(description='Chat with local language models.')
parser.add_argument('--model', '-m', nargs=1, choices=model_names, action='store', help='Language model to chat with.')
parser.add_argument('--model', '-m', nargs=1, metavar='MODEL', choices=model_names, action='store', help='Name of language model to chat with.')
parser.add_argument('--chats-path', type=str, help='Directory to store chats.')
parser.add_argument('--prompt-history', type=str, help='File to store prompt history.')
parser.add_argument('--version', action='version', version=f'%(prog)s {__version__}')
parser.set_defaults(**user_settings, func=chat.run)

subparsers = parser.add_subparsers(help='Sub Commands')
parser_settings = subparsers.add_parser('settings', help='Manage Charla settings')
parser_settings.add_argument('--show', action='store_true', help='Show current settings.')

parser_settings = subparsers.add_parser('settings', help='Show current settings.')
parser_settings.add_argument('--location', action='store_true', help='Show location of settings file.')
parser_settings.set_defaults(func=config.manage)

parser_models = subparsers.add_parser('models', parents=[parent], help='Show available models.')
parser_models.set_defaults(func=handle_models, models=models, model_names=model_names)

argv = parser.parse_args()

# Make sure model is installed
Expand Down
7 changes: 3 additions & 4 deletions charla/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,8 @@ def settings() -> dict[str, str]:


def manage(argv: argparse.Namespace) -> None:
if argv.show:
user_settings = {k: v for k, v in vars(argv).items() if k in default_settings}
print(json.dumps(user_settings, indent=4))
if argv.location:
print(path_settings)
sys.exit()
else:
user_settings = {k: v for k, v in vars(argv).items() if k in default_settings}
print(json.dumps(user_settings, indent=4))

0 comments on commit 1b68bd4

Please sign in to comment.