-
Notifications
You must be signed in to change notification settings - Fork 1.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix: i18n azure llm mode #2095
fix: i18n azure llm mode #2095
Conversation
Adding the "do-not-merge/release-note-label-needed" label because no release-note block was detected, please follow our release note process to remove it. Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository. |
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: The full list of commands accepted by this bot can be found here.
Needs approval from an approver in each of these files:
Approvers can indicate their approval by writing |
@@ -53,7 +53,7 @@ def is_valid(self, model_type: str, model_name, model_credential: Dict[str, obje | |||
return False | |||
try: | |||
model = provider.get_model(model_type, model_name, model_credential, **model_params) | |||
model.invoke([HumanMessage(content=_('Hello'))]) | |||
model.invoke([HumanMessage(content=gettext('Hello'))]) | |||
except Exception as e: | |||
if isinstance(e, AppApiException): | |||
raise e |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The code snippet appears to be written using Python with some string localization conventions that differ from modern practices. Here are the minor adjustments and points of improvement I would suggest:
-
String Localization: The use of
gettext
function is good practice, but it's recommended to use context managers likewith gettext.translation()
where applicable if you intend to localize messages dynamically. -
Function Parameter Passing: The parameter names for passing parameters to the model's
invoke
method are inconsistent. You should pass them explicitly instead of using wildcard arguments (**model_params
).
Here’s an improved version of your code incorporating these suggestions:
try:
model = provider.get_model(model_type, model_name, model_credential, content=gettext('Hello'))
except (Exception, AppApiException) as e:
raise e
This change ensures clarity in how parameters are passed to the model's invoke
method and adheres to best practices related to string handling.
a546ffc
to
caa20e5
Compare
@@ -49,7 +49,7 @@ def is_valid(self, model_type: str, model_name, model_credential: Dict[str, obje | |||
|
|||
try: | |||
model = provider.get_model(model_type, model_name, model_credential, **model_params) | |||
model.invoke([HumanMessage(content=_('Hello'))]) | |||
model.invoke([HumanMessage(content=gettext('Hello'))]) | |||
except AppApiException: | |||
raise | |||
except Exception as e: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There are no irregularities or major issues with this code snippet based on the provided context.
One minor suggestion is to use f-string formatting within gettext
instead of concatenation:
content=f'{{{gettext("Hello")}}}'
This can improve readability.
The rest of the code looks clean and functional for invoking a model with input messages.
@@ -53,7 +53,7 @@ def is_valid(self, model_type: str, model_name, model_credential: Dict[str, obje | |||
return False | |||
try: | |||
model = provider.get_model(model_type, model_name, model_credential, **model_params) | |||
model.invoke([HumanMessage(content=_('Hello'))]) | |||
model.invoke([HumanMessage(content=gettext('Hello'))]) | |||
except Exception as e: | |||
if isinstance(e, AppApiException): | |||
raise e |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The code appears to be using both Python's built-in gettext
function from the gettext
module and Flask's current_app._translate
. This can potentially lead to unexpected behavior if not managed carefully.
Consider removing one of these functions to clarify which translation mechanism is being used. If you intend to use Django's gettext
, ensure all strings are marked for translation with _()
before they are passed to the model method. Here's an optimized version that uses only one source:
@@ -53,11 +53,10 @@ def is_valid(self, model_type: str, model_name, model_credential: Dict[str, obje
return False
try:
- if model.type == 'flask':
- content = current_app._translate("Hello")
- else:
- content = _("Hello")
+ content = translate_phrase("Hello", "en" or "default_language")
+
model.invoke([HumanMessage(content=content)])
except AppApiException as e:
raise e
Make sure to implement a helper function like translate_phrase
that fetches the appropriate translated phrase based on your needs (e.g., fetching translations from a database or an external API).
fix: i18n azure llm mode