Skip to content

Commit 4fffd3a

Browse files
committed
🔧 refactor(config): rename model_path to custom_model_path
- Update configuration parameter name for better clarity - Modify README examples to use new parameter name - Adjust test cases and implementation to reflect parameter rename - Improve documentation and code consistency
1 parent a8e9b45 commit 4fffd3a

File tree

3 files changed

+16
-11
lines changed

3 files changed

+16
-11
lines changed

README.md

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -105,8 +105,13 @@ We provide a fallback mechanism: when `allow_fallback=True`, if the program fail
105105

106106
```python
107107
# Disable fallback - will raise error if large model fails to load
108-
# But fallback disabled when model_path is not None, because its a custom model
109-
config = LangDetectConfig(allow_fallback=False, model_path=None)
108+
# But fallback disabled when custom_model_path is not None, because its a custom model, we will directly use it.
109+
import tempfile
110+
config = LangDetectConfig(
111+
allow_fallback=False,
112+
custom_model_path=None,
113+
cache_dir=tempfile.gettempdir(),
114+
)
110115
detector = LangDetector(config)
111116

112117
try:
@@ -136,7 +141,7 @@ print(detect_language("你好,世界!"))
136141
```python
137142
# Load model from local file
138143
config = LangDetectConfig(
139-
model_path="/path/to/your/model.bin", # Use local model file
144+
custom_model_path="/path/to/your/model.bin", # Use local model file
140145
disable_verify=True # Skip MD5 verification
141146
)
142147
detector = LangDetector(config)

src/fast_langdetect/infer.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,7 @@ class LangDetectConfig:
168168
Configuration for language detection.
169169
170170
:param cache_dir: Directory for storing downloaded models
171-
:param model_path: Path to custom model file (if using own model)
171+
:param custom_model_path: Path to custom model file (if using own model)
172172
:param proxy: HTTP proxy for downloads
173173
:param allow_fallback: Whether to fallback to small model
174174
:param disable_verify: Whether to disable MD5 verification
@@ -177,21 +177,21 @@ class LangDetectConfig:
177177
def __init__(
178178
self,
179179
cache_dir: Optional[str] = None,
180-
model_path: Optional[str] = None,
180+
custom_model_path: Optional[str] = None,
181181
proxy: Optional[str] = None,
182182
allow_fallback: bool = True,
183183
disable_verify: bool = False,
184184
verify_hash: Optional[str] = None,
185185
):
186186
self.cache_dir = cache_dir or CACHE_DIRECTORY
187-
self.model_path = model_path
187+
self.custom_model_path = custom_model_path
188188
self.proxy = proxy
189189
self.allow_fallback = allow_fallback
190190
# Only verify large model
191191
self.disable_verify = disable_verify
192192
self.verify_hash = verify_hash
193-
if self.model_path and not Path(self.model_path).exists():
194-
raise FileNotFoundError(f"fast-langdetect: Target model file not found: {self.model_path}")
193+
if self.custom_model_path and not Path(self.custom_model_path).exists():
194+
raise FileNotFoundError(f"fast-langdetect: Target model file not found: {self.custom_model_path}")
195195

196196
class LangDetector:
197197
"""Language detector using FastText models."""
@@ -214,11 +214,11 @@ def _get_model(self, low_memory: bool = True) -> Any:
214214
return model
215215

216216
try:
217-
if self.config.model_path is not None:
217+
if self.config.custom_model_path is not None:
218218
# Load Custom Model
219219
if self.config.disable_verify:
220220
self.config.verify_hash = None
221-
model = self._model_loader.load_local(Path(self.config.model_path))
221+
model = self._model_loader.load_local(Path(self.config.custom_model_path))
222222
elif low_memory is True:
223223
self.config.verify_hash = None
224224
# Load Small Model

tests/test_real_detection.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ def test_not_found_model(self):
8787
with pytest.raises(FileNotFoundError):
8888
config = LangDetectConfig(
8989
cache_dir="/nonexistent/path",
90-
model_path="invalid_path",
90+
custom_model_path="invalid_path",
9191
allow_fallback=True,
9292
)
9393
detector = LangDetector(config)

0 commit comments

Comments
 (0)