From 055404ad3cce80a5cd563f1c6bcecfe260544d20 Mon Sep 17 00:00:00 2001 From: rbrugaro Date: Mon, 12 Aug 2024 10:02:25 -0700 Subject: [PATCH] remove deprecated langchain imports and switch to langchain-huggingface (#417) * remrove deprecated imports and switch to langchain-huggingface Signed-off-by: rbrugaro * fix typo Signed-off-by: rbrugaro * set requirements to langchain latest release Signed-off-by: rbrugaro * remove version for langchain in requirements Signed-off-by: rbrugaro --------- Signed-off-by: rbrugaro --- comps/embeddings/README.md | 2 +- comps/embeddings/langchain/embedding_tei.py | 4 ++-- comps/embeddings/langchain/local_embedding.py | 4 ++-- comps/embeddings/langchain/requirements.txt | 1 + 4 files changed, 6 insertions(+), 5 deletions(-) diff --git a/comps/embeddings/README.md b/comps/embeddings/README.md index eacefac1f..ce4b4fa46 100644 --- a/comps/embeddings/README.md +++ b/comps/embeddings/README.md @@ -155,6 +155,6 @@ curl http://localhost:6000/v1/health_check\ ```bash curl http://localhost:6000/v1/embeddings\ -X POST \ - -d '{"input":"Hello, world!"}' \ + -d '{"text":"Hello, world!"}' \ -H 'Content-Type: application/json' ``` diff --git a/comps/embeddings/langchain/embedding_tei.py b/comps/embeddings/langchain/embedding_tei.py index 583e24d5a..6a5fbc614 100644 --- a/comps/embeddings/langchain/embedding_tei.py +++ b/comps/embeddings/langchain/embedding_tei.py @@ -5,7 +5,7 @@ import time from typing import Union -from langchain_community.embeddings import HuggingFaceHubEmbeddings +from langchain_huggingface import HuggingFaceEndpointEmbeddings from langsmith import traceable from comps import ( @@ -61,6 +61,6 @@ def embedding( if __name__ == "__main__": tei_embedding_endpoint = os.getenv("TEI_EMBEDDING_ENDPOINT", "http://localhost:8080") - embeddings = HuggingFaceHubEmbeddings(model=tei_embedding_endpoint) + embeddings = HuggingFaceEndpointEmbeddings(model=tei_embedding_endpoint) print("TEI Gaudi Embedding initialized.") opea_microservices["opea_service@embedding_tei_langchain"].start() diff --git a/comps/embeddings/langchain/local_embedding.py b/comps/embeddings/langchain/local_embedding.py index 4aff07c6d..1a3825c40 100644 --- a/comps/embeddings/langchain/local_embedding.py +++ b/comps/embeddings/langchain/local_embedding.py @@ -1,7 +1,7 @@ # Copyright (C) 2024 Intel Corporation # SPDX-License-Identifier: Apache-2.0 -from langchain_community.embeddings import HuggingFaceBgeEmbeddings +from langchain_huggingface import HuggingFaceEmbeddings from comps import EmbedDoc, ServiceType, TextDoc, opea_microservices, opea_telemetry, register_microservice @@ -23,5 +23,5 @@ def embedding(input: TextDoc) -> EmbedDoc: if __name__ == "__main__": - embeddings = HuggingFaceBgeEmbeddings(model_name="BAAI/bge-large-en-v1.5") + embeddings = HuggingFaceEmbeddings(model_name="BAAI/bge-large-en-v1.5") opea_microservices["opea_service@local_embedding"].start() diff --git a/comps/embeddings/langchain/requirements.txt b/comps/embeddings/langchain/requirements.txt index eaa946aad..8f0dd3ad4 100644 --- a/comps/embeddings/langchain/requirements.txt +++ b/comps/embeddings/langchain/requirements.txt @@ -2,6 +2,7 @@ docarray[full] fastapi huggingface_hub langchain +langchain_huggingface langsmith opentelemetry-api opentelemetry-exporter-otlp