diff --git a/etl/src/birdxplorer_etl/lib/ai_model/ai_model_interface_base.py b/etl/src/birdxplorer_etl/lib/ai_model/ai_model_interface_base.py index bed759d..cfb5570 100644 --- a/etl/src/birdxplorer_etl/lib/ai_model/ai_model_interface_base.py +++ b/etl/src/birdxplorer_etl/lib/ai_model/ai_model_interface_base.py @@ -1,4 +1,4 @@ class AIModelInterface: def detect_language(self, text: str) -> str: - raise NotImplementedError("langdetect method not implemented") + raise NotImplementedError("detect_language method not implemented") diff --git a/etl/src/birdxplorer_etl/lib/openapi/open_ai_service.py b/etl/src/birdxplorer_etl/lib/openapi/open_ai_service.py index 721e570..045cc20 100644 --- a/etl/src/birdxplorer_etl/lib/openapi/open_ai_service.py +++ b/etl/src/birdxplorer_etl/lib/openapi/open_ai_service.py @@ -24,14 +24,19 @@ def detect_language(self, text: str) -> str: {"role": "system", "content": "You are a helpful assistant."}, {"role": "user", "content": prompt} ], + temperature=0.0, + seed=1, max_tokens=30 ) + message_content = response.choices[0].message.content.strip() - if message_content not in LanguageIdentifier._value2member_map_: - for code in LanguageIdentifier._value2member_map_: - if code in message_content: - return LanguageIdentifier(code) - raise ValueError(f"Invalid language code received: {message_content}") - else: + if message_content in LanguageIdentifier._value2member_map_: return LanguageIdentifier(message_content) + + valid_code = next((code for code in LanguageIdentifier._value2member_map_ if code in message_content), None) + + if valid_code: + return LanguageIdentifier(valid_code) + + raise ValueError(f"Invali 3d language code received: {message_content}") \ No newline at end of file