mirror of
https://github.com/hwchase17/langchain.git
synced 2025-07-04 12:18:24 +00:00
huggingface[fix]: HuggingFaceEndpointEmbeddings model parameter passing error when async embed (#27953)
This change refines the handling of _model_kwargs in POST requests. Instead of nesting _model_kwargs as a dictionary under the parameters key, it is now directly unpacked and merged into the request's JSON payload. This ensures that the model parameters are passed correctly and avoids unnecessary nesting.E. g.: ```python import asyncio from langchain_huggingface.embeddings import HuggingFaceEndpointEmbeddings embedding_input = ["This input will get multiplied" * 10000] embeddings = HuggingFaceEndpointEmbeddings( model="http://127.0.0.1:8081/embed", model_kwargs={"truncate": True}, ) # Truncated parameters in synchronized methods are handled correctly embeddings.embed_documents(texts=embedding_input) # The truncate parameter is not handled correctly in the asynchronous method, # and 413 Request Entity Too Large is returned. asyncio.run(embeddings.aembed_documents(texts=embedding_input)) ``` Co-authored-by: af su <saf@zjuici.com> Co-authored-by: Erick Friis <erick@langchain.dev>
This commit is contained in:
parent
923ef85105
commit
7c7ee07d30
@ -127,7 +127,7 @@ class HuggingFaceEndpointEmbeddings(BaseModel, Embeddings):
|
|||||||
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 {}
|
||||||
responses = await self.async_client.post(
|
responses = await self.async_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