diff --git a/README.md b/README.md index 8b1665f..27aad84 100644 --- a/README.md +++ b/README.md @@ -44,7 +44,7 @@ cd python-gpt-po python3 -m venv .venv source .venv/bin/activate pip install -r requirements.txt -python -m python_gpt_po.main --folder test --lang nl --bulk --provider="deepseek" --list-models +python -m python_gpt_po.main --provider="deepseek" --list-models ``` ## API Key Configuration @@ -96,6 +96,8 @@ For a detailed explanation of all available parameters and a deep dive into the - `--bulk`: Enable bulk translation mode. - `--bulksize`: Set the number of entries per bulk translation (default is 50). - `--model`: Specify the translation model (defaults are provider-specific). +- `--provider`: Specify the AI provider (openai, anthropic, or deepseek). +- `--list-models`: List available models for the selected provider. This is the only command that can be used without `--folder` and `--lang`. - `--api_key`: API key for translation; can also be provided via environment variable. - `--folder-language`: Infer the target language from the folder structure. @@ -186,7 +188,7 @@ docker run -v $(pwd):/data -e OPENAI_API_KEY="your_key" ghcr.io/pescheckit/pytho # Use a specific Python version (3.12) docker run -v $(pwd):/data -e OPENAI_API_KEY="your_key" ghcr.io/pescheckit/python-gpt-po:latest-py3.12 --folder /data --lang fr -# List available models +# List available models (no need for --folder or --lang) docker run -e OPENAI_API_KEY="your_key" ghcr.io/pescheckit/python-gpt-po:latest --provider openai --list-models ``` diff --git a/docker-entrypoint.sh b/docker-entrypoint.sh index 6e0c7a3..6d9d3e2 100644 --- a/docker-entrypoint.sh +++ b/docker-entrypoint.sh @@ -27,6 +27,9 @@ if [ $# -eq 0 ]; then echo " # MacOS example" echo " docker run -v /Users/username/Documents/translations:/input -e OPENAI_API_KEY= ghcr.io/pescheckit/python-gpt-po --folder /input --lang fr,es" echo + echo " # List available models (no need for --folder or --lang)" + echo " docker run -e OPENAI_API_KEY= ghcr.io/pescheckit/python-gpt-po --provider openai --list-models" + echo echo "For full documentation, visit: https://github.com/pescheckit/python-gpt-po" exit 0 fi diff --git a/docs/usage.md b/docs/usage.md index 704beab..caf72ae 100644 --- a/docs/usage.md +++ b/docs/usage.md @@ -139,8 +139,8 @@ Below is a detailed explanation of all command-line arguments: *Behind the scenes:* The chosen model is passed along to the provider’s API calls. If the model is not available, a warning is logged and the default is used. - **`--list-models`** - *Description:* Lists all available models for the selected provider and exits without processing any files. - *Behind the scenes:* Makes a test API call to retrieve a list of models and prints them to the console. + *Description:* Lists all available models for the selected provider and exits without processing any files. This is the only command that doesn't require `--folder` and `--lang` parameters. + *Behind the scenes:* Makes a test API call to retrieve a list of models and prints them to the console. When this flag is provided, the CLI parser automatically makes the usually required parameters optional. - **`--openai-key`** *Description:* Provides the OpenAI API key directly as a command-line argument (alternative to using `--api_key` or the environment variable). diff --git a/python_gpt_po/utils/cli.py b/python_gpt_po/utils/cli.py index 11b0591..0e145d8 100644 --- a/python_gpt_po/utils/cli.py +++ b/python_gpt_po/utils/cli.py @@ -36,21 +36,28 @@ def parse_args(): Returns: argparse.Namespace: Parsed arguments """ + # First pass - check if list-models is in args + # This allows us to make folder and lang not required when listing models + list_models_present = False + for arg in sys.argv: + if arg in ("--list-models", "--version"): + list_models_present = True + break parser = CustomArgumentParser( description="Translate .po files using AI language models", epilog=""" Examples: # Basic usage with OpenAI - python po_translator.py --folder ./locales --lang fr,es,de + gpt-po-translator --folder ./locales --lang fr,es,de # Use Anthropic with detailed language names - python po_translator.py --folder ./i18n --lang nl,de --detail-lang "Dutch,German" --provider anthropic + gpt-po-translator --folder ./i18n --lang nl,de --detail-lang "Dutch,German" --provider anthropic - # List available models for a provider - python po_translator.py --provider deepseek --list-models + # List available models for a provider (no need for --folder or --lang) + gpt-po-translator --provider deepseek --list-models # Process multiple translations in bulk with a specific model - python po_translator.py --folder ./locales --lang ja,ko --bulk --model gpt-4 + gpt-po-translator --folder ./locales --lang ja,ko --bulk --model gpt-4 """, formatter_class=lambda prog: argparse.RawDescriptionHelpFormatter(prog, max_help_position=35, width=100) ) @@ -62,16 +69,16 @@ def parse_args(): api_group = parser.add_argument_group('API Keys') advanced_group = parser.add_argument_group('Advanced Options') - # Required arguments + # Required arguments (not required if listing models) required_group.add_argument( "-f", "--folder", - required=True, + required=(not list_models_present), metavar="FOLDER", help="Input folder containing .po files" ) required_group.add_argument( "-l", "--lang", - required=True, + required=(not list_models_present), metavar="LANG", help="Comma-separated language codes to translate (e.g., fr,es,de)" )