Skip to content

Commit

Permalink
Support Predibase-LangChain integration for both Predibase SDK-v1 and…
Browse files Browse the repository at this point in the history
… Predibase SDK-v2 users.
  • Loading branch information
alexsherstinsky committed Apr 24, 2024
1 parent f3ca16f commit 7e2f79b
Showing 1 changed file with 13 additions and 8 deletions.
21 changes: 13 additions & 8 deletions libs/community/langchain_community/llms/predibase.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ class Predibase(LLM):
otherwise, an error is raised. If the fine-tuned adapter is hosted at Predibase,
then `adapter_version` in the adapter repository must be specified.
An optional `predibase_sdk_version` parameter defaults to the latest Predibase SDK version.
An optional `predibase_sdk_version` parameter defaults to latest SDK version.
"""

model: str
Expand Down Expand Up @@ -87,8 +87,9 @@ def _call(
result: GeneratedResponse
if self.adapter_id:
"""
Attempt to retrieve the fine-tuned adapter from a Predibase repository.
If absent, then load the fine-tuned adapter from a HuggingFace repository.
Attempt to retrieve the fine-tuned adapter from a Predibase
repository. If absent, then load the fine-tuned adapter
from a HuggingFace repository.
"""
adapter_model: Union[Model, HuggingFaceLLM]
try:
Expand Down Expand Up @@ -144,7 +145,8 @@ def _call(
)
except GenerationError as ge:
raise ValueError(
f'An adapter with the ID "{pb_adapter_id}" cannot be found in the Predibase repository of fine-tuned adapters.'
f"""An adapter with the ID "{pb_adapter_id}" cannot be \
found in the Predibase repository of fine-tuned adapters."""
) from ge
else:
# The adapter version is omitted, hence look for the adapter ID in the HuggingFace repository.

Check failure on line 152 in libs/community/langchain_community/llms/predibase.py

View workflow job for this annotation

GitHub Actions / cd libs/community / make lint #3.8

Ruff (E501)

langchain_community/llms/predibase.py:152:89: E501 Line too long (110 > 88)

Check failure on line 152 in libs/community/langchain_community/llms/predibase.py

View workflow job for this annotation

GitHub Actions / cd libs/community / make lint #3.11

Ruff (E501)

langchain_community/llms/predibase.py:152:89: E501 Line too long (110 > 88)
Expand All @@ -157,8 +159,9 @@ def _call(
)
except GenerationError as ge:
raise ValueError(
f"""Either an adapter with the ID "{self.adapter_id}" cannot be found in a HuggingFace repository, \
or it is incompatible with the base model (please make sure that the adapter configuration is consistent).
f"""Either an adapter with the ID "{self.adapter_id}" \
cannot be found in a HuggingFace repository, or it is incompatible with the \
base model (please make sure that the adapter configuration is consistent).
"""
) from ge
else:
Expand All @@ -169,8 +172,10 @@ def _call(
)
except requests.JSONDecodeError as jde:
raise ValueError(
f"""An LLM with the deployment ID "{self.model}" cannot be found at Predibase \
(please refer to "https://docs.predibase.com/user-guide/inference/models" for the list of supported models).
f"""An LLM with the deployment ID "{self.model}" cannot be found \
at Predibase (please refer to \
"https://docs.predibase.com/user-guide/inference/models" for the list of \
supported models).
"""
) from jde
response_text = response.generated_text
Expand Down

0 comments on commit 7e2f79b

Please sign in to comment.