diff --git a/morpheus/llm/services/llm_service.py b/morpheus/llm/services/llm_service.py index 2d2a3ae333..db11fdb84b 100644 --- a/morpheus/llm/services/llm_service.py +++ b/morpheus/llm/services/llm_service.py @@ -18,6 +18,10 @@ from abc import ABC from abc import abstractmethod +if typing.TYPE_CHECKING: + from morpheus.llm.services.nemo_llm_service import NeMoLLMService + from morpheus.llm.services.openai_chat_service import OpenAIChatService + logger = logging.getLogger(__name__) @@ -137,14 +141,12 @@ def get_client(self, *, model_name: str, **model_kwargs) -> LLMClient: @typing.overload @staticmethod - def create(service_type: typing.Literal["nemo"], *service_args, - **service_kwargs) -> "morpheus.llm.services.nemo_llm_service.NeMoLLMService": + def create(service_type: typing.Literal["nemo"], *service_args, **service_kwargs) -> "NeMoLLMService": pass @typing.overload @staticmethod - def create(service_type: typing.Literal["openai"], *service_args, - **service_kwargs) -> "morpheus.llm.services.openai_chat_service.OpenAIChatService": + def create(service_type: typing.Literal["openai"], *service_args, **service_kwargs) -> "OpenAIChatService": pass @typing.overload @@ -160,6 +162,8 @@ def create(service_type: str | typing.Literal["nemo"] | typing.Literal["openai"] ---------- service_type : str The type of the service to create + service_args : list + Additional arguments to pass to the service. service_kwargs : dict[str, typing.Any] Additional keyword arguments to pass to the service. """ @@ -172,14 +176,15 @@ def create(service_type: str | typing.Literal["nemo"] | typing.Literal["openai"] module = importlib.import_module(module_name) # Get all of the classes in the module to find the correct service class - mod_classes = dict([(name, cls) for name, cls in module.__dict__.items() if isinstance(cls, type)]) + mod_classes = dict({name: cls for name, cls in module.__dict__.items() if isinstance(cls, type)}) class_name_lower = f"{service_type}{llm_or_chat}Service".lower() # Find case-insensitive match for the class name matching_classes = [name for name in mod_classes if name.lower() == class_name_lower] - assert len(matching_classes) == 1, f"Expected to find exactly one class with name {class_name_lower} in module {module_name}, but found {matching_classes}" + assert len(matching_classes) == 1, (f"Expected to find exactly one class with name {class_name_lower} " + f"in module {module_name}, but found {matching_classes}") # Create the class class_ = getattr(module, matching_classes[0]) diff --git a/morpheus/llm/services/nvfoundation_llm_service.py b/morpheus/llm/services/nvfoundation_llm_service.py index 901873ba8c..1d49682b50 100644 --- a/morpheus/llm/services/nvfoundation_llm_service.py +++ b/morpheus/llm/services/nvfoundation_llm_service.py @@ -12,10 +12,8 @@ # See the License for the specific language governing permissions and # limitations under the License. -import asyncio import logging import os -import typing from morpheus.llm.services.llm_service import LLMClient from morpheus.llm.services.llm_service import LLMService @@ -31,7 +29,6 @@ try: from langchain_core.prompt_values import StringPromptValue from langchain_nvidia_ai_endpoints import ChatNVIDIA - from langchain_nvidia_ai_endpoints._common import NVEModel except ImportError as import_exc: IMPORT_EXCEPTION = import_exc diff --git a/morpheus/utils/logger.py b/morpheus/utils/logger.py index 7d4932edf1..49482642e3 100644 --- a/morpheus/utils/logger.py +++ b/morpheus/utils/logger.py @@ -126,8 +126,8 @@ def _configure_from_log_level(*extra_handlers: logging.Handler, log_level: int): # This needs the be the only handler for morpheus logger morpheus_queue_handler = logging.handlers.QueueHandler(morpheus_logging_queue) - # At this point, any morpheus logger will propagate upstream to the morpheus root and then be handled by the queue - # handler + # At this point, any morpheus logger will propagate upstream to the morpheus root and then be handled by the + # queue handler morpheus_logger.addHandler(morpheus_queue_handler) log_file = os.path.join(appdirs.user_log_dir(appauthor="NVIDIA", appname="morpheus"), "morpheus.log")