Skip to content

Commit

Permalink
fix: refactor apply review
Browse files Browse the repository at this point in the history
  • Loading branch information
ayuki-joto committed Jul 24, 2024
1 parent c02c625 commit b04dfca
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 7 deletions.
Original file line number Diff line number Diff line change
@@ -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")

17 changes: 11 additions & 6 deletions etl/src/birdxplorer_etl/lib/openapi/open_ai_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -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}")

0 comments on commit b04dfca

Please sign in to comment.