-
Notifications
You must be signed in to change notification settings - Fork 15.8k
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
community[patch]: add detailed paragraph and example for BaichuanTextEmbeddings #22031
Conversation
maang-h
commented
May 22, 2024
- Description: add detailed paragraph and example for BaichuanTextEmbeddings
- Issue: the issue Standardize docstrings and improve coverage #21983
In langchain_community/embeddings/baichuan.py:80
In langchain_community/embeddings/baichuan.py:80
The latest updates on your projects. Learn more about Vercel for Git ↗︎ 1 Ignored Deployment
|
@@ -79,15 +94,14 @@ def _embed(self, texts: List[str]) -> Optional[List[List[float]]]: | |||
return [result.get("embedding", []) for result in sorted_embeddings] | |||
else: | |||
# Log error or handle unsuccessful response appropriately | |||
print( # noqa: T201 | |||
# Handle 100 <= status_code < 400, not include 200 | |||
raise RequestException( |
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.
This will raise exceptions for all 2xx except for 200 as well, which isn't correct behavior
Why not remove this exception entirely since response.raise_for_status()
already raises?
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 method response.raise_for_status()
just handle status_code from 400 to 600
# requests -> models.py -> Response
def raise_for_status(self):
"""Raises :class:`HTTPError`, if one occurred."""
http_error_msg = ""
if isinstance(self.reason, bytes):
# We attempt to decode utf-8 first because some servers
# choose to localize their reason strings. If the string
# isn't utf-8, we fall back to iso-8859-1 for all other
# encodings. (See PR #3538)
try:
reason = self.reason.decode("utf-8")
except UnicodeDecodeError:
reason = self.reason.decode("iso-8859-1")
else:
reason = self.reason
if 400 <= self.status_code < 500:
http_error_msg = (
f"{self.status_code} Client Error: {reason} for url: {self.url}"
)
elif 500 <= self.status_code < 600:
http_error_msg = (
f"{self.status_code} Server Error: {reason} for url: {self.url}"
)
if http_error_msg:
raise HTTPError(http_error_msg, response=self)
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.
@eyurtsev Can you give me some suggestions for improvement?
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.
I'm merging this version. If you want feel free to follow up with a PR. The conditional if response.status==200 can be changed to just accept 2xx codes. Not super critical here, but code looks a bit odd where an error message is rasied from a 2xx code that isn't 200