mirror of
https://github.com/hwchase17/langchain.git
synced 2025-07-02 03:15:11 +00:00
huggingface: Fix huggingface tei support (#22653)
Update former pull request: https://github.com/langchain-ai/langchain/pull/22595. Modified `libs/partners/huggingface/langchain_huggingface/embeddings/huggingface_endpoint.py`, where the API call function does not match current [Text Embeddings Inference API](https://huggingface.github.io/text-embeddings-inference/#/Text%20Embeddings%20Inference/embed). One example is: ```json { "inputs": "string", "normalize": true, "truncate": false } ``` Parameters in `_model_kwargs` are not passed properly in the latest version. By the way, the issue *[why cause 413? #50](https://github.com/huggingface/text-embeddings-inference/issues/50)* might be solved.
This commit is contained in:
parent
9ccc4b1616
commit
2be66a38d8
@ -112,8 +112,9 @@ class HuggingFaceHubEmbeddings(BaseModel, Embeddings):
|
|||||||
# replace newlines, which can negatively affect performance.
|
# replace newlines, which can negatively affect performance.
|
||||||
texts = [text.replace("\n", " ") for text in texts]
|
texts = [text.replace("\n", " ") for text in texts]
|
||||||
_model_kwargs = self.model_kwargs or {}
|
_model_kwargs = self.model_kwargs or {}
|
||||||
|
# api doc: https://huggingface.github.io/text-embeddings-inference/#/Text%20Embeddings%20Inference/embed
|
||||||
responses = self.client.post(
|
responses = self.client.post(
|
||||||
json={"inputs": texts, "parameters": _model_kwargs}, task=self.task
|
json={"inputs": texts, **_model_kwargs}, task=self.task
|
||||||
)
|
)
|
||||||
return json.loads(responses.decode())
|
return json.loads(responses.decode())
|
||||||
|
|
||||||
|
@ -108,8 +108,9 @@ class HuggingFaceEndpointEmbeddings(BaseModel, Embeddings):
|
|||||||
# replace newlines, which can negatively affect performance.
|
# replace newlines, which can negatively affect performance.
|
||||||
texts = [text.replace("\n", " ") for text in texts]
|
texts = [text.replace("\n", " ") for text in texts]
|
||||||
_model_kwargs = self.model_kwargs or {}
|
_model_kwargs = self.model_kwargs or {}
|
||||||
|
# api doc: https://huggingface.github.io/text-embeddings-inference/#/Text%20Embeddings%20Inference/embed
|
||||||
responses = self.client.post(
|
responses = self.client.post(
|
||||||
json={"inputs": texts, "parameters": _model_kwargs}, task=self.task
|
json={"inputs": texts, **_model_kwargs}, task=self.task
|
||||||
)
|
)
|
||||||
return json.loads(responses.decode())
|
return json.loads(responses.decode())
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user