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
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Improve tips in abnormal request for BaichuanTextEmbeddings
In langchain_community/embeddings/baichuan.py:80
  • Loading branch information
maang-h committed May 21, 2024
commit e3d24ce811ee686142bec528ce90fddf6183f7b1
12 changes: 7 additions & 5 deletions libs/community/langchain_community/embeddings/baichuan.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import warnings
from typing import Any, Dict, List, Optional

import requests
Expand Down Expand Up @@ -79,34 +80,35 @@ def _embed(self, texts: List[str]) -> Optional[List[List[float]]]:
return [result.get("embedding", []) for result in sorted_embeddings]
# Common Error 1: Invalid `api_key`
elif response.status_code == 401:
raise Exception(
warnings.warn(
"401 Unauthorized: Access denied for `BaichuanEmbedding`."
"Please check your `api_key`."
)
# Common Error 2: Incorrect proxy settings
elif response.status_code == 407:
raise Exception(
warnings.warn(
"407 Proxy Authentication Required: Please check your proxy "
"setting and provide valid credentials."
)
# Client Error
elif response.status_code >= 400:
raise Exception(
warnings.warn(
f"{response.status_code} Client Error: Please verify your "
f"input and try again."
)
# Server Error
elif response.status_code >= 500:
raise Exception(
warnings.warn(
f"{response.status_code} Service Error: An internal error "
f"has occurred on the `BaichuanEmbedding` server."
)
else:
# Log error or handle unsuccessful response appropriately
raise Exception( # noqa: T201
warnings.warn( # noqa: T201
f"Error: Received status code {response.status_code} from "
"`BaichuanEmbedding` API"
)
return None
except Exception as e:
# Log the exception or handle it as needed
raise Exception( # noqa: T201
Expand Down
Loading