Skip to content

Commit 51665a4

Browse files
Merge pull request #37 from pescheckit/hotfix_fixed-issue-with-list-providers
Fixed issue with list providers
2 parents ae4ef60 + 213ae8d commit 51665a4

File tree

4 files changed

+24
-12
lines changed

4 files changed

+24
-12
lines changed

README.md

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ cd python-gpt-po
4444
python3 -m venv .venv
4545
source .venv/bin/activate
4646
pip install -r requirements.txt
47-
python -m python_gpt_po.main --folder test --lang nl --bulk --provider="deepseek" --list-models
47+
python -m python_gpt_po.main --provider="deepseek" --list-models
4848
```
4949

5050
## API Key Configuration
@@ -96,6 +96,8 @@ For a detailed explanation of all available parameters and a deep dive into the
9696
- `--bulk`: Enable bulk translation mode.
9797
- `--bulksize`: Set the number of entries per bulk translation (default is 50).
9898
- `--model`: Specify the translation model (defaults are provider-specific).
99+
- `--provider`: Specify the AI provider (openai, anthropic, or deepseek).
100+
- `--list-models`: List available models for the selected provider. This is the only command that can be used without `--folder` and `--lang`.
99101
- `--api_key`: API key for translation; can also be provided via environment variable.
100102
- `--folder-language`: Infer the target language from the folder structure.
101103

@@ -186,7 +188,7 @@ docker run -v $(pwd):/data -e OPENAI_API_KEY="your_key" ghcr.io/pescheckit/pytho
186188
# Use a specific Python version (3.12)
187189
docker run -v $(pwd):/data -e OPENAI_API_KEY="your_key" ghcr.io/pescheckit/python-gpt-po:latest-py3.12 --folder /data --lang fr
188190

189-
# List available models
191+
# List available models (no need for --folder or --lang)
190192
docker run -e OPENAI_API_KEY="your_key" ghcr.io/pescheckit/python-gpt-po:latest --provider openai --list-models
191193
```
192194

docker-entrypoint.sh

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,9 @@ if [ $# -eq 0 ]; then
2727
echo " # MacOS example"
2828
echo " docker run -v /Users/username/Documents/translations:/input -e OPENAI_API_KEY=<your_key> ghcr.io/pescheckit/python-gpt-po --folder /input --lang fr,es"
2929
echo
30+
echo " # List available models (no need for --folder or --lang)"
31+
echo " docker run -e OPENAI_API_KEY=<your_key> ghcr.io/pescheckit/python-gpt-po --provider openai --list-models"
32+
echo
3033
echo "For full documentation, visit: https://github.com/pescheckit/python-gpt-po"
3134
exit 0
3235
fi

docs/usage.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -139,8 +139,8 @@ Below is a detailed explanation of all command-line arguments:
139139
*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.
140140

141141
- **`--list-models`**
142-
*Description:* Lists all available models for the selected provider and exits without processing any files.
143-
*Behind the scenes:* Makes a test API call to retrieve a list of models and prints them to the console.
142+
*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.
143+
*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.
144144

145145
- **`--openai-key`**
146146
*Description:* Provides the OpenAI API key directly as a command-line argument (alternative to using `--api_key` or the environment variable).

python_gpt_po/utils/cli.py

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -36,21 +36,28 @@ def parse_args():
3636
Returns:
3737
argparse.Namespace: Parsed arguments
3838
"""
39+
# First pass - check if list-models is in args
40+
# This allows us to make folder and lang not required when listing models
41+
list_models_present = False
42+
for arg in sys.argv:
43+
if arg in ("--list-models", "--version"):
44+
list_models_present = True
45+
break
3946
parser = CustomArgumentParser(
4047
description="Translate .po files using AI language models",
4148
epilog="""
4249
Examples:
4350
# Basic usage with OpenAI
44-
python po_translator.py --folder ./locales --lang fr,es,de
51+
gpt-po-translator --folder ./locales --lang fr,es,de
4552
4653
# Use Anthropic with detailed language names
47-
python po_translator.py --folder ./i18n --lang nl,de --detail-lang "Dutch,German" --provider anthropic
54+
gpt-po-translator --folder ./i18n --lang nl,de --detail-lang "Dutch,German" --provider anthropic
4855
49-
# List available models for a provider
50-
python po_translator.py --provider deepseek --list-models
56+
# List available models for a provider (no need for --folder or --lang)
57+
gpt-po-translator --provider deepseek --list-models
5158
5259
# Process multiple translations in bulk with a specific model
53-
python po_translator.py --folder ./locales --lang ja,ko --bulk --model gpt-4
60+
gpt-po-translator --folder ./locales --lang ja,ko --bulk --model gpt-4
5461
""",
5562
formatter_class=lambda prog: argparse.RawDescriptionHelpFormatter(prog, max_help_position=35, width=100)
5663
)
@@ -62,16 +69,16 @@ def parse_args():
6269
api_group = parser.add_argument_group('API Keys')
6370
advanced_group = parser.add_argument_group('Advanced Options')
6471

65-
# Required arguments
72+
# Required arguments (not required if listing models)
6673
required_group.add_argument(
6774
"-f", "--folder",
68-
required=True,
75+
required=(not list_models_present),
6976
metavar="FOLDER",
7077
help="Input folder containing .po files"
7178
)
7279
required_group.add_argument(
7380
"-l", "--lang",
74-
required=True,
81+
required=(not list_models_present),
7582
metavar="LANG",
7683
help="Comma-separated language codes to translate (e.g., fr,es,de)"
7784
)

0 commit comments

Comments
 (0)