Skip to content
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

Merged
merged 5 commits into from
Jun 5, 2024

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 This PR changes 10-29 lines, ignoring generated files. Ɑ: embeddings Related to text embedding models module 🤖:improvement Medium size change to existing code to handle new use-cases labels May 22, 2024
libs/community/langchain_community/embeddings/baichuan.py Outdated Show resolved Hide resolved
@@ -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(
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 This PR changes 30-99 lines, ignoring generated files. and removed size:S This PR changes 10-29 lines, ignoring generated files. labels May 27, 2024
@dosubot dosubot bot added the lgtm PR looks good. Use to confirm that a PR is ready for merging. 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
42 checks passed
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
Ɑ: embeddings Related to text embedding models module 🤖:improvement Medium size change to existing code to handle new use-cases lgtm PR looks good. Use to confirm that a PR is ready for merging. size:M This PR changes 30-99 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants