Skip to content

Commit

Permalink
Merge branch 'fea-agent-morpheus' of https://github.com/nv-morpheus/M…
Browse files Browse the repository at this point in the history
…orpheus into openai-client-updates
  • Loading branch information
efajardo-nv committed May 14, 2024
2 parents d172d01 + ff665c5 commit d3c739c
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 11 deletions.
17 changes: 11 additions & 6 deletions morpheus/llm/services/llm_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -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__)


Expand Down Expand Up @@ -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
Expand All @@ -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.
"""
Expand All @@ -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])
Expand Down
3 changes: 0 additions & 3 deletions morpheus/llm/services/nvfoundation_llm_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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

Expand Down
4 changes: 2 additions & 2 deletions morpheus/utils/logger.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down

0 comments on commit d3c739c

Please sign in to comment.