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
Added multilingual support for the Wikipedia reader. #12616
Conversation
@garys-io thanks for approving the changes. A review seems to be still required for the PR to be merged. |
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.
@anirbanbasu thanks for the contribution. Looks good, but can you please check if we can do validation of lang_code
as I mentioned in my comment. 🙏
""" | ||
import wikipedia | ||
|
||
if lang_code.lower() != "en": | ||
# Sets, without checking the validity of, the language code for Wikipedia. |
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.
can we add some validation here? It looks like we can (and maybe should) check and raise error if the supplied lang_code
isn't actually supported via wikipedia.languages()
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.
@nerdai thanks for your comment. That sounds like a good idea. How about the following?
if lang_code.lower() in wikipedia.languages().keys():
wikipedia.set_lang(lang_code.lower())
else:
raise SomeError(with_a_message)
What error would you like to raise? wikipedia.exceptions.WikipediaException
? The error message should be something like "The provided language prefix for Wikipedia is not supported. Check supported languages at https://en.wikipedia.org/wiki/List_of_Wikipedias."
Alternatively, would you like it to silently fall back to "en" if the prefix is not supported instead of raising an exception?
Since I use the word prefix instead of code in the error message to be consistent with the wikipedia
package, I will also change the function argument from lang_code
to lang_prefix
.
Looks good?
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.
Yea, we can raise a ValueError
here. The message you suggested seems reasonable to me.
lang_prefix
> lang_code
🙏
Thanks!
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.
Thanks, I think the following is better than checking wikipedia.languages().keys()
:
if lang_prefix.lower() in wikipedia.languages():
wikipedia.set_lang(lang_prefix.lower())
else:
raise ValueError(
f"Language prefix '{lang_prefix}' for Wikipedia is not supported. Check supported languages at https://en.wikipedia.org/wiki/List_of_Wikipedias."
)
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.
Agreed!
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.
@nerdai thanks, code pushed.
Checks if the provided language prefix is supported by the list of languages of Wikipedia.
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.
lgtm!
Merging this now @anirbanbasu - thanks again for the contribution! |
* Added multilingual support for the Wikipedia reader. * fix: Added a check for the language prefix. Checks if the provided language prefix is supported by the list of languages of Wikipedia.
Description
Wikipedia is available in multiple languages, see https://en.wikipedia.org/wiki/List_of_Wikipedias. Some articles are available in languages apart from English. The current Wikipedia reader does not look for articles outside https://en.wikipedia.org/.
The ability to connect to non-English Wikipedia has been already available in the underlying Wikipedia parser, see starting line 22.
Fixes #12596. Same as mistakenly deleted/closed PR12597.
New Package?
Did I fill in the
tool.llamahub
section in thepyproject.toml
and provide a detailed README.md for my new integration or package?Version Bump?
Did I bump the version in the
pyproject.toml
file of the package I am updating? (Except for thellama-index-core
package)Type of Change
Please delete options that are not relevant.
How Has This Been Tested?
Please describe the tests that you ran to verify your changes. Provide instructions so we can reproduce. Please also list any relevant details for your test configuration
Suggested Checklist:
make format; make lint
to appease the lint gods