mirror of
https://github.com/hwchase17/langchain.git
synced 2025-05-09 17:18:31 +00:00
community[patch]: avoid KeyError when language not in LANGUAGE_SEGMENTERS (#15212)
**Description:** Handle unsupported languages in same way as when none is provided **Issue:** The following line will throw a KeyError if the language is not supported. ```python self.Segmenter = LANGUAGE_SEGMENTERS[language] ``` E.g. when using `Language.CPP` we would get `KeyError: <Language.CPP: 'cpp'>` --------- Co-authored-by: Bagatur <baskaryan@gmail.com>
This commit is contained in:
parent
3f38e1a457
commit
b3ed98dec0
@ -97,6 +97,8 @@ class LanguageParser(BaseBlobParser):
|
||||
language: If None (default), it will try to infer language from source.
|
||||
parser_threshold: Minimum lines needed to activate parsing (0 by default).
|
||||
"""
|
||||
if language and language not in LANGUAGE_SEGMENTERS:
|
||||
raise Exception(f"No parser available for {language}")
|
||||
self.language = language
|
||||
self.parser_threshold = parser_threshold
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user