Skip to content

Conversation

maang-h
Copy link
Contributor

@maang-h maang-h commented May 22, 2024

Copy link

vercel bot commented May 22, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

1 Ignored Deployment
Name Status Preview Comments Updated (UTC)
langchain ⬜️ Ignored (Inspect) Visit Preview May 27, 2024 1:42pm

@dosubot dosubot bot added size:S labels May 22, 2024
# Log error or handle unsuccessful response appropriately
print( # noqa: T201
# Handle 100 <= status_code < 400, not include 200
raise RequestException(
Copy link
Collaborator

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?

Copy link
Contributor Author

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)

Copy link
Contributor Author

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?

Copy link
Collaborator

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

@eyurtsev eyurtsev self-assigned this May 22, 2024
@dosubot dosubot bot added size:M and removed size:S labels May 27, 2024
@dosubot dosubot bot added the lgtm label Jun 5, 2024
@eyurtsev eyurtsev changed the title Docs: add detailed paragraph and example for BaichuanTextEmbeddings community[patch]: add detailed paragraph and example for BaichuanTextEmbeddings Jun 5, 2024
@eyurtsev eyurtsev merged commit 89128b7 into langchain-ai:master Jun 5, 2024
hinthornw pushed a commit that referenced this pull request Jun 20, 2024
…Embeddings (#22031)

- **Description:** add detailed paragraph and example for
BaichuanTextEmbeddings
   - **Issue:** the issue #21983
@maang-h maang-h deleted the add-doc-bcembd branch June 22, 2024 01:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants