From c2c137faa6afb3d0b373128c0f90ac425442eb1a Mon Sep 17 00:00:00 2001 From: lvliang-intel Date: Fri, 3 Jan 2025 10:40:41 +0800 Subject: [PATCH 01/15] Refine component interface Signed-off-by: lvliang-intel --- comps/__init__.py | 2 +- comps/cores/common/component.py | 113 +++++++------- .../opea_multimodal_embedding_bridgetower.py | 2 + .../src/integrations/opea_tei_embedding.py | 2 + .../integrations/predictionguard_embedding.py | 2 + .../src/opea_embedding_microservice.py | 35 +---- tests/cores/common/test_component.py | 138 +++++++----------- .../embeddings/test_embeddings_multimodal.sh | 1 + ...test_embeddings_multimodal_on_intel_hpu.sh | 1 + .../test_embeddings_predictionguard.sh | 1 + tests/embeddings/test_embeddings_tei.sh | 1 + 11 files changed, 127 insertions(+), 171 deletions(-) diff --git a/comps/__init__.py b/comps/__init__.py index 814aa5e4e6..babd491edd 100644 --- a/comps/__init__.py +++ b/comps/__init__.py @@ -53,7 +53,7 @@ from comps.cores.telemetry.opea_telemetry import opea_telemetry # Common -from comps.cores.common.component import OpeaComponent, OpeaComponentController +from comps.cores.common.component import OpeaComponent, OpeaComponentRegistry, OpeaComponentLoader # Statistics from comps.cores.mega.base_statistics import statistics_dict, register_statistics diff --git a/comps/cores/common/component.py b/comps/cores/common/component.py index 2bbd436f21..4c74edac9c 100644 --- a/comps/cores/common/component.py +++ b/comps/cores/common/component.py @@ -85,76 +85,79 @@ def __repr__(self): """ return f"OpeaComponent(name={self.name}, type={self.type}, description={self.description})" - -class OpeaComponentController(ABC): - """The OpeaComponentController class serves as the base class for managing and orchestrating multiple - instances of components of the same type. It provides a unified interface for routing tasks, - registering components, and dynamically discovering available components. - - Attributes: - components (dict): A dictionary to store registered components by their unique identifiers. +class OpeaComponentRegistry: + """ + Registry class to manage component instances. + This registry allows storing, retrieving, and managing component instances by their names. """ - def __init__(self): - """Initializes the OpeaComponentController instance with an empty component registry.""" - self.components = {} - self.active_component = None - - def register(self, component): - """Registers an OpeaComponent instance to the controller. + _registry = {} - Args: - component (OpeaComponent): An instance of a subclass of OpeaComponent to be managed. + @classmethod + def register(cls, name): + """ + Decorator to register a component class with a specified name. - Raises: - ValueError: If the component is already registered. + :param name: The name to associate with the component class + :return: Decorator function + """ + def decorator(component_class): + if name in cls._registry: + raise ValueError(f"A component with the name '{name}' is already registered.") + cls._registry[name] = component_class + return component_class + return decorator + + @classmethod + def get(cls, name): """ - if component.name in self.components: - raise ValueError(f"Component '{component.name}' is already registered.") - logger.info(f"Registered component: {component.name}") - self.components[component.name] = component + Retrieve a component class by its name. - def discover_and_activate(self): - """Discovers healthy components and activates one. + :param name: The name of the component class to retrieve + :return: The component class + """ + if name not in cls._registry: + raise KeyError(f"No component found with the name '{name}'.") + return cls._registry[name] - If multiple components are healthy, it prioritizes the first registered component. + @classmethod + def unregister(cls, name): """ - for component in self.components.values(): - if component.check_health(): - self.active_component = component - logger.info(f"Activated component: {component.name}") - return - raise RuntimeError("No healthy components available.") + Remove a component class from the registry by its name. - async def invoke(self, *args, **kwargs): - """Invokes service accessing using the active component. + :param name: The name of the component class to remove + """ + if name in cls._registry: + del cls._registry[name] - Args: - *args: Positional arguments. - **kwargs: Keyword arguments. - Returns: - Any: The result of the service accessing. +class OpeaComponentLoader: + """ + Loader class to dynamically load and invoke components. + This loader retrieves components from the registry and invokes their functionality. + """ - Raises: - RuntimeError: If no active component is set. + def __init__(self, component_name, **kwargs): """ - if not self.active_component: - raise RuntimeError("No active component. Call 'discover_and_activate' first.") - return await self.active_component.invoke(*args, **kwargs) + Initialize the loader with a component retrieved from the registry and instantiate it. - def list_components(self): - """Lists all registered components. - - Returns: - list: A list of component names that are currently registered. + :param component_name: The name of the component to load + :param kwargs: Additional parameters for the component's initialization """ - return self.components.keys() + # Retrieve the component class from the registry + component_class = OpeaComponentRegistry.get(component_name) + + # Instantiate the component with the given arguments + self.component = component_class(**kwargs) - def __repr__(self): - """Provides a string representation of the controller and its registered components. + async def invoke(self, *args, **kwargs): + """ + Invoke the loaded component's execute method. - Returns: - str: A string representation of the OpeaComponentController instance. + :param args: Positional arguments for the invoke method + :param kwargs: Keyword arguments for the invoke method + :return: The result of the component's invoke method """ - return f"OpeaComponentController(registered_components={self.list_components()})" + if not hasattr(self.component, 'invoke'): + raise AttributeError(f"The component '{self.component}' does not have an 'invoke' method.") + return await self.component.invoke(*args, **kwargs) diff --git a/comps/embeddings/src/integrations/opea_multimodal_embedding_bridgetower.py b/comps/embeddings/src/integrations/opea_multimodal_embedding_bridgetower.py index 9d3e468642..ee5bafa0d4 100644 --- a/comps/embeddings/src/integrations/opea_multimodal_embedding_bridgetower.py +++ b/comps/embeddings/src/integrations/opea_multimodal_embedding_bridgetower.py @@ -8,11 +8,13 @@ import requests from comps import CustomLogger, EmbedMultimodalDoc, MultimodalDoc, OpeaComponent, ServiceType, TextDoc, TextImageDoc +from comps import OpeaComponentRegistry logger = CustomLogger("opea_multimodal_embedding_bridgetower") logflag = os.getenv("LOGFLAG", False) +@OpeaComponentRegistry.register("OPEA_MULTIMODAL_EMBEDDING_BRIDGETOWER") class OpeaMultimodalEmbeddingBrigeTower(OpeaComponent): """A specialized embedding component derived from OpeaComponent for local deployed BrigeTower multimodal embedding services. diff --git a/comps/embeddings/src/integrations/opea_tei_embedding.py b/comps/embeddings/src/integrations/opea_tei_embedding.py index 1bfc708fea..ae72bab154 100644 --- a/comps/embeddings/src/integrations/opea_tei_embedding.py +++ b/comps/embeddings/src/integrations/opea_tei_embedding.py @@ -11,6 +11,7 @@ from comps import CustomLogger, OpeaComponent, ServiceType from comps.cores.mega.utils import get_access_token from comps.cores.proto.api_protocol import EmbeddingRequest, EmbeddingResponse +from comps import OpeaComponentRegistry logger = CustomLogger("opea_tei_embedding") logflag = os.getenv("LOGFLAG", False) @@ -19,6 +20,7 @@ CLIENT_SECRET = os.getenv("CLIENT_SECRET") +@OpeaComponentRegistry.register("OPEA_TEI_EMBEDDING") class OpeaTEIEmbedding(OpeaComponent): """A specialized embedding component derived from OpeaComponent for TEI embedding services. diff --git a/comps/embeddings/src/integrations/predictionguard_embedding.py b/comps/embeddings/src/integrations/predictionguard_embedding.py index a1fa0991ab..c1e19fe2cc 100644 --- a/comps/embeddings/src/integrations/predictionguard_embedding.py +++ b/comps/embeddings/src/integrations/predictionguard_embedding.py @@ -8,11 +8,13 @@ from comps import CustomLogger, OpeaComponent, ServiceType from comps.cores.proto.api_protocol import EmbeddingRequest, EmbeddingResponse, EmbeddingResponseData +from comps import OpeaComponentRegistry logger = CustomLogger("predictionguard_embedding") logflag = os.getenv("LOGFLAG", False) +@OpeaComponentRegistry.register("OPEA_PREDICTIONGUARD_EMBEDDING") class PredictionguardEmbedding(OpeaComponent): """A specialized embedding component derived from OpeaComponent for interacting with Prediction Guard services. diff --git a/comps/embeddings/src/opea_embedding_microservice.py b/comps/embeddings/src/opea_embedding_microservice.py index ade1b6b48a..e1797414d0 100644 --- a/comps/embeddings/src/opea_embedding_microservice.py +++ b/comps/embeddings/src/opea_embedding_microservice.py @@ -9,42 +9,23 @@ from comps import ( CustomLogger, - OpeaComponentController, ServiceType, opea_microservices, register_microservice, register_statistics, statistics_dict, + OpeaComponentLoader ) from comps.cores.proto.api_protocol import EmbeddingRequest, EmbeddingResponse logger = CustomLogger("opea_embedding_microservice") logflag = os.getenv("LOGFLAG", False) -# Initialize OpeaComponentController -controller = OpeaComponentController() - -# Register components -try: - # Instantiate Embedding components and register it to controller - if os.getenv("TEI_EMBEDDING_ENDPOINT"): - opea_tei_embedding = OpeaTEIEmbedding( - name="OpeaTEIEmbedding", - description="OPEA TEI Embedding Service", - ) - controller.register(opea_tei_embedding) - if os.getenv("PREDICTIONGUARD_API_KEY"): - predictionguard_embedding = PredictionguardEmbedding( - name="PredictionGuardEmbedding", - description="Prediction Guard Embedding Service", - ) - controller.register(predictionguard_embedding) - - # Discover and activate a healthy component - controller.discover_and_activate() -except Exception as e: - logger.error(f"Failed to initialize components: {e}") - +embedding_component_name = os.getenv("EMBEDDING_COMPONENT_NAME", "OPEA_TEI_EMBEDDING") +# Initialize OpeaComponentLoader +loader = OpeaComponentLoader(embedding_component_name, + name=embedding_component_name, + description=f"OPEA Embedding Component: {embedding_component_name}") @register_microservice( name="opea_service@embedding", @@ -62,8 +43,8 @@ async def embedding(input: EmbeddingRequest) -> EmbeddingResponse: logger.info(f"Input received: {input}") try: - # Use the controller to invoke the active component - embedding_response = await controller.invoke(input) + # Use the loader to invoke the component + embedding_response = await loader.invoke(input) # Log the result if logging is enabled if logflag: diff --git a/tests/cores/common/test_component.py b/tests/cores/common/test_component.py index 7b1a2cdbf9..64f7f7922b 100644 --- a/tests/cores/common/test_component.py +++ b/tests/cores/common/test_component.py @@ -5,7 +5,7 @@ import unittest from unittest.mock import AsyncMock, MagicMock -from comps import OpeaComponent, OpeaComponentController +from comps import OpeaComponent, OpeaComponentRegistry, OpeaComponentLoader class TestOpeaComponent(unittest.TestCase): @@ -40,110 +40,72 @@ def test_update_config(self): self.assertEqual(component.config["key"], "new_value") -class TestOpeaComponentController(unittest.TestCase): +class TestOpeaComponentRegistry(unittest.TestCase): def test_register_component(self): - controller = OpeaComponentController() - component = MagicMock() - component.name = "TestComponent" - controller.register(component) + # Create a mock component class + class MockComponent(OpeaComponent): + def check_health(self) -> bool: + return True - self.assertIn("TestComponent", controller.components) + async def invoke(self, *args, **kwargs): + return "Service accessed" - with self.assertRaises(ValueError): - controller.register(component) + # Register the component + OpeaComponentRegistry.register("MockComponent")(MockComponent) - def test_discover_and_activate(self): - controller = OpeaComponentController() + # Retrieve the component and ensure it's correct + retrieved_component_class = OpeaComponentRegistry.get("MockComponent") + self.assertEqual(retrieved_component_class, MockComponent) - # Mock a healthy component - component1 = MagicMock() - component1.name = "Component1" - component1.check_health.return_value = True + # Test exception for already registered component + with self.assertRaises(ValueError): + OpeaComponentRegistry.register("MockComponent")(MockComponent) - # Register and activate the healthy component - controller.register(component1) - controller.discover_and_activate() + def test_unregister_component(self): + # Create a mock component class + class MockComponent(OpeaComponent): + def check_health(self) -> bool: + return True - # Ensure the component is activated - self.assertEqual(controller.active_component, component1) + async def invoke(self, *args, **kwargs): + return "Service accessed" - # Add another component that is unhealthy - component2 = MagicMock() - component2.name = "Component2" - component2.check_health.return_value = False - controller.register(component2) + # Register and then unregister the component + OpeaComponentRegistry.register("MockComponent")(MockComponent) + OpeaComponentRegistry.unregister("MockComponent") - # Call discover_and_activate again; the active component should remain the same - controller.discover_and_activate() - self.assertEqual(controller.active_component, component1) + # Ensure the component is no longer in the registry + with self.assertRaises(KeyError): + OpeaComponentRegistry.get("MockComponent") - def test_invoke_no_active_component(self): - controller = OpeaComponentController() - with self.assertRaises(RuntimeError): - asyncio.run(controller.invoke("arg1", key="value")) - def test_invoke_with_active_component(self): - controller = OpeaComponentController() +class TestOpeaComponentLoader(unittest.TestCase): + def test_invoke_registered_component(self): + # Mock a component with the invoke method + class MockComponent(OpeaComponent): + def check_health(self) -> bool: + return True - # Mock a component - component = MagicMock() - component.name = "TestComponent" - component.check_health.return_value = True - component.invoke = AsyncMock(return_value="Service accessed") + async def invoke(self, *args, **kwargs): + return "Service accessed" - # Register and activate the component - controller.register(component) - controller.discover_and_activate() + # Register the mock component + OpeaComponentRegistry.register("MockComponent")(MockComponent) - # Invoke using the active component - result = asyncio.run(controller.invoke("arg1", key="value")) + # Create loader for the component + loader = OpeaComponentLoader("MockComponent") + + # Invoke the component + result = asyncio.run(loader.invoke("arg1", key="value")) - # Assert the result and method call + # Check the result self.assertEqual(result, "Service accessed") - component.invoke.assert_called_with("arg1", key="value") - - def test_discover_then_invoke(self): - """Ensures that `discover_and_activate` and `invoke` work correctly when called sequentially.""" - controller = OpeaComponentController() - - # Mock a healthy component - component1 = MagicMock() - component1.name = "Component1" - component1.check_health.return_value = True - component1.invoke = AsyncMock(return_value="Result from Component1") - - # Register the component - controller.register(component1) - - # Discover and activate - controller.discover_and_activate() - - # Ensure the component is activated - self.assertEqual(controller.active_component, component1) - - # Call invoke separately - result = asyncio.run(controller.invoke("test_input")) - self.assertEqual(result, "Result from Component1") - component1.invoke.assert_called_once_with("test_input") - - def test_list_components(self): - controller = OpeaComponentController() - - # Mock components - component1 = MagicMock() - component1.name = "Component1" - component2 = MagicMock() - component2.name = "Component2" - - # Register components - controller.register(component1) - controller.register(component2) - - # Assert the components list - components_list = controller.list_components() - self.assertIn("Component1", components_list) - self.assertIn("Component2", components_list) + def test_invoke_unregistered_component(self): + # Attempt to load a component that is not registered + with self.assertRaises(KeyError): + OpeaComponentLoader("UnregisteredComponent") if __name__ == "__main__": unittest.main() + diff --git a/tests/embeddings/test_embeddings_multimodal.sh b/tests/embeddings/test_embeddings_multimodal.sh index 34297c467c..4ad3b48362 100644 --- a/tests/embeddings/test_embeddings_multimodal.sh +++ b/tests/embeddings/test_embeddings_multimodal.sh @@ -46,6 +46,7 @@ function build_docker_images() { function start_service() { cd $WORKPATH cd comps/embeddings/deployment/docker_compose/ + export EMBEDDING_COMPONENT_NAME="OPEA_MULTIMODAL_EMBEDDING_BRIDGETOWER" docker compose -f compose_multimodal_bridgetower.yaml up -d sleep 30 } diff --git a/tests/embeddings/test_embeddings_multimodal_on_intel_hpu.sh b/tests/embeddings/test_embeddings_multimodal_on_intel_hpu.sh index 2438916f1e..df5ed41062 100644 --- a/tests/embeddings/test_embeddings_multimodal_on_intel_hpu.sh +++ b/tests/embeddings/test_embeddings_multimodal_on_intel_hpu.sh @@ -46,6 +46,7 @@ function build_docker_images() { function start_service() { cd $WORKPATH cd comps/embeddings/deployment/docker_compose/ + export EMBEDDING_COMPONENT_NAME="OPEA_MULTIMODAL_EMBEDDING_BRIDGETOWER" docker compose -f compose_multimodal_bridgetower_intel_hpu.yaml up -d sleep 30 } diff --git a/tests/embeddings/test_embeddings_predictionguard.sh b/tests/embeddings/test_embeddings_predictionguard.sh index ea834decc5..9be7baf7fc 100644 --- a/tests/embeddings/test_embeddings_predictionguard.sh +++ b/tests/embeddings/test_embeddings_predictionguard.sh @@ -25,6 +25,7 @@ function build_docker_images() { function start_service() { pg_service_port=5124 unset http_proxy + export EMBEDDING_COMPONENT_NAME="OPEA_PREDICTIONGUARD_EMBEDDING" docker run -d --name=test-comps-embedding-pg-server \ -e LOGFLAG=True -e http_proxy=$http_proxy -e https_proxy=$https_proxy \ -e PREDICTIONGUARD_API_KEY=${PREDICTIONGUARD_API_KEY} \ diff --git a/tests/embeddings/test_embeddings_tei.sh b/tests/embeddings/test_embeddings_tei.sh index f419a2a6f0..394a2c3527 100644 --- a/tests/embeddings/test_embeddings_tei.sh +++ b/tests/embeddings/test_embeddings_tei.sh @@ -25,6 +25,7 @@ function start_service() { unset http_proxy docker run -d --name="test-comps-embedding-tei-endpoint" -p $tei_endpoint:80 -v ./data:/data --pull always ghcr.io/huggingface/text-embeddings-inference:cpu-1.5 --model-id $model sleep 3m + export EMBEDDING_COMPONENT_NAME="OPEA_TEI_EMBEDDING" export TEI_EMBEDDING_ENDPOINT="http://${ip_address}:${tei_endpoint}" tei_service_port=5002 docker run -d --name="test-comps-embedding-tei-server" -e LOGFLAG=True -e http_proxy=$http_proxy -e https_proxy=$https_proxy -p ${tei_service_port}:6000 --ipc=host -e TEI_EMBEDDING_ENDPOINT=$TEI_EMBEDDING_ENDPOINT opea/embedding:comps From b611dd109444861cec685210a708fb05f13cca22 Mon Sep 17 00:00:00 2001 From: lvliang-intel Date: Fri, 3 Jan 2025 13:30:25 +0800 Subject: [PATCH 02/15] update env Signed-off-by: lvliang-intel --- .../compose_multimodal_bridgetower.yaml | 1 + ...pose_multimodal_bridgetower_intel_hpu.yaml | 1 + .../compose_predictionguard.yaml | 1 + .../docker_compose/compose_tei.yaml | 1 + tests/cores/common/test_component.py | 39 +++++++++++-------- .../embeddings/test_embeddings_multimodal.sh | 1 - ...test_embeddings_multimodal_on_intel_hpu.sh | 1 - .../test_embeddings_predictionguard.sh | 2 +- tests/embeddings/test_embeddings_tei.sh | 3 +- 9 files changed, 28 insertions(+), 22 deletions(-) diff --git a/comps/embeddings/deployment/docker_compose/compose_multimodal_bridgetower.yaml b/comps/embeddings/deployment/docker_compose/compose_multimodal_bridgetower.yaml index ef7e136ae6..c7044ac296 100644 --- a/comps/embeddings/deployment/docker_compose/compose_multimodal_bridgetower.yaml +++ b/comps/embeddings/deployment/docker_compose/compose_multimodal_bridgetower.yaml @@ -31,6 +31,7 @@ services: http_proxy: ${http_proxy} https_proxy: ${https_proxy} MULTIMODAL_EMBEDDING: true + EMBEDDING_COMPONENT_NAME: "OPEA_MULTIMODAL_EMBEDDING_BRIDGETOWER" MMEI_EMBEDDING_ENDPOINT: ${MMEI_EMBEDDING_ENDPOINT} MM_EMBEDDING_PORT_MICROSERVICE: ${MM_EMBEDDING_PORT_MICROSERVICE} restart: unless-stopped diff --git a/comps/embeddings/deployment/docker_compose/compose_multimodal_bridgetower_intel_hpu.yaml b/comps/embeddings/deployment/docker_compose/compose_multimodal_bridgetower_intel_hpu.yaml index 347150f458..946e68f730 100644 --- a/comps/embeddings/deployment/docker_compose/compose_multimodal_bridgetower_intel_hpu.yaml +++ b/comps/embeddings/deployment/docker_compose/compose_multimodal_bridgetower_intel_hpu.yaml @@ -35,6 +35,7 @@ services: http_proxy: ${http_proxy} https_proxy: ${https_proxy} MULTIMODAL_EMBEDDING: true + EMBEDDING_COMPONENT_NAME: "OPEA_MULTIMODAL_EMBEDDING_BRIDGETOWER" MMEI_EMBEDDING_ENDPOINT: ${MMEI_EMBEDDING_ENDPOINT} MM_EMBEDDING_PORT_MICROSERVICE: ${MM_EMBEDDING_PORT_MICROSERVICE} restart: unless-stopped diff --git a/comps/embeddings/deployment/docker_compose/compose_predictionguard.yaml b/comps/embeddings/deployment/docker_compose/compose_predictionguard.yaml index 192f278157..6ea2fa4d55 100644 --- a/comps/embeddings/deployment/docker_compose/compose_predictionguard.yaml +++ b/comps/embeddings/deployment/docker_compose/compose_predictionguard.yaml @@ -14,6 +14,7 @@ services: https_proxy: ${https_proxy} PG_EMBEDDING_MODEL_NAME: ${PG_EMBEDDING_MODEL_NAME} PREDICTIONGUARD_API_KEY: ${PREDICTIONGUARD_API_KEY} + EMBEDDING_COMPONENT_NAME: "OPEA_PREDICTIONGUARD_EMBEDDING" restart: unless-stopped networks: diff --git a/comps/embeddings/deployment/docker_compose/compose_tei.yaml b/comps/embeddings/deployment/docker_compose/compose_tei.yaml index 0ab83969e8..da19212b32 100644 --- a/comps/embeddings/deployment/docker_compose/compose_tei.yaml +++ b/comps/embeddings/deployment/docker_compose/compose_tei.yaml @@ -33,6 +33,7 @@ services: http_proxy: ${http_proxy} https_proxy: ${https_proxy} TEI_EMBEDDING_ENDPOINT: ${TEI_EMBEDDING_ENDPOINT} + EMBEDDING_COMPONENT_NAME: "OPEA_TEI_EMBEDDING" depends_on: tei-embedding-service: condition: service_healthy diff --git a/tests/cores/common/test_component.py b/tests/cores/common/test_component.py index 64f7f7922b..e53b49f250 100644 --- a/tests/cores/common/test_component.py +++ b/tests/cores/common/test_component.py @@ -3,13 +3,14 @@ import asyncio import unittest -from unittest.mock import AsyncMock, MagicMock - from comps import OpeaComponent, OpeaComponentRegistry, OpeaComponentLoader class TestOpeaComponent(unittest.TestCase): class MockOpeaComponent(OpeaComponent): + def __init__(self, name, type, description, config=None): + super().__init__(name, type, description, config) + def check_health(self) -> bool: return True @@ -18,7 +19,6 @@ async def invoke(self, *args, **kwargs): def test_initialization(self): component = self.MockOpeaComponent("TestComponent", "embedding", "Test description") - self.assertEqual(component.name, "TestComponent") self.assertEqual(component.type, "embedding") self.assertEqual(component.description, "Test description") @@ -27,7 +27,6 @@ def test_initialization(self): def test_get_meta(self): component = self.MockOpeaComponent("TestComponent", "embedding", "Test description", {"key": "value"}) meta = component.get_meta() - self.assertEqual(meta["name"], "TestComponent") self.assertEqual(meta["type"], "embedding") self.assertEqual(meta["description"], "Test description") @@ -36,34 +35,37 @@ def test_get_meta(self): def test_update_config(self): component = self.MockOpeaComponent("TestComponent", "embedding", "Test description") component.update_config("key", "new_value") - self.assertEqual(component.config["key"], "new_value") class TestOpeaComponentRegistry(unittest.TestCase): + def setUp(self): + # Ensure the component is unregistered before each test to avoid conflicts + if "MockComponent" in OpeaComponentRegistry._registry: + OpeaComponentRegistry.unregister("MockComponent") + def test_register_component(self): - # Create a mock component class class MockComponent(OpeaComponent): + def __init__(self, name, type, description, config=None): + super().__init__(name, type, description, config) + def check_health(self) -> bool: return True async def invoke(self, *args, **kwargs): return "Service accessed" - # Register the component + # Register the mock component OpeaComponentRegistry.register("MockComponent")(MockComponent) - # Retrieve the component and ensure it's correct retrieved_component_class = OpeaComponentRegistry.get("MockComponent") self.assertEqual(retrieved_component_class, MockComponent) - # Test exception for already registered component - with self.assertRaises(ValueError): - OpeaComponentRegistry.register("MockComponent")(MockComponent) - def test_unregister_component(self): - # Create a mock component class class MockComponent(OpeaComponent): + def __init__(self, name, type, description, config=None): + super().__init__(name, type, description, config) + def check_health(self) -> bool: return True @@ -73,7 +75,6 @@ async def invoke(self, *args, **kwargs): # Register and then unregister the component OpeaComponentRegistry.register("MockComponent")(MockComponent) OpeaComponentRegistry.unregister("MockComponent") - # Ensure the component is no longer in the registry with self.assertRaises(KeyError): OpeaComponentRegistry.get("MockComponent") @@ -81,8 +82,10 @@ async def invoke(self, *args, **kwargs): class TestOpeaComponentLoader(unittest.TestCase): def test_invoke_registered_component(self): - # Mock a component with the invoke method class MockComponent(OpeaComponent): + def __init__(self, name, type, description, config=None): + super().__init__(name, type, description, config) + def check_health(self) -> bool: return True @@ -93,8 +96,8 @@ async def invoke(self, *args, **kwargs): OpeaComponentRegistry.register("MockComponent")(MockComponent) # Create loader for the component - loader = OpeaComponentLoader("MockComponent") - + loader = OpeaComponentLoader("MockComponent", name="MockComponent", type="embedding", description="Test component") + # Invoke the component result = asyncio.run(loader.invoke("arg1", key="value")) @@ -106,6 +109,8 @@ def test_invoke_unregistered_component(self): with self.assertRaises(KeyError): OpeaComponentLoader("UnregisteredComponent") + if __name__ == "__main__": unittest.main() + diff --git a/tests/embeddings/test_embeddings_multimodal.sh b/tests/embeddings/test_embeddings_multimodal.sh index 4ad3b48362..34297c467c 100644 --- a/tests/embeddings/test_embeddings_multimodal.sh +++ b/tests/embeddings/test_embeddings_multimodal.sh @@ -46,7 +46,6 @@ function build_docker_images() { function start_service() { cd $WORKPATH cd comps/embeddings/deployment/docker_compose/ - export EMBEDDING_COMPONENT_NAME="OPEA_MULTIMODAL_EMBEDDING_BRIDGETOWER" docker compose -f compose_multimodal_bridgetower.yaml up -d sleep 30 } diff --git a/tests/embeddings/test_embeddings_multimodal_on_intel_hpu.sh b/tests/embeddings/test_embeddings_multimodal_on_intel_hpu.sh index df5ed41062..2438916f1e 100644 --- a/tests/embeddings/test_embeddings_multimodal_on_intel_hpu.sh +++ b/tests/embeddings/test_embeddings_multimodal_on_intel_hpu.sh @@ -46,7 +46,6 @@ function build_docker_images() { function start_service() { cd $WORKPATH cd comps/embeddings/deployment/docker_compose/ - export EMBEDDING_COMPONENT_NAME="OPEA_MULTIMODAL_EMBEDDING_BRIDGETOWER" docker compose -f compose_multimodal_bridgetower_intel_hpu.yaml up -d sleep 30 } diff --git a/tests/embeddings/test_embeddings_predictionguard.sh b/tests/embeddings/test_embeddings_predictionguard.sh index 9be7baf7fc..7ffacfaf4a 100644 --- a/tests/embeddings/test_embeddings_predictionguard.sh +++ b/tests/embeddings/test_embeddings_predictionguard.sh @@ -25,10 +25,10 @@ function build_docker_images() { function start_service() { pg_service_port=5124 unset http_proxy - export EMBEDDING_COMPONENT_NAME="OPEA_PREDICTIONGUARD_EMBEDDING" docker run -d --name=test-comps-embedding-pg-server \ -e LOGFLAG=True -e http_proxy=$http_proxy -e https_proxy=$https_proxy \ -e PREDICTIONGUARD_API_KEY=${PREDICTIONGUARD_API_KEY} \ + -e EMBEDDING_COMPONENT_NAME="OPEA_PREDICTIONGUARD_EMBEDDING" \ -p ${pg_service_port}:6000 --ipc=host opea/embedding:comps sleep 60 } diff --git a/tests/embeddings/test_embeddings_tei.sh b/tests/embeddings/test_embeddings_tei.sh index 394a2c3527..b3d2a30198 100644 --- a/tests/embeddings/test_embeddings_tei.sh +++ b/tests/embeddings/test_embeddings_tei.sh @@ -25,10 +25,9 @@ function start_service() { unset http_proxy docker run -d --name="test-comps-embedding-tei-endpoint" -p $tei_endpoint:80 -v ./data:/data --pull always ghcr.io/huggingface/text-embeddings-inference:cpu-1.5 --model-id $model sleep 3m - export EMBEDDING_COMPONENT_NAME="OPEA_TEI_EMBEDDING" export TEI_EMBEDDING_ENDPOINT="http://${ip_address}:${tei_endpoint}" tei_service_port=5002 - docker run -d --name="test-comps-embedding-tei-server" -e LOGFLAG=True -e http_proxy=$http_proxy -e https_proxy=$https_proxy -p ${tei_service_port}:6000 --ipc=host -e TEI_EMBEDDING_ENDPOINT=$TEI_EMBEDDING_ENDPOINT opea/embedding:comps + docker run -d --name="test-comps-embedding-tei-server" -e LOGFLAG=True -e http_proxy=$http_proxy -e https_proxy=$https_proxy -p ${tei_service_port}:6000 --ipc=host -e TEI_EMBEDDING_ENDPOINT=$TEI_EMBEDDING_ENDPOINT -e EMBEDDING_COMPONENT_NAME="OPEA_TEI_EMBEDDING" opea/embedding:comps sleep 15 } From 0b4967ecb4b6efd69c3b6af396821e790b4f478f Mon Sep 17 00:00:00 2001 From: lvliang-intel Date: Fri, 3 Jan 2025 13:42:44 +0800 Subject: [PATCH 03/15] add health check Signed-off-by: lvliang-intel --- .../integrations/opea_multimodal_embedding_bridgetower.py | 3 +++ comps/embeddings/src/integrations/opea_tei_embedding.py | 5 +++++ .../embeddings/src/integrations/predictionguard_embedding.py | 3 +++ comps/embeddings/src/opea_embedding_microservice.py | 3 --- 4 files changed, 11 insertions(+), 3 deletions(-) diff --git a/comps/embeddings/src/integrations/opea_multimodal_embedding_bridgetower.py b/comps/embeddings/src/integrations/opea_multimodal_embedding_bridgetower.py index ee5bafa0d4..87a7dc3523 100644 --- a/comps/embeddings/src/integrations/opea_multimodal_embedding_bridgetower.py +++ b/comps/embeddings/src/integrations/opea_multimodal_embedding_bridgetower.py @@ -25,6 +25,9 @@ class OpeaMultimodalEmbeddingBrigeTower(OpeaComponent): def __init__(self, name: str, description: str, config: dict = None): super().__init__(name, ServiceType.EMBEDDING.name.lower(), description, config) self.base_url = os.getenv("MMEI_EMBEDDING_ENDPOINT", "http://localhost:8080") + health_status = self.check_health() + if not health_status: + logger.error("OpeaMultimodalEmbeddingBrigeTower health check failed.") async def invoke(self, input: MultimodalDoc) -> EmbedMultimodalDoc: """Invokes the embedding service to generate embeddings for the provided input. diff --git a/comps/embeddings/src/integrations/opea_tei_embedding.py b/comps/embeddings/src/integrations/opea_tei_embedding.py index ae72bab154..af58fae4a5 100644 --- a/comps/embeddings/src/integrations/opea_tei_embedding.py +++ b/comps/embeddings/src/integrations/opea_tei_embedding.py @@ -34,6 +34,11 @@ def __init__(self, name: str, description: str, config: dict = None): self.base_url = os.getenv("TEI_EMBEDDING_ENDPOINT", "http://localhost:8080") self.client = self._initialize_client() + health_status = self.check_health() + if not health_status: + logger.error("OpeaTEIEmbedding health check failed.") + + def _initialize_client(self) -> AsyncInferenceClient: """Initializes the AsyncInferenceClient.""" access_token = ( diff --git a/comps/embeddings/src/integrations/predictionguard_embedding.py b/comps/embeddings/src/integrations/predictionguard_embedding.py index c1e19fe2cc..5c294aef28 100644 --- a/comps/embeddings/src/integrations/predictionguard_embedding.py +++ b/comps/embeddings/src/integrations/predictionguard_embedding.py @@ -32,6 +32,9 @@ def __init__(self, name: str, description: str, config: dict = None): else: logger.info("No PredictionGuard API KEY provided, client not instantiated") self.model_name = os.getenv("PG_EMBEDDING_MODEL_NAME", "bridgetower-large-itm-mlm-itc") + health_status = self.check_health() + if not health_status: + logger.error("PredictionguardEmbedding health check failed.") def check_health(self) -> bool: """Checks the health of the Prediction Guard embedding service. diff --git a/comps/embeddings/src/opea_embedding_microservice.py b/comps/embeddings/src/opea_embedding_microservice.py index e1797414d0..46693f8d36 100644 --- a/comps/embeddings/src/opea_embedding_microservice.py +++ b/comps/embeddings/src/opea_embedding_microservice.py @@ -4,9 +4,6 @@ import os import time -from integrations.opea_tei_embedding import OpeaTEIEmbedding -from integrations.predictionguard_embedding import PredictionguardEmbedding - from comps import ( CustomLogger, ServiceType, From a588291e70b645911a9752722ee0f9c489da01e0 Mon Sep 17 00:00:00 2001 From: lvliang-intel Date: Fri, 3 Jan 2025 14:02:39 +0800 Subject: [PATCH 04/15] update mulimodal embedding Signed-off-by: lvliang-intel --- comps/embeddings/src/__init__.py | 4 +++ .../opea_multimodal_embedding_microservice.py | 30 +++++-------------- 2 files changed, 12 insertions(+), 22 deletions(-) diff --git a/comps/embeddings/src/__init__.py b/comps/embeddings/src/__init__.py index 916f3a44b2..c3cfb8c095 100644 --- a/comps/embeddings/src/__init__.py +++ b/comps/embeddings/src/__init__.py @@ -1,2 +1,6 @@ # Copyright (C) 2024 Intel Corporation # SPDX-License-Identifier: Apache-2.0 + +from integrations.opea_tei_embedding import OpeaTEIEmbedding +from integrations.predictionguard_embedding import PredictionguardEmbedding +from integrations.opea_multimodal_embedding_bridgetower import OpeaMultimodalEmbeddingBrigeTower diff --git a/comps/embeddings/src/opea_multimodal_embedding_microservice.py b/comps/embeddings/src/opea_multimodal_embedding_microservice.py index 6f0ba8a78b..3a2c89bb32 100644 --- a/comps/embeddings/src/opea_multimodal_embedding_microservice.py +++ b/comps/embeddings/src/opea_multimodal_embedding_microservice.py @@ -4,40 +4,26 @@ import os import time -from integrations.opea_multimodal_embedding_bridgetower import OpeaMultimodalEmbeddingBrigeTower - from comps import ( CustomLogger, EmbedMultimodalDoc, MultimodalDoc, - OpeaComponentController, ServiceType, opea_microservices, register_microservice, register_statistics, statistics_dict, + OpeaComponentLoader ) logger = CustomLogger("opea_multimodal_embedding_microservice") logflag = os.getenv("LOGFLAG", False) -# Initialize OpeaComponentController -controller = OpeaComponentController() - -# Register components -try: - # Instantiate Embedding components and register it to controller - if os.getenv("MMEI_EMBEDDING_ENDPOINT"): - opea_mm_embedding_bt = OpeaMultimodalEmbeddingBrigeTower( - name="OpeaMultimodalEmbeddingBrigeTower", - description="OPEA Multimodal Embedding Service using BridgeTower", - ) - controller.register(opea_mm_embedding_bt) - - # Discover and activate a healthy component - controller.discover_and_activate() -except Exception as e: - logger.error(f"Failed to initialize components: {e}") +embedding_component_name = os.getenv("EMBEDDING_COMPONENT_NAME", "OPEA_MULTIMODAL_EMBEDDING_BRIDGETOWER") +# Initialize OpeaComponentLoader +loader = OpeaComponentLoader(embedding_component_name, + name=embedding_component_name, + description=f"OPEA Embedding Component: {embedding_component_name}") port = int(os.getenv("MM_EMBEDDING_PORT_MICROSERVICE", 6000)) @@ -60,8 +46,8 @@ async def embedding(input: MultimodalDoc) -> EmbedMultimodalDoc: logger.info(f"Input received: {input}") try: - # Use the controller to invoke the active component - embedding_response = await controller.invoke(input) + # Use the loader to invoke the component + embedding_response = await loader.invoke(input) # Log the result if logging is enabled if logflag: From 2b2bb5b9aec4a18c7947db1f84336e760a1bc0ac Mon Sep 17 00:00:00 2001 From: lvliang-intel Date: Fri, 3 Jan 2025 15:03:13 +0800 Subject: [PATCH 05/15] update import Signed-off-by: lvliang-intel --- comps/embeddings/src/__init__.py | 4 ---- comps/embeddings/src/opea_embedding_microservice.py | 3 +++ .../embeddings/src/opea_multimodal_embedding_microservice.py | 2 ++ 3 files changed, 5 insertions(+), 4 deletions(-) diff --git a/comps/embeddings/src/__init__.py b/comps/embeddings/src/__init__.py index c3cfb8c095..916f3a44b2 100644 --- a/comps/embeddings/src/__init__.py +++ b/comps/embeddings/src/__init__.py @@ -1,6 +1,2 @@ # Copyright (C) 2024 Intel Corporation # SPDX-License-Identifier: Apache-2.0 - -from integrations.opea_tei_embedding import OpeaTEIEmbedding -from integrations.predictionguard_embedding import PredictionguardEmbedding -from integrations.opea_multimodal_embedding_bridgetower import OpeaMultimodalEmbeddingBrigeTower diff --git a/comps/embeddings/src/opea_embedding_microservice.py b/comps/embeddings/src/opea_embedding_microservice.py index 46693f8d36..e1797414d0 100644 --- a/comps/embeddings/src/opea_embedding_microservice.py +++ b/comps/embeddings/src/opea_embedding_microservice.py @@ -4,6 +4,9 @@ import os import time +from integrations.opea_tei_embedding import OpeaTEIEmbedding +from integrations.predictionguard_embedding import PredictionguardEmbedding + from comps import ( CustomLogger, ServiceType, diff --git a/comps/embeddings/src/opea_multimodal_embedding_microservice.py b/comps/embeddings/src/opea_multimodal_embedding_microservice.py index 3a2c89bb32..811d4a3b55 100644 --- a/comps/embeddings/src/opea_multimodal_embedding_microservice.py +++ b/comps/embeddings/src/opea_multimodal_embedding_microservice.py @@ -4,6 +4,8 @@ import os import time +from integrations.opea_multimodal_embedding_bridgetower import OpeaMultimodalEmbeddingBrigeTower + from comps import ( CustomLogger, EmbedMultimodalDoc, From 515acff225505c98c17a79ccd08cc7120848ca6e Mon Sep 17 00:00:00 2001 From: lvliang-intel Date: Fri, 3 Jan 2025 16:59:53 +0800 Subject: [PATCH 06/15] refine other components Signed-off-by: lvliang-intel --- comps/animation/src/integration/opea.py | 6 ++- .../src/opea_animation_microservice.py | 24 +++-------- comps/asr/src/integrations/opea_whisper.py | 7 ++- comps/asr/src/opea_asr_microservice.py | 29 ++++--------- comps/dataprep/src/integrations/milvus.py | 6 ++- comps/dataprep/src/integrations/redis.py | 7 ++- ..._controller.py => opea_dataprep_loader.py} | 12 +++--- .../src/opea_dataprep_microservice.py | 43 ++++++------------- .../integration/opea_image2image_native.py | 7 ++- .../src/opea_image2image_microservice.py | 32 +++----------- comps/image2video/src/integrations/opea.py | 7 ++- .../src/opea_image2video_microservice.py | 29 ++++--------- .../docker_compose/text-generation_tgi.yaml | 1 + .../text-generation_vllm_langchain.yaml | 1 + .../src/text-generation/integrations/opea.py | 6 ++- .../text-generation/opea_llm_microservice.py | 27 ++++-------- comps/reranks/src/integrations/opea_tei.py | 7 ++- .../src/opea_reranking_microservice.py | 28 ++++-------- comps/retrievers/src/integrations/milvus.py | 7 ++- comps/retrievers/src/integrations/redis.py | 6 ++- .../src/opea_retrievers_microservice.py | 37 ++++------------ comps/text2sql/src/integrations/opea.py | 6 ++- .../src/opea_text2sql_microservice.py | 26 +++-------- comps/tts/src/integrations/opea_gptsovits.py | 7 ++- comps/tts/src/integrations/opea_speecht5.py | 6 ++- comps/tts/src/opea_tts_microservice.py | 35 ++++----------- tests/dataprep/test_dataprep_milvus.sh | 2 +- tests/dataprep/test_dataprep_redis.sh | 2 +- tests/retrievers/test_retrievers_milvus.sh | 2 +- tests/tts/test_tts_opea_gptsovits.sh | 2 +- 30 files changed, 161 insertions(+), 256 deletions(-) rename comps/dataprep/src/{opea_dataprep_controller.py => opea_dataprep_loader.py} (65%) diff --git a/comps/animation/src/integration/opea.py b/comps/animation/src/integration/opea.py index 16cb2b5d12..c0dbf1845e 100644 --- a/comps/animation/src/integration/opea.py +++ b/comps/animation/src/integration/opea.py @@ -5,18 +5,22 @@ import requests -from comps import CustomLogger, OpeaComponent, ServiceType +from comps import CustomLogger, OpeaComponent, ServiceType, OpeaComponentRegistry logger = CustomLogger("opea_animation") logflag = os.getenv("LOGFLAG", False) +@OpeaComponentRegistry.register("OPEA_ANIMATION") class OpeaAnimation(OpeaComponent): """A specialized animation component derived from OpeaComponent.""" def __init__(self, name: str, description: str, config: dict = None): super().__init__(name, ServiceType.ANIMATION.name.lower(), description, config) self.base_url = os.getenv("WAV2LIP_ENDPOINT", "http://localhost:7860") + health_status = self.check_health() + if not health_status: + logger.error("OpeaAnimation health check failed.") def invoke(self, input: str): """Invokes the animation service to generate embeddings for the animation input. diff --git a/comps/animation/src/opea_animation_microservice.py b/comps/animation/src/opea_animation_microservice.py index 13ea92cbbc..629c0b0367 100644 --- a/comps/animation/src/opea_animation_microservice.py +++ b/comps/animation/src/opea_animation_microservice.py @@ -9,7 +9,7 @@ import time # GenAIComps -from comps import CustomLogger, OpeaComponentController +from comps import CustomLogger, OpeaComponentLoader from comps.animation.src.integration.opea import OpeaAnimation logger = CustomLogger("opea_animation") @@ -24,22 +24,12 @@ statistics_dict, ) -# Initialize OpeaComponentController -controller = OpeaComponentController() -# Register components -try: - # Instantiate Animation component and register it to controller - opea_animation = OpeaAnimation( - name="OpeaAnimation", - description="OPEA Animation Service", - ) - controller.register(opea_animation) - - # Discover and activate a healthy component - controller.discover_and_activate() -except Exception as e: - logger.error(f"Failed to initialize components: {e}") +animation_component_name = os.getenv("ANIMATION_COMPONENT_NAME", "OPEA_ANIMATION") +# Initialize OpeaComponentLoader +loader = OpeaComponentLoader(animation_component_name, + name=animation_component_name, + description=f"OPEA ANIMATION Component: {animation_component_name}") # Register the microservice @@ -56,7 +46,7 @@ def animate(audio: Base64ByteStrDoc): start = time.time() - outfile = opea_animation.invoke(audio.byte_str) + outfile = loader.invoke(audio.byte_str) if logflag: logger.info(f"Video generated successfully, check {outfile} for the result.") diff --git a/comps/asr/src/integrations/opea_whisper.py b/comps/asr/src/integrations/opea_whisper.py index 9a9c917151..135f128252 100644 --- a/comps/asr/src/integrations/opea_whisper.py +++ b/comps/asr/src/integrations/opea_whisper.py @@ -8,13 +8,13 @@ import requests from fastapi import File, Form, UploadFile -from comps import CustomLogger, OpeaComponent, ServiceType +from comps import CustomLogger, OpeaComponent, ServiceType, OpeaComponentRegistry from comps.cores.proto.api_protocol import AudioTranscriptionResponse logger = CustomLogger("opea_whisper") logflag = os.getenv("LOGFLAG", False) - +@OpeaComponentRegistry.register("OPEA_WHISPER_ASR") class OpeaWhisperAsr(OpeaComponent): """A specialized ASR (Automatic Speech Recognition) component derived from OpeaComponent for Whisper ASR services. @@ -25,6 +25,9 @@ class OpeaWhisperAsr(OpeaComponent): def __init__(self, name: str, description: str, config: dict = None): super().__init__(name, ServiceType.ASR.name.lower(), description, config) self.base_url = os.getenv("ASR_ENDPOINT", "http://localhost:7066") + health_status = self.check_health() + if not health_status: + logger.error("OpeaWhisperAsr health check failed.") async def invoke( self, diff --git a/comps/asr/src/opea_asr_microservice.py b/comps/asr/src/opea_asr_microservice.py index c56b52bfcb..a3313d4ed7 100644 --- a/comps/asr/src/opea_asr_microservice.py +++ b/comps/asr/src/opea_asr_microservice.py @@ -12,7 +12,7 @@ Base64ByteStrDoc, CustomLogger, LLMParamsDoc, - OpeaComponentController, + OpeaComponentLoader, ServiceType, opea_microservices, register_microservice, @@ -24,24 +24,11 @@ logger = CustomLogger("opea_asr_microservice") logflag = os.getenv("LOGFLAG", False) -# Initialize OpeaComponentController -controller = OpeaComponentController() - -# Register components -try: - # Instantiate ASR components - opea_whisper = OpeaWhisperAsr( - name="OpeaWhisperAsr", - description="OPEA Whisper ASR Service", - ) - - # Register components with the controller - controller.register(opea_whisper) - - # Discover and activate a healthy component - controller.discover_and_activate() -except Exception as e: - logger.error(f"Failed to initialize components: {e}") +asr_component_name = os.getenv("ASR_COMPONENT_NAME", "OPEA_WHISPER_ASR") +# Initialize OpeaComponentLoader +loader = OpeaComponentLoader(asr_component_name, + name=asr_component_name, + description=f"OPEA ASR Component: {asr_component_name}") @register_microservice( @@ -69,8 +56,8 @@ async def audio_to_text( logger.info("ASR file uploaded.") try: - # Use the controller to invoke the active component - asr_response = await controller.invoke( + # Use the loader to invoke the component + asr_response = await loader.invoke( file=file, model=model, language=language, diff --git a/comps/dataprep/src/integrations/milvus.py b/comps/dataprep/src/integrations/milvus.py index c0f4b959ec..058a97125f 100644 --- a/comps/dataprep/src/integrations/milvus.py +++ b/comps/dataprep/src/integrations/milvus.py @@ -15,7 +15,7 @@ from langchain_milvus.vectorstores import Milvus from langchain_text_splitters import HTMLHeaderTextSplitter -from comps import CustomLogger, DocPath, OpeaComponent, ServiceType +from comps import CustomLogger, DocPath, OpeaComponent, ServiceType, OpeaComponentRegistry from comps.dataprep.src.utils import ( create_upload_folder, document_loader, @@ -157,6 +157,7 @@ def delete_by_partition_field(my_milvus, partition_field): logger.info(f"[ delete partition ] delete success: {res}") +@OpeaComponentRegistry.register("OPEA_DATAPREP_MILVUS") class OpeaMilvusDataprep(OpeaComponent): """A specialized dataprep component derived from OpeaComponent for milvus dataprep services. @@ -167,6 +168,9 @@ class OpeaMilvusDataprep(OpeaComponent): def __init__(self, name: str, description: str, config: dict = None): super().__init__(name, ServiceType.DATAPREP.name.lower(), description, config) self.embedder = self._initialize_embedder() + health_status = self.check_health() + if not health_status: + logger.error("OpeaMilvusDataprep health check failed.") def _initialize_embedder(self): if logflag: diff --git a/comps/dataprep/src/integrations/redis.py b/comps/dataprep/src/integrations/redis.py index 64375473db..241dd1a3bb 100644 --- a/comps/dataprep/src/integrations/redis.py +++ b/comps/dataprep/src/integrations/redis.py @@ -18,7 +18,7 @@ from redis.commands.search.field import TextField from redis.commands.search.indexDefinition import IndexDefinition, IndexType -from comps import CustomLogger, DocPath, OpeaComponent, ServiceType +from comps import CustomLogger, DocPath, OpeaComponent, ServiceType, OpeaComponentRegistry from comps.dataprep.src.utils import ( create_upload_folder, document_loader, @@ -214,7 +214,7 @@ def ingest_data_to_redis(doc_path: DocPath): file_name = doc_path.path.split("/")[-1] return ingest_chunks_to_redis(file_name, chunks) - +@OpeaComponentRegistry.register("OPEA_DATAPREP_REDIS") class OpeaRedisDataprep(OpeaComponent): """A specialized dataprep component derived from OpeaComponent for redis dataprep services. @@ -227,6 +227,9 @@ def __init__(self, name: str, description: str, config: dict = None): self.client = self._initialize_client() self.data_index_client = self.client.ft(INDEX_NAME) self.key_index_client = self.client.ft(KEY_INDEX_NAME) + health_status = self.check_health() + if not health_status: + logger.error("OpeaRedisDataprep health check failed.") def _initialize_client(self) -> redis.Redis: if logflag: diff --git a/comps/dataprep/src/opea_dataprep_controller.py b/comps/dataprep/src/opea_dataprep_loader.py similarity index 65% rename from comps/dataprep/src/opea_dataprep_controller.py rename to comps/dataprep/src/opea_dataprep_loader.py index f879776b5e..71fe6cab80 100644 --- a/comps/dataprep/src/opea_dataprep_controller.py +++ b/comps/dataprep/src/opea_dataprep_loader.py @@ -4,13 +4,13 @@ import os -from comps import CustomLogger, OpeaComponentController +from comps import CustomLogger, OpeaComponentLoader -logger = CustomLogger("opea_dataprep_controller") +logger = CustomLogger("opea_dataprep_loader") logflag = os.getenv("LOGFLAG", False) -class OpeaDataprepController(OpeaComponentController): +class OpeaDataprepLoader(OpeaComponentLoader): def __init__(self): super().__init__() @@ -19,15 +19,15 @@ def invoke(self, *args, **kwargs): async def ingest_files(self, *args, **kwargs): if logflag: - logger.info("[ dataprep controller ] ingest files") + logger.info("[ dataprep loader ] ingest files") return await self.active_component.ingest_files(*args, **kwargs) async def get_files(self, *args, **kwargs): if logflag: - logger.info("[ dataprep controller ] get files") + logger.info("[ dataprep loader ] get files") return await self.active_component.get_files(*args, **kwargs) async def delete_files(self, *args, **kwargs): if logflag: - logger.info("[ dataprep controller ] delete files") + logger.info("[ dataprep loader ] delete files") return await self.active_component.delete_files(*args, **kwargs) diff --git a/comps/dataprep/src/opea_dataprep_microservice.py b/comps/dataprep/src/opea_dataprep_microservice.py index 4ead0588b9..7f6aebd8d8 100644 --- a/comps/dataprep/src/opea_dataprep_microservice.py +++ b/comps/dataprep/src/opea_dataprep_microservice.py @@ -9,7 +9,7 @@ from fastapi import Body, File, Form, UploadFile from integrations.milvus import OpeaMilvusDataprep from integrations.redis import OpeaRedisDataprep -from opea_dataprep_controller import OpeaDataprepController +from opea_dataprep_loader import OpeaDataprepLoader from comps import ( CustomLogger, @@ -23,32 +23,13 @@ logger = CustomLogger("opea_dataprep_microservice") logflag = os.getenv("LOGFLAG", False) -dataprep_type = os.getenv("DATAPREP_TYPE", False) upload_folder = "./uploaded_files/" -# Initialize Controller -controller = OpeaDataprepController() - -# Register components -try: - # Instantiate Dataprep components and register it to controller - if dataprep_type == "redis": - redis_dataprep = OpeaRedisDataprep( - name="OpeaRedisDataprep", - description="OPEA Redis Dataprep Service", - ) - controller.register(redis_dataprep) - elif dataprep_type == "milvus": - milvus_dataprep = OpeaMilvusDataprep( - name="OpeaMilvusDataprep", - description="OPEA Milvus Dataprep Service", - ) - controller.register(milvus_dataprep) - - # Discover and activate a healthy component - controller.discover_and_activate() -except Exception as e: - logger.error(f"Failed to initialize components: {e}") +dataprep_component_name = os.getenv("DATAPREP_COMPONENT_NAME", "OPEA_DATAPREP_REDIS") +# Initialize OpeaComponentLoader +loader = OpeaDataprepLoader(dataprep_component_name, + name=dataprep_component_name, + description=f"OPEA DATAPREP Component: {dataprep_component_name}") @register_microservice( @@ -74,8 +55,8 @@ async def ingest_files( logger.info(f"[ ingest ] link_list:{link_list}") try: - # Use the controller to invoke the active component - response = await controller.ingest_files( + # Use the loader to invoke the component + response = await loader.ingest_files( files, link_list, chunk_size, chunk_overlap, process_table, table_strategy ) # Log the result if logging is enabled @@ -104,8 +85,8 @@ async def get_files(): logger.info("[ get ] start to get ingested files") try: - # Use the controller to invoke the active component - response = await controller.get_files() + # Use the loader to invoke the component + response = await loader.get_files() # Log the result if logging is enabled if logflag: logger.info(f"[ get ] ingested files: {response}") @@ -132,8 +113,8 @@ async def delete_files(file_path: str = Body(..., embed=True)): logger.info("[ delete ] start to delete ingested files") try: - # Use the controller to invoke the active component - response = await controller.delete_files(file_path) + # Use the loader to invoke the component + response = await loader.delete_files(file_path) # Log the result if logging is enabled if logflag: logger.info(f"[ delete ] deleted result: {response}") diff --git a/comps/image2image/src/integration/opea_image2image_native.py b/comps/image2image/src/integration/opea_image2image_native.py index 4399c12931..e0e467b700 100644 --- a/comps/image2image/src/integration/opea_image2image_native.py +++ b/comps/image2image/src/integration/opea_image2image_native.py @@ -4,7 +4,7 @@ import os import threading -from comps import CustomLogger, OpeaComponent, SDImg2ImgInputs, ServiceType +from comps import CustomLogger, OpeaComponent, SDImg2ImgInputs, ServiceType, OpeaComponentRegistry logger = CustomLogger("opea_imagetoimage") logflag = os.getenv("LOGFLAG", False) @@ -64,7 +64,7 @@ def initialize( logger.info("Stable Diffusion model initialized.") initialized = True - +@OpeaComponentRegistry.register("OPEA_IMAGE2IMAGE") class OpeaImageToImage(OpeaComponent): """A specialized ImageToImage component derived from OpeaComponent for Stable Diffusion model . @@ -94,6 +94,9 @@ def __init__( ) self.pipe = pipe self.seed = seed + health_status = self.check_health() + if not health_status: + logger.error("OpeaImageToImage health check failed.") def invoke(self, input: SDImg2ImgInputs): """Invokes the ImageToImage service to generate Images for the provided input. diff --git a/comps/image2image/src/opea_image2image_microservice.py b/comps/image2image/src/opea_image2image_microservice.py index 7cf8da5168..be929cab61 100644 --- a/comps/image2image/src/opea_image2image_microservice.py +++ b/comps/image2image/src/opea_image2image_microservice.py @@ -8,7 +8,7 @@ from comps import ( CustomLogger, - OpeaComponentController, + OpeaComponentLoader, SDImg2ImgInputs, SDOutputs, ServiceType, @@ -24,14 +24,11 @@ logger = CustomLogger("image2image") -# Initialize OpeaComponentController -controller = OpeaComponentController() - -# Register components -# try: - -# except Exception as e: -# logger.error(f"Failed to initialize components: {e}") +image2image_component_name = os.getenv("IMAGE2IMAGE_COMPONENT_NAME", "OPEA_IMAGE2IMAGE") +# Initialize OpeaComponentLoader +loader = OpeaComponentLoader(image2image_component_name, + name=image2image_component_name, + description=f"OPEA IMAGE2IMAGE Component: {image2image_component_name}") @register_microservice( @@ -46,7 +43,7 @@ @register_statistics(names=["opea_service@image2image"]) def image2image(input: SDImg2ImgInputs): start = time.time() - results = controller.invoke(input) + results = loader.invoke(input) statistics_dict["opea_service@image2image"].append_latency(time.time() - start, None) return SDOutputs(images=results) @@ -61,21 +58,6 @@ def image2image(input: SDImg2ImgInputs): parser.add_argument("--bf16", action="store_true") args = parser.parse_args() - # Instantiate Animation component and register it to controller - opea_imagetoimage = OpeaImageToImage( - name="OpeaImageToImage", - description="OPEA Image To Image Service", - seed=args.seed, - model_name_or_path=args.model_name_or_path, - device=args.device, - token=args.token, - bf16=args.bf16, - use_hpu_graphs=args.use_hpu_graphs, - ) - - controller.register(opea_imagetoimage) - # Discover and activate a healthy component - controller.discover_and_activate() logger.info("Image2image server started.") opea_microservices["opea_service@image2image"].start() diff --git a/comps/image2video/src/integrations/opea.py b/comps/image2video/src/integrations/opea.py index f1fabcb1dd..3460b55232 100644 --- a/comps/image2video/src/integrations/opea.py +++ b/comps/image2video/src/integrations/opea.py @@ -7,11 +7,11 @@ from diffusers import StableVideoDiffusionPipeline from diffusers.utils import export_to_video, load_image -from comps import CustomLogger, ImagesPath, OpeaComponent, ServiceType, VideoPath +from comps import CustomLogger, ImagesPath, OpeaComponent, ServiceType, VideoPath, OpeaComponentRegistry logger = CustomLogger("opea") - +@OpeaComponentRegistry.register("OPEA_IMAGE2VIDEO") class OpeaImage2video(OpeaComponent): """A specialized image2video component derived from OpeaComponent for image2video services.""" @@ -42,6 +42,9 @@ def __init__(self, name: str, description: str, config: dict = None): else: raise NotImplementedError(f"Only support cpu and hpu device now, device {self.device} not supported.") logger.info("Stable Video Diffusion model initialized.") + health_status = self.check_health() + if not health_status: + logger.error("OpeaImage2video health check failed.") async def invoke(self, input: ImagesPath) -> VideoPath: """Invokes the image2video service to generate video(s) for the provided input. diff --git a/comps/image2video/src/opea_image2video_microservice.py b/comps/image2video/src/opea_image2video_microservice.py index 0d941f351c..f30ab12c7f 100644 --- a/comps/image2video/src/opea_image2video_microservice.py +++ b/comps/image2video/src/opea_image2video_microservice.py @@ -2,6 +2,7 @@ # SPDX-License-Identifier: Apache-2.0 import argparse +import os import time from integrations.opea import OpeaImage2video @@ -9,7 +10,7 @@ from comps import ( CustomLogger, ImagesPath, - OpeaComponentController, + OpeaComponentLoader, ServiceType, VideoPath, opea_microservices, @@ -20,8 +21,11 @@ logger = CustomLogger("opea_image2video_microservice") -# Initialize OpeaComponentController -controller = OpeaComponentController() +image2video_component_name = os.getenv("IMAGE2VIDEO_COMPONENT_NAME", "OPEA_IMAGE2VIDEO") +# Initialize OpeaComponentLoader +loader = OpeaComponentLoader(image2video_component_name, + name=image2video_component_name, + description=f"OPEA RERANK Component: {image2video_component_name}") @register_microservice( @@ -37,8 +41,8 @@ async def image2video(input: ImagesPath): start = time.time() try: - # Use the controller to invoke the active component - results = await controller.invoke(input) + # Use the loader to invoke the component + results = await loader.invoke(input) statistics_dict["opea_service@image2video"].append_latency(time.time() - start, None) return results except Exception as e: @@ -57,20 +61,5 @@ async def image2video(input: ImagesPath): args = parser.parse_args() - # Register components - try: - # Instantiate Image2video components - opea_image2video = OpeaImage2video( - name="OpeaImage2video", description="OPEA Image2video Service", config=args.__dict__ - ) - - # Register components with the controller - controller.register(opea_image2video) - - # Discover and activate a healthy component - controller.discover_and_activate() - except Exception as e: - logger.error(f"Failed to initialize components: {e}") - logger.info("Image2video server started.") opea_microservices["opea_service@image2video"].start() diff --git a/comps/llms/deployment/docker_compose/text-generation_tgi.yaml b/comps/llms/deployment/docker_compose/text-generation_tgi.yaml index 63514f9680..6aabf2ede0 100644 --- a/comps/llms/deployment/docker_compose/text-generation_tgi.yaml +++ b/comps/llms/deployment/docker_compose/text-generation_tgi.yaml @@ -41,6 +41,7 @@ services: LLM_ENDPOINT: ${LLM_ENDPOINT} HF_TOKEN: ${HF_TOKEN} LLM_MODEL_ID: ${LLM_MODEL_ID} + LLM_COMPONENT_NAME: "OPEA_LLM" restart: unless-stopped networks: diff --git a/comps/llms/deployment/docker_compose/text-generation_vllm_langchain.yaml b/comps/llms/deployment/docker_compose/text-generation_vllm_langchain.yaml index 077ceee8b1..5e8b7ed9ba 100644 --- a/comps/llms/deployment/docker_compose/text-generation_vllm_langchain.yaml +++ b/comps/llms/deployment/docker_compose/text-generation_vllm_langchain.yaml @@ -39,6 +39,7 @@ services: vLLM_ENDPOINT: ${vLLM_ENDPOINT} HF_TOKEN: ${HF_TOKEN} LLM_MODEL: ${LLM_MODEL} + LLM_COMPONENT_NAME: "OPEA_LLM" restart: unless-stopped networks: diff --git a/comps/llms/src/text-generation/integrations/opea.py b/comps/llms/src/text-generation/integrations/opea.py index 877e8311b6..3eed727cd6 100644 --- a/comps/llms/src/text-generation/integrations/opea.py +++ b/comps/llms/src/text-generation/integrations/opea.py @@ -9,7 +9,7 @@ from langchain_core.prompts import PromptTemplate from openai import AsyncOpenAI -from comps import CustomLogger, LLMParamsDoc, OpeaComponent, SearchedDoc, ServiceType +from comps import CustomLogger, LLMParamsDoc, OpeaComponent, SearchedDoc, ServiceType, OpeaComponentRegistry from comps.cores.mega.utils import ConfigError, get_access_token, load_model_configs from comps.cores.proto.api_protocol import ChatCompletionRequest @@ -47,6 +47,7 @@ def get_llm_endpoint(): raise ConfigError(f"Input model {MODEL_NAME} not present in model_configs") +@OpeaComponentRegistry.register("OPEA_LLM") class OPEALLM(OpeaComponent): """A specialized OPEA LLM component derived from OpeaComponent for interacting with TGI/vLLM services based on OpenAI API. @@ -57,6 +58,9 @@ class OPEALLM(OpeaComponent): def __init__(self, name: str, description: str, config: dict = None): super().__init__(name, ServiceType.LLM.name.lower(), description, config) self.client = self._initialize_client() + health_status = self.check_health() + if not health_status: + logger.error("OPEALLM health check failed.") def _initialize_client(self) -> AsyncOpenAI: """Initializes the AsyncOpenAI.""" diff --git a/comps/llms/src/text-generation/opea_llm_microservice.py b/comps/llms/src/text-generation/opea_llm_microservice.py index 262214586f..ada39f284e 100644 --- a/comps/llms/src/text-generation/opea_llm_microservice.py +++ b/comps/llms/src/text-generation/opea_llm_microservice.py @@ -10,36 +10,25 @@ from comps import ( CustomLogger, LLMParamsDoc, - OpeaComponentController, SearchedDoc, ServiceType, opea_microservices, register_microservice, register_statistics, statistics_dict, + OpeaComponentLoader ) from comps.cores.proto.api_protocol import ChatCompletionRequest logger = CustomLogger("llm") logflag = os.getenv("LOGFLAG", False) -# Initialize OpeaComponentController -controller = OpeaComponentController() -# Register components -try: - opea_llm = OPEALLM( - name="OPEALLM", - description="OPEA LLM Service, compatible with OpenAI API", - ) - - # Register components with the controller - controller.register(opea_llm) - - # Discover and activate a healthy component - controller.discover_and_activate() -except Exception as e: - logger.error(f"Failed to initialize components: {e}") +llm_component_name = os.getenv("LLM_COMPONENT_NAME", "OPEA_LLM") +# Initialize OpeaComponentLoader +loader = OpeaComponentLoader(llm_component_name, + name=llm_component_name, + description=f"OPEA LLM Component: {llm_component_name}") @register_microservice( @@ -58,8 +47,8 @@ async def llm_generate(input: Union[LLMParamsDoc, ChatCompletionRequest, Searche logger.info(input) try: - # Use the controller to invoke the active component - response = await controller.invoke(input) + # Use the loader to invoke the component + response = await loader.invoke(input) # Record statistics statistics_dict["opea_service@llm"].append_latency(time.time() - start, None) return response diff --git a/comps/reranks/src/integrations/opea_tei.py b/comps/reranks/src/integrations/opea_tei.py index 09dda5e9d0..2fa48333cc 100644 --- a/comps/reranks/src/integrations/opea_tei.py +++ b/comps/reranks/src/integrations/opea_tei.py @@ -8,7 +8,7 @@ import requests from huggingface_hub import AsyncInferenceClient -from comps import CustomLogger, LLMParamsDoc, SearchedDoc, ServiceType +from comps import CustomLogger, LLMParamsDoc, SearchedDoc, ServiceType, OpeaComponentRegistry from comps.cores.common.component import OpeaComponent from comps.cores.mega.utils import get_access_token from comps.cores.proto.api_protocol import ( @@ -26,7 +26,7 @@ CLIENTID = os.getenv("CLIENTID") CLIENT_SECRET = os.getenv("CLIENT_SECRET") - +@OpeaComponentRegistry.register("OPEA_RERANK_TEI") class OPEATEIReranking(OpeaComponent): """A specialized reranking component derived from OpeaComponent for TEI reranking services. @@ -38,6 +38,9 @@ def __init__(self, name: str, description: str, config: dict = None): super().__init__(name, ServiceType.RERANK.name.lower(), description, config) self.base_url = os.getenv("TEI_RERANKING_ENDPOINT", "http://localhost:8808") self.client = self._initialize_client() + health_status = self.check_health() + if not health_status: + logger.error("OPEATEIReranking health check failed.") def _initialize_client(self) -> AsyncInferenceClient: """Initializes the AsyncInferenceClient.""" diff --git a/comps/reranks/src/opea_reranking_microservice.py b/comps/reranks/src/opea_reranking_microservice.py index 8d429b95d4..6e46fd060b 100644 --- a/comps/reranks/src/opea_reranking_microservice.py +++ b/comps/reranks/src/opea_reranking_microservice.py @@ -9,7 +9,7 @@ from comps import ( CustomLogger, - OpeaComponentController, + OpeaComponentLoader, ServiceType, opea_microservices, register_microservice, @@ -21,24 +21,12 @@ logger = CustomLogger("opea_reranking_microservice") logflag = os.getenv("LOGFLAG", False) -rerank_type = os.getenv("RERANK_TYPE", False) -controller = OpeaComponentController() -# Register components -try: - # Instantiate reranking components - if rerank_type == "tei": - opea_tei_reranking = OPEATEIReranking( - name="OPEATEIReranking", - description="OPEA TEI Reranking Service", - ) - # Register components with the controller - controller.register(opea_tei_reranking) - - # Discover and activate a healthy component - controller.discover_and_activate() -except Exception as e: - logger.error(f"Failed to initialize components: {e}") +rerank_component_name = os.getenv("RERANK_COMPONENT_NAME", "OPEA_RERANK_TEI") +# Initialize OpeaComponentLoader +loader = OpeaComponentLoader(rerank_component_name, + name=rerank_component_name, + description=f"OPEA RERANK Component: {rerank_component_name}") @register_microservice( @@ -59,8 +47,8 @@ async def reranking( logger.info(f"Input received: {input}") try: - # Use the controller to invoke the active component - reranking_response = await controller.invoke(input) + # Use the loader to invoke the component + reranking_response = await loader.invoke(input) # Log the result if logging is enabled if logflag: diff --git a/comps/retrievers/src/integrations/milvus.py b/comps/retrievers/src/integrations/milvus.py index 548022c099..8095700ba3 100644 --- a/comps/retrievers/src/integrations/milvus.py +++ b/comps/retrievers/src/integrations/milvus.py @@ -8,14 +8,14 @@ from langchain_community.embeddings import HuggingFaceBgeEmbeddings, HuggingFaceHubEmbeddings, OpenAIEmbeddings from langchain_milvus.vectorstores import Milvus -from comps import CustomLogger, EmbedDoc, OpeaComponent, SearchedDoc, ServiceType, TextDoc +from comps import CustomLogger, EmbedDoc, OpeaComponent, SearchedDoc, ServiceType, OpeaComponentRegistry from .config import COLLECTION_NAME, INDEX_PARAMS, LOCAL_EMBEDDING_MODEL, MILVUS_URI, TEI_EMBEDDING_ENDPOINT logger = CustomLogger("milvus_retrievers") logflag = os.getenv("LOGFLAG", False) - +@OpeaComponentRegistry.register("OPEA_RETRIEVER_MILVUS") class OpeaMilvusRetriever(OpeaComponent): """A specialized retriever component derived from OpeaComponent for milvus retriever services. @@ -28,6 +28,9 @@ def __init__(self, name: str, description: str, config: dict = None): self.embedder = self._initialize_embedder() self.client = self._initialize_client() + health_status = self.check_health() + if not health_status: + logger.error("OpeaMilvusRetriever health check failed.") def _initialize_embedder(self): if TEI_EMBEDDING_ENDPOINT: diff --git a/comps/retrievers/src/integrations/redis.py b/comps/retrievers/src/integrations/redis.py index 09d0a022f6..16fdd2c6b1 100644 --- a/comps/retrievers/src/integrations/redis.py +++ b/comps/retrievers/src/integrations/redis.py @@ -7,7 +7,7 @@ from langchain_community.vectorstores import Redis -from comps import CustomLogger, EmbedDoc, EmbedMultimodalDoc, OpeaComponent, SearchedDoc, ServiceType +from comps import CustomLogger, EmbedDoc, EmbedMultimodalDoc, OpeaComponent, SearchedDoc, ServiceType, OpeaComponentRegistry from comps.cores.proto.api_protocol import ChatCompletionRequest, EmbeddingResponse, RetrievalRequest, RetrievalResponse from .config import BRIDGE_TOWER_EMBEDDING, EMBED_MODEL, INDEX_NAME, REDIS_URL, TEI_EMBEDDING_ENDPOINT @@ -16,6 +16,7 @@ logflag = os.getenv("LOGFLAG", False) +@OpeaComponentRegistry.register("OPEA_RETRIEVER_REDIS") class OpeaRedisRetriever(OpeaComponent): """A specialized retriever component derived from OpeaComponent for redis retriever services. @@ -43,6 +44,9 @@ def __init__(self, name: str, description: str, config: dict = None): self.embeddings = HuggingFaceBgeEmbeddings(model_name=EMBED_MODEL) self.client = self._initialize_client() + health_status = self.check_health() + if not health_status: + logger.error("OpeaRedisRetriever health check failed.") def _initialize_client(self) -> Redis: """Initializes the redis client.""" diff --git a/comps/retrievers/src/opea_retrievers_microservice.py b/comps/retrievers/src/opea_retrievers_microservice.py index 9b0681cc2e..289c45f898 100644 --- a/comps/retrievers/src/opea_retrievers_microservice.py +++ b/comps/retrievers/src/opea_retrievers_microservice.py @@ -13,7 +13,7 @@ CustomLogger, EmbedDoc, EmbedMultimodalDoc, - OpeaComponentController, + OpeaComponentLoader, SearchedDoc, SearchedMultimodalDoc, ServiceType, @@ -32,31 +32,12 @@ logger = CustomLogger("opea_retrievers_microservice") logflag = os.getenv("LOGFLAG", False) -retriever_type = os.getenv("RETRIEVER_TYPE", False) -# Initialize Controller -controller = OpeaComponentController() - - -# Register components -try: - # Instantiate Retrievers components and register it to controller - if retriever_type == "redis": - redis_retriever = OpeaRedisRetriever( - name="OpeaRedisRetriever", - description="OPEA Redis Retriever Service", - ) - controller.register(redis_retriever) - elif retriever_type == "milvus": - milvus_retriever = OpeaMilvusRetriever( - name="OpeaMilvusRetriever", - description="OPEA Milvus Retriever Service", - ) - controller.register(milvus_retriever) - - # Discover and activate a healthy component - controller.discover_and_activate() -except Exception as e: - logger.error(f"Failed to initialize components: {e}") + +retriever_component_name = os.getenv("RETRIEVER_COMPONENT_NAME", "OPEA_RETRIEVER_REDIS") +# Initialize OpeaComponentLoader +loader = OpeaComponentLoader(retriever_component_name, + name=retriever_component_name, + description=f"OPEA RETRIEVER Component: {retriever_component_name}") @register_microservice( @@ -76,8 +57,8 @@ async def ingest_files( logger.info(f"[ retrieval ] input:{input}") try: - # Use the controller to invoke the active component - response = await controller.invoke(input) + # Use the loader to invoke the component + response = await loader.invoke(input) # return different response format retrieved_docs = [] diff --git a/comps/text2sql/src/integrations/opea.py b/comps/text2sql/src/integrations/opea.py index e69ab752df..3d915768fa 100644 --- a/comps/text2sql/src/integrations/opea.py +++ b/comps/text2sql/src/integrations/opea.py @@ -13,7 +13,7 @@ from sqlalchemy import create_engine from sqlalchemy.exc import SQLAlchemyError -from comps import CustomLogger, OpeaComponent, ServiceType +from comps import CustomLogger, OpeaComponent, ServiceType, OpeaComponentRegistry from comps.text2sql.src.integrations.sql_agent import CustomSQLDatabaseToolkit, custom_create_sql_agent logger = CustomLogger("comps-text2sql") @@ -69,6 +69,7 @@ class Input(BaseModel): conn_str: Optional[PostgresConnection] = None +@OpeaComponentRegistry.register("OPEA_TEXT2SQL") class OpeaText2SQL(OpeaComponent): """A specialized text to sql component derived from OpeaComponent for interacting with TGI services and Database. @@ -78,6 +79,9 @@ class OpeaText2SQL(OpeaComponent): def __init__(self, name: str, description: str, config: dict = None): super().__init__(name, ServiceType.TEXT2SQL.name.lower(), description, config) + health_status = self.check_health() + if not health_status: + logger.error("OpeaText2SQL health check failed.") async def check_health(self) -> bool: """Checks the health of the TGI service. diff --git a/comps/text2sql/src/opea_text2sql_microservice.py b/comps/text2sql/src/opea_text2sql_microservice.py index 3e4d4bb5ae..0a5202f16d 100644 --- a/comps/text2sql/src/opea_text2sql_microservice.py +++ b/comps/text2sql/src/opea_text2sql_microservice.py @@ -7,7 +7,7 @@ from fastapi.exceptions import HTTPException -from comps import CustomLogger, OpeaComponentController, opea_microservices, register_microservice +from comps import CustomLogger, OpeaComponentLoader, opea_microservices, register_microservice from comps.text2sql.src.integrations.opea import Input, OpeaText2SQL cur_path = pathlib.Path(__file__).parent.resolve() @@ -17,23 +17,11 @@ logger = CustomLogger("text2sql") logflag = os.getenv("LOGFLAG", False) -try: - # Initialize OpeaComponentController - controller = OpeaComponentController() - - # Register components - text2sql_agent = OpeaText2SQL( - name="Text2SQL", - description="Text2SQL Service", - ) - - # Register components with the controller - controller.register(text2sql_agent) - - # Discover and activate a healthy component - controller.discover_and_activate() -except Exception as e: - logger.error(f"Failed to initialize components: {e}") +text2sql_component_name = os.getenv("TEXT2SQL_COMPONENT_NAME", "OPEA_TEXT2SQL") +# Initialize OpeaComponentLoader +loader = OpeaComponentLoader(text2sql_component_name, + name=text2sql_component_name, + description=f"OPEA RERANK Component: {text2sql_component_name}") @register_microservice( @@ -55,7 +43,7 @@ async def execute_agent(input: Input): dict: A dictionary with a 'result' key containing the output of the executed SQL query. """ if input.conn_str.test_connection(): - response = await controller.invoke(input) + response = await loader.invoke(input) # response = "a" return {"result": response} else: diff --git a/comps/tts/src/integrations/opea_gptsovits.py b/comps/tts/src/integrations/opea_gptsovits.py index fffb97ba84..3937f92271 100644 --- a/comps/tts/src/integrations/opea_gptsovits.py +++ b/comps/tts/src/integrations/opea_gptsovits.py @@ -7,13 +7,15 @@ import requests from fastapi.responses import StreamingResponse -from comps import CustomLogger, OpeaComponent, ServiceType + +from comps import CustomLogger, OpeaComponent, ServiceType, OpeaComponentRegistry from comps.cores.proto.api_protocol import AudioSpeechRequest logger = CustomLogger("opea_gptsovits") logflag = os.getenv("LOGFLAG", False) +@OpeaComponentRegistry.register("OPEA_GPTSOVITS_TTS") class OpeaGptsovitsTts(OpeaComponent): """A specialized TTS (Text To Speech) component derived from OpeaComponent for GPTSoVITS TTS services. @@ -24,6 +26,9 @@ class OpeaGptsovitsTts(OpeaComponent): def __init__(self, name: str, description: str, config: dict = None): super().__init__(name, ServiceType.TTS.name.lower(), description, config) self.base_url = os.getenv("TTS_ENDPOINT", "http://localhost:9880") + health_status = self.check_health() + if not health_status: + logger.error("OpeaGptsovitsTts health check failed.") async def invoke( self, diff --git a/comps/tts/src/integrations/opea_speecht5.py b/comps/tts/src/integrations/opea_speecht5.py index 669d3ea6fa..dc5043e309 100644 --- a/comps/tts/src/integrations/opea_speecht5.py +++ b/comps/tts/src/integrations/opea_speecht5.py @@ -7,13 +7,14 @@ import requests from fastapi.responses import StreamingResponse -from comps import CustomLogger, OpeaComponent, ServiceType +from comps import CustomLogger, OpeaComponent, ServiceType, OpeaComponentRegistry from comps.cores.proto.api_protocol import AudioSpeechRequest logger = CustomLogger("opea_speecht5") logflag = os.getenv("LOGFLAG", False) +@OpeaComponentRegistry.register("OPEA_SPEECHT5_TTS") class OpeaSpeecht5Tts(OpeaComponent): """A specialized TTS (Text To Speech) component derived from OpeaComponent for SpeechT5 TTS services. @@ -24,6 +25,9 @@ class OpeaSpeecht5Tts(OpeaComponent): def __init__(self, name: str, description: str, config: dict = None): super().__init__(name, ServiceType.TTS.name.lower(), description, config) self.base_url = os.getenv("TTS_ENDPOINT", "http://localhost:7055") + health_status = self.check_health() + if not health_status: + logger.error("OpeaSpeecht5Tts health check failed.") def invoke( self, diff --git a/comps/tts/src/opea_tts_microservice.py b/comps/tts/src/opea_tts_microservice.py index 89771f4e33..e1f27d1b77 100644 --- a/comps/tts/src/opea_tts_microservice.py +++ b/comps/tts/src/opea_tts_microservice.py @@ -10,7 +10,7 @@ from comps import ( CustomLogger, - OpeaComponentController, + OpeaComponentLoader, ServiceType, opea_microservices, register_microservice, @@ -22,30 +22,11 @@ logger = CustomLogger("opea_tts_microservice") logflag = os.getenv("LOGFLAG", False) -# Initialize OpeaComponentController -controller = OpeaComponentController() - -# Register components -try: - # Instantiate TTS components - opea_speecht5 = OpeaSpeecht5Tts( - name="OpeaSpeecht5Tts", - description="OPEA SpeechT5 TTS Service", - ) - - opea_gptsovits = OpeaGptsovitsTts( - name="OpeaGptsovitsTts", - description="OPEA GPTSoVITS TTS Service", - ) - - # Register components with the controller - controller.register(opea_speecht5) - controller.register(opea_gptsovits) - - # Discover and activate a healthy component - controller.discover_and_activate() -except Exception as e: - logger.error(f"Failed to initialize components: {e}") +tts_component_name = os.getenv("TTS_COMPONENT_NAME", "OPEA_SPEECHT5_TTS") +# Initialize OpeaComponentLoader +loader = OpeaComponentLoader(tts_component_name, + name=tts_component_name, + description=f"OPEA TTS Component: {tts_component_name}") async def stream_forwarder(response): @@ -71,8 +52,8 @@ async def text_to_speech(request: AudioSpeechRequest) -> StreamingResponse: logger.info(f"Input received: {request}") try: - # Use the controller to invoke the active component - tts_response = controller.invoke(request) + # Use the loader to invoke the component + tts_response = loader.invoke(request) if logflag: logger.info(tts_response) statistics_dict["opea_service@tts"].append_latency(time.time() - start, None) diff --git a/tests/dataprep/test_dataprep_milvus.sh b/tests/dataprep/test_dataprep_milvus.sh index 5732e6a50f..33388593e3 100644 --- a/tests/dataprep/test_dataprep_milvus.sh +++ b/tests/dataprep/test_dataprep_milvus.sh @@ -39,7 +39,7 @@ function start_service() { MILVUS_HOST=${ip_address} dataprep_service_port=5022 HF_TOKEN=${HF_TOKEN} - docker run -d --name="test-comps-dataprep-milvus-server" -p ${dataprep_service_port}:5000 -e http_proxy=$http_proxy -e https_proxy=$https_proxy -e no_proxy=$no_proxy -e TEI_EMBEDDING_ENDPOINT=${TEI_EMBEDDING_ENDPOINT} -e MILVUS_HOST=${MILVUS_HOST} -e HUGGINGFACEHUB_API_TOKEN=${HF_TOKEN} -e LOGFLAG=true -e DATAPREP_TYPE="milvus" --ipc=host opea/dataprep-milvus:comps + docker run -d --name="test-comps-dataprep-milvus-server" -p ${dataprep_service_port}:5000 -e http_proxy=$http_proxy -e https_proxy=$https_proxy -e no_proxy=$no_proxy -e TEI_EMBEDDING_ENDPOINT=${TEI_EMBEDDING_ENDPOINT} -e MILVUS_HOST=${MILVUS_HOST} -e HUGGINGFACEHUB_API_TOKEN=${HF_TOKEN} -e LOGFLAG=true -e DATAPREP_COMPONENT_NAME="OPEA_DATAPREP_MILVUS" --ipc=host opea/dataprep-milvus:comps sleep 1m } diff --git a/tests/dataprep/test_dataprep_redis.sh b/tests/dataprep/test_dataprep_redis.sh index 13afc43c81..7e8af5b005 100644 --- a/tests/dataprep/test_dataprep_redis.sh +++ b/tests/dataprep/test_dataprep_redis.sh @@ -33,7 +33,7 @@ function start_service() { REDIS_URL="redis://${ip_address}:${REDIS_PORT}" export INDEX_NAME="rag_redis" export HF_TOKEN=${HF_TOKEN} - docker run -d --name="test-comps-dataprep-redis-langchain-server" -e http_proxy=$http_proxy -e https_proxy=$https_proxy -e REDIS_URL=$REDIS_URL -e REDIS_HOST=$ip_address -e REDIS_PORT=$REDIS_PORT -e TEI_EMBEDDING_ENDPOINT=${TEI_EMBEDDING_ENDPOINT} -e INDEX_NAME=$INDEX_NAME -e HUGGINGFACEHUB_API_TOKEN=${HF_TOKEN} -e LOGFLAG=true -e DATAPREP_TYPE="redis" -p ${dataprep_service_port}:5000 --ipc=host opea/dataprep-redis:comps + docker run -d --name="test-comps-dataprep-redis-langchain-server" -e http_proxy=$http_proxy -e https_proxy=$https_proxy -e REDIS_URL=$REDIS_URL -e REDIS_HOST=$ip_address -e REDIS_PORT=$REDIS_PORT -e TEI_EMBEDDING_ENDPOINT=${TEI_EMBEDDING_ENDPOINT} -e INDEX_NAME=$INDEX_NAME -e HUGGINGFACEHUB_API_TOKEN=${HF_TOKEN} -e LOGFLAG=true -e DATAPREP_COMPONENT_NAME="OPEA_DATAPREP_REDIS" -p ${dataprep_service_port}:5000 --ipc=host opea/dataprep-redis:comps sleep 1m } diff --git a/tests/retrievers/test_retrievers_milvus.sh b/tests/retrievers/test_retrievers_milvus.sh index 2fe6fc0c96..dae4243ea5 100644 --- a/tests/retrievers/test_retrievers_milvus.sh +++ b/tests/retrievers/test_retrievers_milvus.sh @@ -38,7 +38,7 @@ function start_service() { export HUGGINGFACEHUB_API_TOKEN=$HF_TOKEN retriever_port=5015 # unset http_proxy - docker run -d --name="test-comps-retriever-milvus-server" -p ${retriever_port}:7000 --ipc=host -e HUGGINGFACEHUB_API_TOKEN=${HUGGINGFACEHUB_API_TOKEN} -e TEI_EMBEDDING_ENDPOINT=$TEI_EMBEDDING_ENDPOINT -e http_proxy=$http_proxy -e https_proxy=$https_proxy -e no_proxy=$no_proxy -e MILVUS_HOST=$ip_address -e LOGFLAG=true -e RETRIEVER_TYPE="milvus" opea/retriever-milvus:comps + docker run -d --name="test-comps-retriever-milvus-server" -p ${retriever_port}:7000 --ipc=host -e HUGGINGFACEHUB_API_TOKEN=${HUGGINGFACEHUB_API_TOKEN} -e TEI_EMBEDDING_ENDPOINT=$TEI_EMBEDDING_ENDPOINT -e http_proxy=$http_proxy -e https_proxy=$https_proxy -e no_proxy=$no_proxy -e MILVUS_HOST=$ip_address -e LOGFLAG=true -e RETRIEVER_COMPONENT_NAME="OPEA_RETRIEVER_MILVUS" opea/retriever-milvus:comps sleep 1m } diff --git a/tests/tts/test_tts_opea_gptsovits.sh b/tests/tts/test_tts_opea_gptsovits.sh index 6399c29d31..bff8f1ccf3 100644 --- a/tests/tts/test_tts_opea_gptsovits.sh +++ b/tests/tts/test_tts_opea_gptsovits.sh @@ -32,7 +32,7 @@ function start_service() { unset http_proxy docker run -d --name="test-comps-tts-gpt-sovits" -e http_proxy=$http_proxy -e https_proxy=$https_proxy -p 9880:9880 --ipc=host opea/gpt-sovits:comps sleep 2m - docker run -d --name="test-comps-tts" -e TTS_ENDPOINT=http://$ip_address:9880 -e http_proxy=$http_proxy -e https_proxy=$https_proxy -p 5016:9088 --ipc=host opea/tts:comps + docker run -d --name="test-comps-tts" -e TTS_ENDPOINT=http://$ip_address:9880 -e http_proxy=$http_proxy -e https_proxy=$https_proxy -e TTS_COMPONENT_NAME="OPEA_GPTSOVITS_TTS" -p 5016:9088 --ipc=host opea/tts:comps sleep 15 } From c51a262d9758ef6c35b4c7914c168ecc965890dd Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Fri, 3 Jan 2025 09:04:32 +0000 Subject: [PATCH 07/15] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- comps/animation/src/integration/opea.py | 2 +- .../src/opea_animation_microservice.py | 9 +++--- comps/asr/src/integrations/opea_whisper.py | 3 +- comps/asr/src/opea_asr_microservice.py | 6 ++-- comps/cores/common/component.py | 30 +++++++++---------- comps/dataprep/src/integrations/milvus.py | 2 +- comps/dataprep/src/integrations/redis.py | 3 +- .../src/opea_dataprep_microservice.py | 12 ++++---- .../opea_multimodal_embedding_bridgetower.py | 12 ++++++-- .../src/integrations/opea_tei_embedding.py | 4 +-- .../integrations/predictionguard_embedding.py | 3 +- .../src/opea_embedding_microservice.py | 11 ++++--- .../opea_multimodal_embedding_microservice.py | 10 ++++--- .../integration/opea_image2image_native.py | 3 +- .../src/opea_image2image_microservice.py | 8 +++-- comps/image2video/src/integrations/opea.py | 3 +- .../src/opea_image2video_microservice.py | 8 +++-- .../src/text-generation/integrations/opea.py | 2 +- .../text-generation/opea_llm_microservice.py | 8 ++--- comps/reranks/src/integrations/opea_tei.py | 3 +- .../src/opea_reranking_microservice.py | 6 ++-- comps/retrievers/src/integrations/milvus.py | 3 +- comps/retrievers/src/integrations/redis.py | 10 ++++++- .../src/opea_retrievers_microservice.py | 8 +++-- comps/text2sql/src/integrations/opea.py | 2 +- .../src/opea_text2sql_microservice.py | 8 +++-- comps/tts/src/integrations/opea_gptsovits.py | 3 +- comps/tts/src/integrations/opea_speecht5.py | 2 +- comps/tts/src/opea_tts_microservice.py | 6 ++-- tests/cores/common/test_component.py | 11 +++---- 30 files changed, 116 insertions(+), 85 deletions(-) diff --git a/comps/animation/src/integration/opea.py b/comps/animation/src/integration/opea.py index c0dbf1845e..e90b351c45 100644 --- a/comps/animation/src/integration/opea.py +++ b/comps/animation/src/integration/opea.py @@ -5,7 +5,7 @@ import requests -from comps import CustomLogger, OpeaComponent, ServiceType, OpeaComponentRegistry +from comps import CustomLogger, OpeaComponent, OpeaComponentRegistry, ServiceType logger = CustomLogger("opea_animation") logflag = os.getenv("LOGFLAG", False) diff --git a/comps/animation/src/opea_animation_microservice.py b/comps/animation/src/opea_animation_microservice.py index 629c0b0367..ec40bfc115 100644 --- a/comps/animation/src/opea_animation_microservice.py +++ b/comps/animation/src/opea_animation_microservice.py @@ -24,12 +24,13 @@ statistics_dict, ) - animation_component_name = os.getenv("ANIMATION_COMPONENT_NAME", "OPEA_ANIMATION") # Initialize OpeaComponentLoader -loader = OpeaComponentLoader(animation_component_name, - name=animation_component_name, - description=f"OPEA ANIMATION Component: {animation_component_name}") +loader = OpeaComponentLoader( + animation_component_name, + name=animation_component_name, + description=f"OPEA ANIMATION Component: {animation_component_name}", +) # Register the microservice diff --git a/comps/asr/src/integrations/opea_whisper.py b/comps/asr/src/integrations/opea_whisper.py index 135f128252..72f688e888 100644 --- a/comps/asr/src/integrations/opea_whisper.py +++ b/comps/asr/src/integrations/opea_whisper.py @@ -8,12 +8,13 @@ import requests from fastapi import File, Form, UploadFile -from comps import CustomLogger, OpeaComponent, ServiceType, OpeaComponentRegistry +from comps import CustomLogger, OpeaComponent, OpeaComponentRegistry, ServiceType from comps.cores.proto.api_protocol import AudioTranscriptionResponse logger = CustomLogger("opea_whisper") logflag = os.getenv("LOGFLAG", False) + @OpeaComponentRegistry.register("OPEA_WHISPER_ASR") class OpeaWhisperAsr(OpeaComponent): """A specialized ASR (Automatic Speech Recognition) component derived from OpeaComponent for Whisper ASR services. diff --git a/comps/asr/src/opea_asr_microservice.py b/comps/asr/src/opea_asr_microservice.py index a3313d4ed7..3cc9475750 100644 --- a/comps/asr/src/opea_asr_microservice.py +++ b/comps/asr/src/opea_asr_microservice.py @@ -26,9 +26,9 @@ asr_component_name = os.getenv("ASR_COMPONENT_NAME", "OPEA_WHISPER_ASR") # Initialize OpeaComponentLoader -loader = OpeaComponentLoader(asr_component_name, - name=asr_component_name, - description=f"OPEA ASR Component: {asr_component_name}") +loader = OpeaComponentLoader( + asr_component_name, name=asr_component_name, description=f"OPEA ASR Component: {asr_component_name}" +) @register_microservice( diff --git a/comps/cores/common/component.py b/comps/cores/common/component.py index 4c74edac9c..a302fe5b22 100644 --- a/comps/cores/common/component.py +++ b/comps/cores/common/component.py @@ -85,9 +85,10 @@ def __repr__(self): """ return f"OpeaComponent(name={self.name}, type={self.type}, description={self.description})" + class OpeaComponentRegistry: - """ - Registry class to manage component instances. + """Registry class to manage component instances. + This registry allows storing, retrieving, and managing component instances by their names. """ @@ -95,23 +96,23 @@ class OpeaComponentRegistry: @classmethod def register(cls, name): - """ - Decorator to register a component class with a specified name. + """Decorator to register a component class with a specified name. :param name: The name to associate with the component class :return: Decorator function """ + def decorator(component_class): if name in cls._registry: raise ValueError(f"A component with the name '{name}' is already registered.") cls._registry[name] = component_class return component_class + return decorator @classmethod def get(cls, name): - """ - Retrieve a component class by its name. + """Retrieve a component class by its name. :param name: The name of the component class to retrieve :return: The component class @@ -122,8 +123,7 @@ def get(cls, name): @classmethod def unregister(cls, name): - """ - Remove a component class from the registry by its name. + """Remove a component class from the registry by its name. :param name: The name of the component class to remove """ @@ -132,32 +132,30 @@ def unregister(cls, name): class OpeaComponentLoader: - """ - Loader class to dynamically load and invoke components. + """Loader class to dynamically load and invoke components. + This loader retrieves components from the registry and invokes their functionality. """ def __init__(self, component_name, **kwargs): - """ - Initialize the loader with a component retrieved from the registry and instantiate it. + """Initialize the loader with a component retrieved from the registry and instantiate it. :param component_name: The name of the component to load :param kwargs: Additional parameters for the component's initialization """ # Retrieve the component class from the registry component_class = OpeaComponentRegistry.get(component_name) - + # Instantiate the component with the given arguments self.component = component_class(**kwargs) async def invoke(self, *args, **kwargs): - """ - Invoke the loaded component's execute method. + """Invoke the loaded component's execute method. :param args: Positional arguments for the invoke method :param kwargs: Keyword arguments for the invoke method :return: The result of the component's invoke method """ - if not hasattr(self.component, 'invoke'): + if not hasattr(self.component, "invoke"): raise AttributeError(f"The component '{self.component}' does not have an 'invoke' method.") return await self.component.invoke(*args, **kwargs) diff --git a/comps/dataprep/src/integrations/milvus.py b/comps/dataprep/src/integrations/milvus.py index 058a97125f..2eb517e40a 100644 --- a/comps/dataprep/src/integrations/milvus.py +++ b/comps/dataprep/src/integrations/milvus.py @@ -15,7 +15,7 @@ from langchain_milvus.vectorstores import Milvus from langchain_text_splitters import HTMLHeaderTextSplitter -from comps import CustomLogger, DocPath, OpeaComponent, ServiceType, OpeaComponentRegistry +from comps import CustomLogger, DocPath, OpeaComponent, OpeaComponentRegistry, ServiceType from comps.dataprep.src.utils import ( create_upload_folder, document_loader, diff --git a/comps/dataprep/src/integrations/redis.py b/comps/dataprep/src/integrations/redis.py index 241dd1a3bb..1d084d1b7a 100644 --- a/comps/dataprep/src/integrations/redis.py +++ b/comps/dataprep/src/integrations/redis.py @@ -18,7 +18,7 @@ from redis.commands.search.field import TextField from redis.commands.search.indexDefinition import IndexDefinition, IndexType -from comps import CustomLogger, DocPath, OpeaComponent, ServiceType, OpeaComponentRegistry +from comps import CustomLogger, DocPath, OpeaComponent, OpeaComponentRegistry, ServiceType from comps.dataprep.src.utils import ( create_upload_folder, document_loader, @@ -214,6 +214,7 @@ def ingest_data_to_redis(doc_path: DocPath): file_name = doc_path.path.split("/")[-1] return ingest_chunks_to_redis(file_name, chunks) + @OpeaComponentRegistry.register("OPEA_DATAPREP_REDIS") class OpeaRedisDataprep(OpeaComponent): """A specialized dataprep component derived from OpeaComponent for redis dataprep services. diff --git a/comps/dataprep/src/opea_dataprep_microservice.py b/comps/dataprep/src/opea_dataprep_microservice.py index 7f6aebd8d8..e3e0cf626b 100644 --- a/comps/dataprep/src/opea_dataprep_microservice.py +++ b/comps/dataprep/src/opea_dataprep_microservice.py @@ -27,9 +27,11 @@ dataprep_component_name = os.getenv("DATAPREP_COMPONENT_NAME", "OPEA_DATAPREP_REDIS") # Initialize OpeaComponentLoader -loader = OpeaDataprepLoader(dataprep_component_name, - name=dataprep_component_name, - description=f"OPEA DATAPREP Component: {dataprep_component_name}") +loader = OpeaDataprepLoader( + dataprep_component_name, + name=dataprep_component_name, + description=f"OPEA DATAPREP Component: {dataprep_component_name}", +) @register_microservice( @@ -56,9 +58,7 @@ async def ingest_files( try: # Use the loader to invoke the component - response = await loader.ingest_files( - files, link_list, chunk_size, chunk_overlap, process_table, table_strategy - ) + response = await loader.ingest_files(files, link_list, chunk_size, chunk_overlap, process_table, table_strategy) # Log the result if logging is enabled if logflag: logger.info(f"[ ingest ] Output generated: {response}") diff --git a/comps/embeddings/src/integrations/opea_multimodal_embedding_bridgetower.py b/comps/embeddings/src/integrations/opea_multimodal_embedding_bridgetower.py index 87a7dc3523..c9152136ca 100644 --- a/comps/embeddings/src/integrations/opea_multimodal_embedding_bridgetower.py +++ b/comps/embeddings/src/integrations/opea_multimodal_embedding_bridgetower.py @@ -7,8 +7,16 @@ import requests -from comps import CustomLogger, EmbedMultimodalDoc, MultimodalDoc, OpeaComponent, ServiceType, TextDoc, TextImageDoc -from comps import OpeaComponentRegistry +from comps import ( + CustomLogger, + EmbedMultimodalDoc, + MultimodalDoc, + OpeaComponent, + OpeaComponentRegistry, + ServiceType, + TextDoc, + TextImageDoc, +) logger = CustomLogger("opea_multimodal_embedding_bridgetower") logflag = os.getenv("LOGFLAG", False) diff --git a/comps/embeddings/src/integrations/opea_tei_embedding.py b/comps/embeddings/src/integrations/opea_tei_embedding.py index af58fae4a5..dd7dd602e1 100644 --- a/comps/embeddings/src/integrations/opea_tei_embedding.py +++ b/comps/embeddings/src/integrations/opea_tei_embedding.py @@ -8,10 +8,9 @@ import requests from huggingface_hub import AsyncInferenceClient -from comps import CustomLogger, OpeaComponent, ServiceType +from comps import CustomLogger, OpeaComponent, OpeaComponentRegistry, ServiceType from comps.cores.mega.utils import get_access_token from comps.cores.proto.api_protocol import EmbeddingRequest, EmbeddingResponse -from comps import OpeaComponentRegistry logger = CustomLogger("opea_tei_embedding") logflag = os.getenv("LOGFLAG", False) @@ -38,7 +37,6 @@ def __init__(self, name: str, description: str, config: dict = None): if not health_status: logger.error("OpeaTEIEmbedding health check failed.") - def _initialize_client(self) -> AsyncInferenceClient: """Initializes the AsyncInferenceClient.""" access_token = ( diff --git a/comps/embeddings/src/integrations/predictionguard_embedding.py b/comps/embeddings/src/integrations/predictionguard_embedding.py index 5c294aef28..5a7f4dec57 100644 --- a/comps/embeddings/src/integrations/predictionguard_embedding.py +++ b/comps/embeddings/src/integrations/predictionguard_embedding.py @@ -6,9 +6,8 @@ from predictionguard import PredictionGuard -from comps import CustomLogger, OpeaComponent, ServiceType +from comps import CustomLogger, OpeaComponent, OpeaComponentRegistry, ServiceType from comps.cores.proto.api_protocol import EmbeddingRequest, EmbeddingResponse, EmbeddingResponseData -from comps import OpeaComponentRegistry logger = CustomLogger("predictionguard_embedding") logflag = os.getenv("LOGFLAG", False) diff --git a/comps/embeddings/src/opea_embedding_microservice.py b/comps/embeddings/src/opea_embedding_microservice.py index e1797414d0..577080019e 100644 --- a/comps/embeddings/src/opea_embedding_microservice.py +++ b/comps/embeddings/src/opea_embedding_microservice.py @@ -9,12 +9,12 @@ from comps import ( CustomLogger, + OpeaComponentLoader, ServiceType, opea_microservices, register_microservice, register_statistics, statistics_dict, - OpeaComponentLoader ) from comps.cores.proto.api_protocol import EmbeddingRequest, EmbeddingResponse @@ -23,9 +23,12 @@ embedding_component_name = os.getenv("EMBEDDING_COMPONENT_NAME", "OPEA_TEI_EMBEDDING") # Initialize OpeaComponentLoader -loader = OpeaComponentLoader(embedding_component_name, - name=embedding_component_name, - description=f"OPEA Embedding Component: {embedding_component_name}") +loader = OpeaComponentLoader( + embedding_component_name, + name=embedding_component_name, + description=f"OPEA Embedding Component: {embedding_component_name}", +) + @register_microservice( name="opea_service@embedding", diff --git a/comps/embeddings/src/opea_multimodal_embedding_microservice.py b/comps/embeddings/src/opea_multimodal_embedding_microservice.py index 811d4a3b55..a52f1b048c 100644 --- a/comps/embeddings/src/opea_multimodal_embedding_microservice.py +++ b/comps/embeddings/src/opea_multimodal_embedding_microservice.py @@ -10,12 +10,12 @@ CustomLogger, EmbedMultimodalDoc, MultimodalDoc, + OpeaComponentLoader, ServiceType, opea_microservices, register_microservice, register_statistics, statistics_dict, - OpeaComponentLoader ) logger = CustomLogger("opea_multimodal_embedding_microservice") @@ -23,9 +23,11 @@ embedding_component_name = os.getenv("EMBEDDING_COMPONENT_NAME", "OPEA_MULTIMODAL_EMBEDDING_BRIDGETOWER") # Initialize OpeaComponentLoader -loader = OpeaComponentLoader(embedding_component_name, - name=embedding_component_name, - description=f"OPEA Embedding Component: {embedding_component_name}") +loader = OpeaComponentLoader( + embedding_component_name, + name=embedding_component_name, + description=f"OPEA Embedding Component: {embedding_component_name}", +) port = int(os.getenv("MM_EMBEDDING_PORT_MICROSERVICE", 6000)) diff --git a/comps/image2image/src/integration/opea_image2image_native.py b/comps/image2image/src/integration/opea_image2image_native.py index e0e467b700..b9125b5e23 100644 --- a/comps/image2image/src/integration/opea_image2image_native.py +++ b/comps/image2image/src/integration/opea_image2image_native.py @@ -4,7 +4,7 @@ import os import threading -from comps import CustomLogger, OpeaComponent, SDImg2ImgInputs, ServiceType, OpeaComponentRegistry +from comps import CustomLogger, OpeaComponent, OpeaComponentRegistry, SDImg2ImgInputs, ServiceType logger = CustomLogger("opea_imagetoimage") logflag = os.getenv("LOGFLAG", False) @@ -64,6 +64,7 @@ def initialize( logger.info("Stable Diffusion model initialized.") initialized = True + @OpeaComponentRegistry.register("OPEA_IMAGE2IMAGE") class OpeaImageToImage(OpeaComponent): """A specialized ImageToImage component derived from OpeaComponent for Stable Diffusion model . diff --git a/comps/image2image/src/opea_image2image_microservice.py b/comps/image2image/src/opea_image2image_microservice.py index be929cab61..83c09e5d9b 100644 --- a/comps/image2image/src/opea_image2image_microservice.py +++ b/comps/image2image/src/opea_image2image_microservice.py @@ -26,9 +26,11 @@ image2image_component_name = os.getenv("IMAGE2IMAGE_COMPONENT_NAME", "OPEA_IMAGE2IMAGE") # Initialize OpeaComponentLoader -loader = OpeaComponentLoader(image2image_component_name, - name=image2image_component_name, - description=f"OPEA IMAGE2IMAGE Component: {image2image_component_name}") +loader = OpeaComponentLoader( + image2image_component_name, + name=image2image_component_name, + description=f"OPEA IMAGE2IMAGE Component: {image2image_component_name}", +) @register_microservice( diff --git a/comps/image2video/src/integrations/opea.py b/comps/image2video/src/integrations/opea.py index 3460b55232..5cb5a5a90c 100644 --- a/comps/image2video/src/integrations/opea.py +++ b/comps/image2video/src/integrations/opea.py @@ -7,10 +7,11 @@ from diffusers import StableVideoDiffusionPipeline from diffusers.utils import export_to_video, load_image -from comps import CustomLogger, ImagesPath, OpeaComponent, ServiceType, VideoPath, OpeaComponentRegistry +from comps import CustomLogger, ImagesPath, OpeaComponent, OpeaComponentRegistry, ServiceType, VideoPath logger = CustomLogger("opea") + @OpeaComponentRegistry.register("OPEA_IMAGE2VIDEO") class OpeaImage2video(OpeaComponent): """A specialized image2video component derived from OpeaComponent for image2video services.""" diff --git a/comps/image2video/src/opea_image2video_microservice.py b/comps/image2video/src/opea_image2video_microservice.py index f30ab12c7f..cbbea72778 100644 --- a/comps/image2video/src/opea_image2video_microservice.py +++ b/comps/image2video/src/opea_image2video_microservice.py @@ -23,9 +23,11 @@ image2video_component_name = os.getenv("IMAGE2VIDEO_COMPONENT_NAME", "OPEA_IMAGE2VIDEO") # Initialize OpeaComponentLoader -loader = OpeaComponentLoader(image2video_component_name, - name=image2video_component_name, - description=f"OPEA RERANK Component: {image2video_component_name}") +loader = OpeaComponentLoader( + image2video_component_name, + name=image2video_component_name, + description=f"OPEA RERANK Component: {image2video_component_name}", +) @register_microservice( diff --git a/comps/llms/src/text-generation/integrations/opea.py b/comps/llms/src/text-generation/integrations/opea.py index 3eed727cd6..249184c3c4 100644 --- a/comps/llms/src/text-generation/integrations/opea.py +++ b/comps/llms/src/text-generation/integrations/opea.py @@ -9,7 +9,7 @@ from langchain_core.prompts import PromptTemplate from openai import AsyncOpenAI -from comps import CustomLogger, LLMParamsDoc, OpeaComponent, SearchedDoc, ServiceType, OpeaComponentRegistry +from comps import CustomLogger, LLMParamsDoc, OpeaComponent, OpeaComponentRegistry, SearchedDoc, ServiceType from comps.cores.mega.utils import ConfigError, get_access_token, load_model_configs from comps.cores.proto.api_protocol import ChatCompletionRequest diff --git a/comps/llms/src/text-generation/opea_llm_microservice.py b/comps/llms/src/text-generation/opea_llm_microservice.py index ada39f284e..513d8d5201 100644 --- a/comps/llms/src/text-generation/opea_llm_microservice.py +++ b/comps/llms/src/text-generation/opea_llm_microservice.py @@ -10,13 +10,13 @@ from comps import ( CustomLogger, LLMParamsDoc, + OpeaComponentLoader, SearchedDoc, ServiceType, opea_microservices, register_microservice, register_statistics, statistics_dict, - OpeaComponentLoader ) from comps.cores.proto.api_protocol import ChatCompletionRequest @@ -26,9 +26,9 @@ llm_component_name = os.getenv("LLM_COMPONENT_NAME", "OPEA_LLM") # Initialize OpeaComponentLoader -loader = OpeaComponentLoader(llm_component_name, - name=llm_component_name, - description=f"OPEA LLM Component: {llm_component_name}") +loader = OpeaComponentLoader( + llm_component_name, name=llm_component_name, description=f"OPEA LLM Component: {llm_component_name}" +) @register_microservice( diff --git a/comps/reranks/src/integrations/opea_tei.py b/comps/reranks/src/integrations/opea_tei.py index 2fa48333cc..5f2cb8a4c1 100644 --- a/comps/reranks/src/integrations/opea_tei.py +++ b/comps/reranks/src/integrations/opea_tei.py @@ -8,7 +8,7 @@ import requests from huggingface_hub import AsyncInferenceClient -from comps import CustomLogger, LLMParamsDoc, SearchedDoc, ServiceType, OpeaComponentRegistry +from comps import CustomLogger, LLMParamsDoc, OpeaComponentRegistry, SearchedDoc, ServiceType from comps.cores.common.component import OpeaComponent from comps.cores.mega.utils import get_access_token from comps.cores.proto.api_protocol import ( @@ -26,6 +26,7 @@ CLIENTID = os.getenv("CLIENTID") CLIENT_SECRET = os.getenv("CLIENT_SECRET") + @OpeaComponentRegistry.register("OPEA_RERANK_TEI") class OPEATEIReranking(OpeaComponent): """A specialized reranking component derived from OpeaComponent for TEI reranking services. diff --git a/comps/reranks/src/opea_reranking_microservice.py b/comps/reranks/src/opea_reranking_microservice.py index 6e46fd060b..55de837b0f 100644 --- a/comps/reranks/src/opea_reranking_microservice.py +++ b/comps/reranks/src/opea_reranking_microservice.py @@ -24,9 +24,9 @@ rerank_component_name = os.getenv("RERANK_COMPONENT_NAME", "OPEA_RERANK_TEI") # Initialize OpeaComponentLoader -loader = OpeaComponentLoader(rerank_component_name, - name=rerank_component_name, - description=f"OPEA RERANK Component: {rerank_component_name}") +loader = OpeaComponentLoader( + rerank_component_name, name=rerank_component_name, description=f"OPEA RERANK Component: {rerank_component_name}" +) @register_microservice( diff --git a/comps/retrievers/src/integrations/milvus.py b/comps/retrievers/src/integrations/milvus.py index 8095700ba3..c52d0a6b3c 100644 --- a/comps/retrievers/src/integrations/milvus.py +++ b/comps/retrievers/src/integrations/milvus.py @@ -8,13 +8,14 @@ from langchain_community.embeddings import HuggingFaceBgeEmbeddings, HuggingFaceHubEmbeddings, OpenAIEmbeddings from langchain_milvus.vectorstores import Milvus -from comps import CustomLogger, EmbedDoc, OpeaComponent, SearchedDoc, ServiceType, OpeaComponentRegistry +from comps import CustomLogger, EmbedDoc, OpeaComponent, OpeaComponentRegistry, SearchedDoc, ServiceType from .config import COLLECTION_NAME, INDEX_PARAMS, LOCAL_EMBEDDING_MODEL, MILVUS_URI, TEI_EMBEDDING_ENDPOINT logger = CustomLogger("milvus_retrievers") logflag = os.getenv("LOGFLAG", False) + @OpeaComponentRegistry.register("OPEA_RETRIEVER_MILVUS") class OpeaMilvusRetriever(OpeaComponent): """A specialized retriever component derived from OpeaComponent for milvus retriever services. diff --git a/comps/retrievers/src/integrations/redis.py b/comps/retrievers/src/integrations/redis.py index 16fdd2c6b1..b8b38082f5 100644 --- a/comps/retrievers/src/integrations/redis.py +++ b/comps/retrievers/src/integrations/redis.py @@ -7,7 +7,15 @@ from langchain_community.vectorstores import Redis -from comps import CustomLogger, EmbedDoc, EmbedMultimodalDoc, OpeaComponent, SearchedDoc, ServiceType, OpeaComponentRegistry +from comps import ( + CustomLogger, + EmbedDoc, + EmbedMultimodalDoc, + OpeaComponent, + OpeaComponentRegistry, + SearchedDoc, + ServiceType, +) from comps.cores.proto.api_protocol import ChatCompletionRequest, EmbeddingResponse, RetrievalRequest, RetrievalResponse from .config import BRIDGE_TOWER_EMBEDDING, EMBED_MODEL, INDEX_NAME, REDIS_URL, TEI_EMBEDDING_ENDPOINT diff --git a/comps/retrievers/src/opea_retrievers_microservice.py b/comps/retrievers/src/opea_retrievers_microservice.py index 289c45f898..067199de15 100644 --- a/comps/retrievers/src/opea_retrievers_microservice.py +++ b/comps/retrievers/src/opea_retrievers_microservice.py @@ -35,9 +35,11 @@ retriever_component_name = os.getenv("RETRIEVER_COMPONENT_NAME", "OPEA_RETRIEVER_REDIS") # Initialize OpeaComponentLoader -loader = OpeaComponentLoader(retriever_component_name, - name=retriever_component_name, - description=f"OPEA RETRIEVER Component: {retriever_component_name}") +loader = OpeaComponentLoader( + retriever_component_name, + name=retriever_component_name, + description=f"OPEA RETRIEVER Component: {retriever_component_name}", +) @register_microservice( diff --git a/comps/text2sql/src/integrations/opea.py b/comps/text2sql/src/integrations/opea.py index 3d915768fa..71ac553c8d 100644 --- a/comps/text2sql/src/integrations/opea.py +++ b/comps/text2sql/src/integrations/opea.py @@ -13,7 +13,7 @@ from sqlalchemy import create_engine from sqlalchemy.exc import SQLAlchemyError -from comps import CustomLogger, OpeaComponent, ServiceType, OpeaComponentRegistry +from comps import CustomLogger, OpeaComponent, OpeaComponentRegistry, ServiceType from comps.text2sql.src.integrations.sql_agent import CustomSQLDatabaseToolkit, custom_create_sql_agent logger = CustomLogger("comps-text2sql") diff --git a/comps/text2sql/src/opea_text2sql_microservice.py b/comps/text2sql/src/opea_text2sql_microservice.py index 0a5202f16d..63abd8edf5 100644 --- a/comps/text2sql/src/opea_text2sql_microservice.py +++ b/comps/text2sql/src/opea_text2sql_microservice.py @@ -19,9 +19,11 @@ text2sql_component_name = os.getenv("TEXT2SQL_COMPONENT_NAME", "OPEA_TEXT2SQL") # Initialize OpeaComponentLoader -loader = OpeaComponentLoader(text2sql_component_name, - name=text2sql_component_name, - description=f"OPEA RERANK Component: {text2sql_component_name}") +loader = OpeaComponentLoader( + text2sql_component_name, + name=text2sql_component_name, + description=f"OPEA RERANK Component: {text2sql_component_name}", +) @register_microservice( diff --git a/comps/tts/src/integrations/opea_gptsovits.py b/comps/tts/src/integrations/opea_gptsovits.py index 3937f92271..d8d0579237 100644 --- a/comps/tts/src/integrations/opea_gptsovits.py +++ b/comps/tts/src/integrations/opea_gptsovits.py @@ -7,8 +7,7 @@ import requests from fastapi.responses import StreamingResponse - -from comps import CustomLogger, OpeaComponent, ServiceType, OpeaComponentRegistry +from comps import CustomLogger, OpeaComponent, OpeaComponentRegistry, ServiceType from comps.cores.proto.api_protocol import AudioSpeechRequest logger = CustomLogger("opea_gptsovits") diff --git a/comps/tts/src/integrations/opea_speecht5.py b/comps/tts/src/integrations/opea_speecht5.py index dc5043e309..d2fce46c09 100644 --- a/comps/tts/src/integrations/opea_speecht5.py +++ b/comps/tts/src/integrations/opea_speecht5.py @@ -7,7 +7,7 @@ import requests from fastapi.responses import StreamingResponse -from comps import CustomLogger, OpeaComponent, ServiceType, OpeaComponentRegistry +from comps import CustomLogger, OpeaComponent, OpeaComponentRegistry, ServiceType from comps.cores.proto.api_protocol import AudioSpeechRequest logger = CustomLogger("opea_speecht5") diff --git a/comps/tts/src/opea_tts_microservice.py b/comps/tts/src/opea_tts_microservice.py index e1f27d1b77..b446d8b663 100644 --- a/comps/tts/src/opea_tts_microservice.py +++ b/comps/tts/src/opea_tts_microservice.py @@ -24,9 +24,9 @@ tts_component_name = os.getenv("TTS_COMPONENT_NAME", "OPEA_SPEECHT5_TTS") # Initialize OpeaComponentLoader -loader = OpeaComponentLoader(tts_component_name, - name=tts_component_name, - description=f"OPEA TTS Component: {tts_component_name}") +loader = OpeaComponentLoader( + tts_component_name, name=tts_component_name, description=f"OPEA TTS Component: {tts_component_name}" +) async def stream_forwarder(response): diff --git a/tests/cores/common/test_component.py b/tests/cores/common/test_component.py index e53b49f250..4028ff64b4 100644 --- a/tests/cores/common/test_component.py +++ b/tests/cores/common/test_component.py @@ -3,14 +3,15 @@ import asyncio import unittest -from comps import OpeaComponent, OpeaComponentRegistry, OpeaComponentLoader + +from comps import OpeaComponent, OpeaComponentLoader, OpeaComponentRegistry class TestOpeaComponent(unittest.TestCase): class MockOpeaComponent(OpeaComponent): def __init__(self, name, type, description, config=None): super().__init__(name, type, description, config) - + def check_health(self) -> bool: return True @@ -96,7 +97,9 @@ async def invoke(self, *args, **kwargs): OpeaComponentRegistry.register("MockComponent")(MockComponent) # Create loader for the component - loader = OpeaComponentLoader("MockComponent", name="MockComponent", type="embedding", description="Test component") + loader = OpeaComponentLoader( + "MockComponent", name="MockComponent", type="embedding", description="Test component" + ) # Invoke the component result = asyncio.run(loader.invoke("arg1", key="value")) @@ -112,5 +115,3 @@ def test_invoke_unregistered_component(self): if __name__ == "__main__": unittest.main() - - From a4f3a05bdefc382977f58b78ac3137a70b11de38 Mon Sep 17 00:00:00 2001 From: lvliang-intel Date: Fri, 3 Jan 2025 17:59:31 +0800 Subject: [PATCH 08/15] fix dataprepissue Signed-off-by: lvliang-intel --- comps/dataprep/src/opea_dataprep_loader.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/comps/dataprep/src/opea_dataprep_loader.py b/comps/dataprep/src/opea_dataprep_loader.py index 71fe6cab80..2e18e4456d 100644 --- a/comps/dataprep/src/opea_dataprep_loader.py +++ b/comps/dataprep/src/opea_dataprep_loader.py @@ -11,8 +11,8 @@ class OpeaDataprepLoader(OpeaComponentLoader): - def __init__(self): - super().__init__() + def __init__(self, component_name, **kwargs): + super().__init__(component_name=component_name, **kwargs) def invoke(self, *args, **kwargs): pass From d443faaea135d296a90b911ca2196b905856f36a Mon Sep 17 00:00:00 2001 From: lvliang-intel Date: Fri, 3 Jan 2025 18:01:41 +0800 Subject: [PATCH 09/15] fix tts issue Signed-off-by: lvliang-intel --- comps/tts/src/opea_tts_microservice.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/comps/tts/src/opea_tts_microservice.py b/comps/tts/src/opea_tts_microservice.py index b446d8b663..eddff0104c 100644 --- a/comps/tts/src/opea_tts_microservice.py +++ b/comps/tts/src/opea_tts_microservice.py @@ -53,7 +53,7 @@ async def text_to_speech(request: AudioSpeechRequest) -> StreamingResponse: try: # Use the loader to invoke the component - tts_response = loader.invoke(request) + tts_response = await loader.invoke(request) if logflag: logger.info(tts_response) statistics_dict["opea_service@tts"].append_latency(time.time() - start, None) From dd2e816d8dd71de6e71fad134957c24466701191 Mon Sep 17 00:00:00 2001 From: lvliang-intel Date: Fri, 3 Jan 2025 22:32:56 +0800 Subject: [PATCH 10/15] fix ci issues Signed-off-by: lvliang-intel --- comps/dataprep/src/opea_dataprep_loader.py | 6 ++--- .../src/opea_image2video_microservice.py | 24 ++++++++++++------- comps/tts/src/integrations/opea_gptsovits.py | 7 +++--- comps/tts/src/integrations/opea_speecht5.py | 9 +++---- 4 files changed, 27 insertions(+), 19 deletions(-) diff --git a/comps/dataprep/src/opea_dataprep_loader.py b/comps/dataprep/src/opea_dataprep_loader.py index 2e18e4456d..cd0ffb5aba 100644 --- a/comps/dataprep/src/opea_dataprep_loader.py +++ b/comps/dataprep/src/opea_dataprep_loader.py @@ -20,14 +20,14 @@ def invoke(self, *args, **kwargs): async def ingest_files(self, *args, **kwargs): if logflag: logger.info("[ dataprep loader ] ingest files") - return await self.active_component.ingest_files(*args, **kwargs) + return await self.component.ingest_files(*args, **kwargs) async def get_files(self, *args, **kwargs): if logflag: logger.info("[ dataprep loader ] get files") - return await self.active_component.get_files(*args, **kwargs) + return await self.component.get_files(*args, **kwargs) async def delete_files(self, *args, **kwargs): if logflag: logger.info("[ dataprep loader ] delete files") - return await self.active_component.delete_files(*args, **kwargs) + return await self.component.delete_files(*args, **kwargs) diff --git a/comps/image2video/src/opea_image2video_microservice.py b/comps/image2video/src/opea_image2video_microservice.py index cbbea72778..d998aa95e9 100644 --- a/comps/image2video/src/opea_image2video_microservice.py +++ b/comps/image2video/src/opea_image2video_microservice.py @@ -21,14 +21,7 @@ logger = CustomLogger("opea_image2video_microservice") -image2video_component_name = os.getenv("IMAGE2VIDEO_COMPONENT_NAME", "OPEA_IMAGE2VIDEO") -# Initialize OpeaComponentLoader -loader = OpeaComponentLoader( - image2video_component_name, - name=image2video_component_name, - description=f"OPEA RERANK Component: {image2video_component_name}", -) - +component_loader = None @register_microservice( name="opea_service@image2video", @@ -44,7 +37,7 @@ async def image2video(input: ImagesPath): start = time.time() try: # Use the loader to invoke the component - results = await loader.invoke(input) + results = await component_loader.invoke(input) statistics_dict["opea_service@image2video"].append_latency(time.time() - start, None) return results except Exception as e: @@ -62,6 +55,19 @@ async def image2video(input: ImagesPath): parser.add_argument("--seed", type=int, default=42) args = parser.parse_args() + image2video_component_name = os.getenv("IMAGE2VIDEO_COMPONENT_NAME", "OPEA_IMAGE2VIDEO") + # Register components + try: + # Initialize OpeaComponentLoader + component_loader = OpeaComponentLoader( + image2video_component_name, + name=image2video_component_name, + description=f"OPEA IMAGE2VIDEO Component: {image2video_component_name}", + config=args.__dict__ + ) + except Exception as e: + logger.error(f"Failed to initialize components: {e}") + exit(1) logger.info("Image2video server started.") opea_microservices["opea_service@image2video"].start() diff --git a/comps/tts/src/integrations/opea_gptsovits.py b/comps/tts/src/integrations/opea_gptsovits.py index d8d0579237..e41a3a30f8 100644 --- a/comps/tts/src/integrations/opea_gptsovits.py +++ b/comps/tts/src/integrations/opea_gptsovits.py @@ -4,7 +4,7 @@ import os import time -import requests +import requests, httpx from fastapi.responses import StreamingResponse from comps import CustomLogger, OpeaComponent, OpeaComponentRegistry, ServiceType @@ -32,13 +32,14 @@ def __init__(self, name: str, description: str, config: dict = None): async def invoke( self, request: AudioSpeechRequest, - ) -> requests.models.Response: + ) -> httpx.Response: """Involve the TTS service to generate speech for the provided input.""" # see https://github.com/Spycsh/GPT-SoVITS/blob/openai_compat/api.py#L948 for usage # make sure you change the refer_wav_path locally request.voice = None - response = requests.post(f"{self.base_url}/v1/audio/speech", data=request.json()) + async with httpx.AsyncClient() as client: + response = await client.post(f"{self.base_url}/v1/audio/speech", json=request.dict()) return response def check_health(self) -> bool: diff --git a/comps/tts/src/integrations/opea_speecht5.py b/comps/tts/src/integrations/opea_speecht5.py index d2fce46c09..e8a42352f1 100644 --- a/comps/tts/src/integrations/opea_speecht5.py +++ b/comps/tts/src/integrations/opea_speecht5.py @@ -4,7 +4,7 @@ import os import time -import requests +import requests, httpx from fastapi.responses import StreamingResponse from comps import CustomLogger, OpeaComponent, OpeaComponentRegistry, ServiceType @@ -29,10 +29,10 @@ def __init__(self, name: str, description: str, config: dict = None): if not health_status: logger.error("OpeaSpeecht5Tts health check failed.") - def invoke( + async def invoke( self, request: AudioSpeechRequest, - ) -> requests.models.Response: + ) -> httpx.Response: """Involve the TTS service to generate speech for the provided input.""" # validate the request parameters if request.model not in ["microsoft/speecht5_tts"]: @@ -40,7 +40,8 @@ def invoke( if request.voice not in ["default", "male"] or request.speed != 1.0: logger.warning("Currently parameter 'speed' can only be 1.0 and 'voice' can only be default or male!") - response = requests.post(f"{self.base_url}/v1/audio/speech", data=request.json()) + async with httpx.AsyncClient() as client: + response = await client.post(f"{self.base_url}/v1/audio/speech", json=request.dict()) return response def check_health(self) -> bool: From 796f82c816914c2ae02d77baac663253e8775dd7 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Fri, 3 Jan 2025 14:36:45 +0000 Subject: [PATCH 11/15] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- comps/image2video/src/opea_image2video_microservice.py | 3 ++- comps/tts/src/integrations/opea_gptsovits.py | 3 ++- comps/tts/src/integrations/opea_speecht5.py | 3 ++- 3 files changed, 6 insertions(+), 3 deletions(-) diff --git a/comps/image2video/src/opea_image2video_microservice.py b/comps/image2video/src/opea_image2video_microservice.py index d998aa95e9..f17be2a2c9 100644 --- a/comps/image2video/src/opea_image2video_microservice.py +++ b/comps/image2video/src/opea_image2video_microservice.py @@ -23,6 +23,7 @@ component_loader = None + @register_microservice( name="opea_service@image2video", service_type=ServiceType.IMAGE2VIDEO, @@ -63,7 +64,7 @@ async def image2video(input: ImagesPath): image2video_component_name, name=image2video_component_name, description=f"OPEA IMAGE2VIDEO Component: {image2video_component_name}", - config=args.__dict__ + config=args.__dict__, ) except Exception as e: logger.error(f"Failed to initialize components: {e}") diff --git a/comps/tts/src/integrations/opea_gptsovits.py b/comps/tts/src/integrations/opea_gptsovits.py index e41a3a30f8..e3e74ab496 100644 --- a/comps/tts/src/integrations/opea_gptsovits.py +++ b/comps/tts/src/integrations/opea_gptsovits.py @@ -4,7 +4,8 @@ import os import time -import requests, httpx +import httpx +import requests from fastapi.responses import StreamingResponse from comps import CustomLogger, OpeaComponent, OpeaComponentRegistry, ServiceType diff --git a/comps/tts/src/integrations/opea_speecht5.py b/comps/tts/src/integrations/opea_speecht5.py index e8a42352f1..b62542c99b 100644 --- a/comps/tts/src/integrations/opea_speecht5.py +++ b/comps/tts/src/integrations/opea_speecht5.py @@ -4,7 +4,8 @@ import os import time -import requests, httpx +import httpx +import requests from fastapi.responses import StreamingResponse from comps import CustomLogger, OpeaComponent, OpeaComponentRegistry, ServiceType From cee4899ff6f76e2c8bdb5c5dc2a4497607f63647 Mon Sep 17 00:00:00 2001 From: lvliang-intel Date: Sat, 4 Jan 2025 09:22:52 +0800 Subject: [PATCH 12/15] fix tts response issue Signed-off-by: lvliang-intel --- comps/tts/src/integrations/opea_gptsovits.py | 11 +++++++---- comps/tts/src/integrations/opea_speecht5.py | 11 +++++++---- 2 files changed, 14 insertions(+), 8 deletions(-) diff --git a/comps/tts/src/integrations/opea_gptsovits.py b/comps/tts/src/integrations/opea_gptsovits.py index e41a3a30f8..81f37b81fc 100644 --- a/comps/tts/src/integrations/opea_gptsovits.py +++ b/comps/tts/src/integrations/opea_gptsovits.py @@ -4,7 +4,7 @@ import os import time -import requests, httpx +import requests, asyncio from fastapi.responses import StreamingResponse from comps import CustomLogger, OpeaComponent, OpeaComponentRegistry, ServiceType @@ -32,14 +32,17 @@ def __init__(self, name: str, description: str, config: dict = None): async def invoke( self, request: AudioSpeechRequest, - ) -> httpx.Response: + ) -> requests.models.Response: """Involve the TTS service to generate speech for the provided input.""" # see https://github.com/Spycsh/GPT-SoVITS/blob/openai_compat/api.py#L948 for usage # make sure you change the refer_wav_path locally request.voice = None - async with httpx.AsyncClient() as client: - response = await client.post(f"{self.base_url}/v1/audio/speech", json=request.dict()) + response = await asyncio.to_thread( + requests.post, + f"{self.base_url}/v1/audio/speech", + json=request.dict(), + ) return response def check_health(self) -> bool: diff --git a/comps/tts/src/integrations/opea_speecht5.py b/comps/tts/src/integrations/opea_speecht5.py index e8a42352f1..91e711c483 100644 --- a/comps/tts/src/integrations/opea_speecht5.py +++ b/comps/tts/src/integrations/opea_speecht5.py @@ -4,7 +4,7 @@ import os import time -import requests, httpx +import requests, asyncio from fastapi.responses import StreamingResponse from comps import CustomLogger, OpeaComponent, OpeaComponentRegistry, ServiceType @@ -32,7 +32,7 @@ def __init__(self, name: str, description: str, config: dict = None): async def invoke( self, request: AudioSpeechRequest, - ) -> httpx.Response: + ) -> requests.models.Response: """Involve the TTS service to generate speech for the provided input.""" # validate the request parameters if request.model not in ["microsoft/speecht5_tts"]: @@ -40,8 +40,11 @@ async def invoke( if request.voice not in ["default", "male"] or request.speed != 1.0: logger.warning("Currently parameter 'speed' can only be 1.0 and 'voice' can only be default or male!") - async with httpx.AsyncClient() as client: - response = await client.post(f"{self.base_url}/v1/audio/speech", json=request.dict()) + response = await asyncio.to_thread( + requests.post, + f"{self.base_url}/v1/audio/speech", + json=request.dict(), + ) return response def check_health(self) -> bool: From cc397d253c60995072cc3f3f8bdf75232d355c18 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Sat, 4 Jan 2025 01:27:50 +0000 Subject: [PATCH 13/15] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- comps/tts/src/integrations/opea_gptsovits.py | 3 ++- comps/tts/src/integrations/opea_speecht5.py | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/comps/tts/src/integrations/opea_gptsovits.py b/comps/tts/src/integrations/opea_gptsovits.py index 81f37b81fc..71eb5101e6 100644 --- a/comps/tts/src/integrations/opea_gptsovits.py +++ b/comps/tts/src/integrations/opea_gptsovits.py @@ -1,10 +1,11 @@ # Copyright (C) 2024 Intel Corporation # SPDX-License-Identifier: Apache-2.0 +import asyncio import os import time -import requests, asyncio +import requests from fastapi.responses import StreamingResponse from comps import CustomLogger, OpeaComponent, OpeaComponentRegistry, ServiceType diff --git a/comps/tts/src/integrations/opea_speecht5.py b/comps/tts/src/integrations/opea_speecht5.py index 91e711c483..905e2fb018 100644 --- a/comps/tts/src/integrations/opea_speecht5.py +++ b/comps/tts/src/integrations/opea_speecht5.py @@ -1,10 +1,11 @@ # Copyright (C) 2024 Intel Corporation # SPDX-License-Identifier: Apache-2.0 +import asyncio import os import time -import requests, asyncio +import requests from fastapi.responses import StreamingResponse from comps import CustomLogger, OpeaComponent, OpeaComponentRegistry, ServiceType From 260eee59479e967876fe6743e4c8fc84ae5c0e00 Mon Sep 17 00:00:00 2001 From: lvliang-intel Date: Mon, 6 Jan 2025 15:41:00 +0800 Subject: [PATCH 14/15] fix comments Signed-off-by: lvliang-intel --- .../src/opea_animation_microservice.py | 1 - comps/asr/src/opea_asr_microservice.py | 2 +- comps/cores/common/component.py | 2 ++ .../src/opea_dataprep_microservice.py | 1 - .../src/opea_embedding_microservice.py | 1 - .../opea_multimodal_embedding_microservice.py | 1 - .../src/opea_image2image_microservice.py | 24 +++++++++++-------- .../src/opea_image2video_microservice.py | 1 - .../text-generation/opea_llm_microservice.py | 2 +- .../src/opea_reranking_microservice.py | 2 +- .../src/opea_retrievers_microservice.py | 1 - .../src/opea_text2sql_microservice.py | 1 - comps/tts/src/opea_tts_microservice.py | 2 +- 13 files changed, 20 insertions(+), 21 deletions(-) diff --git a/comps/animation/src/opea_animation_microservice.py b/comps/animation/src/opea_animation_microservice.py index ec40bfc115..c8875430bb 100644 --- a/comps/animation/src/opea_animation_microservice.py +++ b/comps/animation/src/opea_animation_microservice.py @@ -28,7 +28,6 @@ # Initialize OpeaComponentLoader loader = OpeaComponentLoader( animation_component_name, - name=animation_component_name, description=f"OPEA ANIMATION Component: {animation_component_name}", ) diff --git a/comps/asr/src/opea_asr_microservice.py b/comps/asr/src/opea_asr_microservice.py index 3cc9475750..a219c5d61b 100644 --- a/comps/asr/src/opea_asr_microservice.py +++ b/comps/asr/src/opea_asr_microservice.py @@ -27,7 +27,7 @@ asr_component_name = os.getenv("ASR_COMPONENT_NAME", "OPEA_WHISPER_ASR") # Initialize OpeaComponentLoader loader = OpeaComponentLoader( - asr_component_name, name=asr_component_name, description=f"OPEA ASR Component: {asr_component_name}" + asr_component_name, description=f"OPEA ASR Component: {asr_component_name}" ) diff --git a/comps/cores/common/component.py b/comps/cores/common/component.py index a302fe5b22..64fbeba6c8 100644 --- a/comps/cores/common/component.py +++ b/comps/cores/common/component.py @@ -143,6 +143,8 @@ def __init__(self, component_name, **kwargs): :param component_name: The name of the component to load :param kwargs: Additional parameters for the component's initialization """ + kwargs['name'] = component_name + # Retrieve the component class from the registry component_class = OpeaComponentRegistry.get(component_name) diff --git a/comps/dataprep/src/opea_dataprep_microservice.py b/comps/dataprep/src/opea_dataprep_microservice.py index e3e0cf626b..cb38163969 100644 --- a/comps/dataprep/src/opea_dataprep_microservice.py +++ b/comps/dataprep/src/opea_dataprep_microservice.py @@ -29,7 +29,6 @@ # Initialize OpeaComponentLoader loader = OpeaDataprepLoader( dataprep_component_name, - name=dataprep_component_name, description=f"OPEA DATAPREP Component: {dataprep_component_name}", ) diff --git a/comps/embeddings/src/opea_embedding_microservice.py b/comps/embeddings/src/opea_embedding_microservice.py index 577080019e..0303fcce01 100644 --- a/comps/embeddings/src/opea_embedding_microservice.py +++ b/comps/embeddings/src/opea_embedding_microservice.py @@ -25,7 +25,6 @@ # Initialize OpeaComponentLoader loader = OpeaComponentLoader( embedding_component_name, - name=embedding_component_name, description=f"OPEA Embedding Component: {embedding_component_name}", ) diff --git a/comps/embeddings/src/opea_multimodal_embedding_microservice.py b/comps/embeddings/src/opea_multimodal_embedding_microservice.py index a52f1b048c..4ab31bc88c 100644 --- a/comps/embeddings/src/opea_multimodal_embedding_microservice.py +++ b/comps/embeddings/src/opea_multimodal_embedding_microservice.py @@ -25,7 +25,6 @@ # Initialize OpeaComponentLoader loader = OpeaComponentLoader( embedding_component_name, - name=embedding_component_name, description=f"OPEA Embedding Component: {embedding_component_name}", ) diff --git a/comps/image2image/src/opea_image2image_microservice.py b/comps/image2image/src/opea_image2image_microservice.py index 83c09e5d9b..b60fd1f591 100644 --- a/comps/image2image/src/opea_image2image_microservice.py +++ b/comps/image2image/src/opea_image2image_microservice.py @@ -23,15 +23,7 @@ logger = CustomLogger("image2image") - -image2image_component_name = os.getenv("IMAGE2IMAGE_COMPONENT_NAME", "OPEA_IMAGE2IMAGE") -# Initialize OpeaComponentLoader -loader = OpeaComponentLoader( - image2image_component_name, - name=image2image_component_name, - description=f"OPEA IMAGE2IMAGE Component: {image2image_component_name}", -) - +component_loader = None @register_microservice( name="opea_service@image2image", @@ -45,7 +37,7 @@ @register_statistics(names=["opea_service@image2image"]) def image2image(input: SDImg2ImgInputs): start = time.time() - results = loader.invoke(input) + results = component_loader.invoke(input) statistics_dict["opea_service@image2image"].append_latency(time.time() - start, None) return SDOutputs(images=results) @@ -60,6 +52,18 @@ def image2image(input: SDImg2ImgInputs): parser.add_argument("--bf16", action="store_true") args = parser.parse_args() + image2image_component_name = os.getenv("IMAGE2IMAGE_COMPONENT_NAME", "OPEA_IMAGE2IMAGE") + # Register components + try: + # Initialize OpeaComponentLoader + component_loader = OpeaComponentLoader( + image2image_component_name, + description=f"OPEA IMAGE2IMAGE Component: {image2image_component_name}", + config=args.__dict__, + ) + except Exception as e: + logger.error(f"Failed to initialize components: {e}") + exit(1) logger.info("Image2image server started.") opea_microservices["opea_service@image2image"].start() diff --git a/comps/image2video/src/opea_image2video_microservice.py b/comps/image2video/src/opea_image2video_microservice.py index f17be2a2c9..8e61c1c0da 100644 --- a/comps/image2video/src/opea_image2video_microservice.py +++ b/comps/image2video/src/opea_image2video_microservice.py @@ -62,7 +62,6 @@ async def image2video(input: ImagesPath): # Initialize OpeaComponentLoader component_loader = OpeaComponentLoader( image2video_component_name, - name=image2video_component_name, description=f"OPEA IMAGE2VIDEO Component: {image2video_component_name}", config=args.__dict__, ) diff --git a/comps/llms/src/text-generation/opea_llm_microservice.py b/comps/llms/src/text-generation/opea_llm_microservice.py index 513d8d5201..94f3bf0213 100644 --- a/comps/llms/src/text-generation/opea_llm_microservice.py +++ b/comps/llms/src/text-generation/opea_llm_microservice.py @@ -27,7 +27,7 @@ llm_component_name = os.getenv("LLM_COMPONENT_NAME", "OPEA_LLM") # Initialize OpeaComponentLoader loader = OpeaComponentLoader( - llm_component_name, name=llm_component_name, description=f"OPEA LLM Component: {llm_component_name}" + llm_component_name, description=f"OPEA LLM Component: {llm_component_name}" ) diff --git a/comps/reranks/src/opea_reranking_microservice.py b/comps/reranks/src/opea_reranking_microservice.py index 55de837b0f..29215ddb39 100644 --- a/comps/reranks/src/opea_reranking_microservice.py +++ b/comps/reranks/src/opea_reranking_microservice.py @@ -25,7 +25,7 @@ rerank_component_name = os.getenv("RERANK_COMPONENT_NAME", "OPEA_RERANK_TEI") # Initialize OpeaComponentLoader loader = OpeaComponentLoader( - rerank_component_name, name=rerank_component_name, description=f"OPEA RERANK Component: {rerank_component_name}" + rerank_component_name, description=f"OPEA RERANK Component: {rerank_component_name}" ) diff --git a/comps/retrievers/src/opea_retrievers_microservice.py b/comps/retrievers/src/opea_retrievers_microservice.py index 067199de15..273c4d9a91 100644 --- a/comps/retrievers/src/opea_retrievers_microservice.py +++ b/comps/retrievers/src/opea_retrievers_microservice.py @@ -37,7 +37,6 @@ # Initialize OpeaComponentLoader loader = OpeaComponentLoader( retriever_component_name, - name=retriever_component_name, description=f"OPEA RETRIEVER Component: {retriever_component_name}", ) diff --git a/comps/text2sql/src/opea_text2sql_microservice.py b/comps/text2sql/src/opea_text2sql_microservice.py index 63abd8edf5..c662b78eec 100644 --- a/comps/text2sql/src/opea_text2sql_microservice.py +++ b/comps/text2sql/src/opea_text2sql_microservice.py @@ -21,7 +21,6 @@ # Initialize OpeaComponentLoader loader = OpeaComponentLoader( text2sql_component_name, - name=text2sql_component_name, description=f"OPEA RERANK Component: {text2sql_component_name}", ) diff --git a/comps/tts/src/opea_tts_microservice.py b/comps/tts/src/opea_tts_microservice.py index eddff0104c..a30f5c7c3c 100644 --- a/comps/tts/src/opea_tts_microservice.py +++ b/comps/tts/src/opea_tts_microservice.py @@ -25,7 +25,7 @@ tts_component_name = os.getenv("TTS_COMPONENT_NAME", "OPEA_SPEECHT5_TTS") # Initialize OpeaComponentLoader loader = OpeaComponentLoader( - tts_component_name, name=tts_component_name, description=f"OPEA TTS Component: {tts_component_name}" + tts_component_name, description=f"OPEA TTS Component: {tts_component_name}" ) From 44ccc7b45b3613f23caf35fcdc4b43397a063456 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Mon, 6 Jan 2025 07:47:07 +0000 Subject: [PATCH 15/15] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- comps/asr/src/opea_asr_microservice.py | 4 +--- comps/cores/common/component.py | 2 +- comps/image2image/src/opea_image2image_microservice.py | 3 ++- comps/llms/src/text-generation/opea_llm_microservice.py | 4 +--- comps/reranks/src/opea_reranking_microservice.py | 4 +--- comps/tts/src/opea_tts_microservice.py | 4 +--- 6 files changed, 7 insertions(+), 14 deletions(-) diff --git a/comps/asr/src/opea_asr_microservice.py b/comps/asr/src/opea_asr_microservice.py index a219c5d61b..decf602a69 100644 --- a/comps/asr/src/opea_asr_microservice.py +++ b/comps/asr/src/opea_asr_microservice.py @@ -26,9 +26,7 @@ asr_component_name = os.getenv("ASR_COMPONENT_NAME", "OPEA_WHISPER_ASR") # Initialize OpeaComponentLoader -loader = OpeaComponentLoader( - asr_component_name, description=f"OPEA ASR Component: {asr_component_name}" -) +loader = OpeaComponentLoader(asr_component_name, description=f"OPEA ASR Component: {asr_component_name}") @register_microservice( diff --git a/comps/cores/common/component.py b/comps/cores/common/component.py index 64fbeba6c8..6f8544818b 100644 --- a/comps/cores/common/component.py +++ b/comps/cores/common/component.py @@ -143,7 +143,7 @@ def __init__(self, component_name, **kwargs): :param component_name: The name of the component to load :param kwargs: Additional parameters for the component's initialization """ - kwargs['name'] = component_name + kwargs["name"] = component_name # Retrieve the component class from the registry component_class = OpeaComponentRegistry.get(component_name) diff --git a/comps/image2image/src/opea_image2image_microservice.py b/comps/image2image/src/opea_image2image_microservice.py index b60fd1f591..af07ce9d74 100644 --- a/comps/image2image/src/opea_image2image_microservice.py +++ b/comps/image2image/src/opea_image2image_microservice.py @@ -25,6 +25,7 @@ component_loader = None + @register_microservice( name="opea_service@image2image", service_type=ServiceType.IMAGE2IMAGE, @@ -60,7 +61,7 @@ def image2image(input: SDImg2ImgInputs): image2image_component_name, description=f"OPEA IMAGE2IMAGE Component: {image2image_component_name}", config=args.__dict__, - ) + ) except Exception as e: logger.error(f"Failed to initialize components: {e}") exit(1) diff --git a/comps/llms/src/text-generation/opea_llm_microservice.py b/comps/llms/src/text-generation/opea_llm_microservice.py index 94f3bf0213..fb24911c41 100644 --- a/comps/llms/src/text-generation/opea_llm_microservice.py +++ b/comps/llms/src/text-generation/opea_llm_microservice.py @@ -26,9 +26,7 @@ llm_component_name = os.getenv("LLM_COMPONENT_NAME", "OPEA_LLM") # Initialize OpeaComponentLoader -loader = OpeaComponentLoader( - llm_component_name, description=f"OPEA LLM Component: {llm_component_name}" -) +loader = OpeaComponentLoader(llm_component_name, description=f"OPEA LLM Component: {llm_component_name}") @register_microservice( diff --git a/comps/reranks/src/opea_reranking_microservice.py b/comps/reranks/src/opea_reranking_microservice.py index 29215ddb39..fdab6237f0 100644 --- a/comps/reranks/src/opea_reranking_microservice.py +++ b/comps/reranks/src/opea_reranking_microservice.py @@ -24,9 +24,7 @@ rerank_component_name = os.getenv("RERANK_COMPONENT_NAME", "OPEA_RERANK_TEI") # Initialize OpeaComponentLoader -loader = OpeaComponentLoader( - rerank_component_name, description=f"OPEA RERANK Component: {rerank_component_name}" -) +loader = OpeaComponentLoader(rerank_component_name, description=f"OPEA RERANK Component: {rerank_component_name}") @register_microservice( diff --git a/comps/tts/src/opea_tts_microservice.py b/comps/tts/src/opea_tts_microservice.py index a30f5c7c3c..29bd3e1bc0 100644 --- a/comps/tts/src/opea_tts_microservice.py +++ b/comps/tts/src/opea_tts_microservice.py @@ -24,9 +24,7 @@ tts_component_name = os.getenv("TTS_COMPONENT_NAME", "OPEA_SPEECHT5_TTS") # Initialize OpeaComponentLoader -loader = OpeaComponentLoader( - tts_component_name, description=f"OPEA TTS Component: {tts_component_name}" -) +loader = OpeaComponentLoader(tts_component_name, description=f"OPEA TTS Component: {tts_component_name}") async def stream_forwarder(response):