Initial upload: Local LLM Prompt Manager CLI tool
This commit is contained in:
68
src/commands/config.py
Normal file
68
src/commands/config.py
Normal file
@@ -0,0 +1,68 @@
|
||||
"""Configuration CLI commands."""
|
||||
|
||||
from typing import Optional
|
||||
|
||||
import click
|
||||
|
||||
from ..config import ConfigManager
|
||||
from ..llm import LLMClientFactory
|
||||
|
||||
|
||||
@click.group()
|
||||
def config_cmd():
|
||||
"""Manage configuration."""
|
||||
pass
|
||||
|
||||
|
||||
@config_cmd.command("show")
|
||||
def show_config():
|
||||
"""Show current configuration."""
|
||||
from rich.console import Console
|
||||
from rich.table import Table
|
||||
|
||||
manager = ConfigManager()
|
||||
config = manager.load()
|
||||
|
||||
table = Table(title="Configuration")
|
||||
table.add_column("Setting", style="cyan")
|
||||
table.add_column("Value", style="green")
|
||||
|
||||
for key, value in config.to_dict().items():
|
||||
table.add_row(key, str(value))
|
||||
|
||||
console = Console()
|
||||
console.print(table)
|
||||
|
||||
|
||||
@config_cmd.command("set")
|
||||
@click.argument("key")
|
||||
@click.argument("value")
|
||||
def set_config(key: str, value: str):
|
||||
"""Set a configuration value."""
|
||||
manager = ConfigManager()
|
||||
|
||||
valid_keys = ["prompt_dir", "ollama_url", "lmstudio_url", "default_model", "default_provider"]
|
||||
|
||||
if key not in valid_keys:
|
||||
click.echo(f"Invalid key: {key}", err=True)
|
||||
click.echo(f"Valid keys: {', '.join(valid_keys)}", err=True)
|
||||
return
|
||||
|
||||
manager.set(key, value)
|
||||
click.echo(f"Set {key} = {value}")
|
||||
|
||||
|
||||
@config_cmd.command("test")
|
||||
@click.option("--provider", default=None, help="Provider to test")
|
||||
def test_connection(provider: Optional[str]):
|
||||
"""Test LLM connection."""
|
||||
client = LLMClientFactory.create(provider=provider)
|
||||
|
||||
if client.test_connection():
|
||||
models = client.get_available_models()
|
||||
click.echo("Connection successful!")
|
||||
if models:
|
||||
click.echo(f"Available models: {', '.join(models[:5])}")
|
||||
else:
|
||||
click.echo("Connection failed", err=True)
|
||||
click.echo("Ensure the LLM service is running and check the API URL", err=True)
|
||||
Reference in New Issue
Block a user