From b23f231a938b44d540ad8ac1978f078d1890e043 Mon Sep 17 00:00:00 2001 From: David Gardner Date: Thu, 26 Oct 2023 16:01:14 -0700 Subject: [PATCH 1/3] Tests and docstrings --- morpheus/llm/services/llm_service.py | 46 +++++++++++++++++++++++++- tests/llm/services/test_llm_service.py | 27 +++++++++++++++ 2 files changed, 72 insertions(+), 1 deletion(-) create mode 100644 tests/llm/services/test_llm_service.py diff --git a/morpheus/llm/services/llm_service.py b/morpheus/llm/services/llm_service.py index 4e651195e2..4229955a2a 100644 --- a/morpheus/llm/services/llm_service.py +++ b/morpheus/llm/services/llm_service.py @@ -13,6 +13,7 @@ # limitations under the License. import logging +import typing from abc import ABC from abc import abstractmethod @@ -23,23 +24,66 @@ class LLMClient(ABC): @abstractmethod def generate(self, prompt: str) -> str: + """ + Issue a request to generate a response based on a given prompt. + + Parameters + ---------- + prompt : str + The prompt to generate a response for. + """ pass @abstractmethod async def generate_async(self, prompt: str) -> str: + """ + Issue an asynchronous request to generate a response based on a given prompt. + + Parameters + ---------- + prompt : str + The prompt to generate a response for. + """ pass @abstractmethod def generate_batch(self, prompts: list[str]) -> list[str]: + """ + Issue a request to generate a list of responses based on a list of prompts. + + Parameters + ---------- + prompts : list[str] + The prompts to generate responses for. + """ pass @abstractmethod async def generate_batch_async(self, prompts: list[str]) -> list[str]: + """ + Issue an asynchronous request to generate a list of responses based on a list of prompts. + + Parameters + ---------- + prompts : list[str] + The prompts to generate responses for. + """ pass class LLMService(ABC): @abstractmethod - def get_client(self, model_name: str, **model_kwargs) -> LLMClient: + def get_client(self, model_name: str, **model_kwargs: dict[str, typing.Any]) -> LLMClient: + """ + Returns a client for interacting with a specific model. + + Parameters + ---------- + model_name : str + The name of the model to create a client for. + + model_kwargs : dict[str, typing.Any] + Additional keyword arguments to pass to the model when generating text. + """ pass diff --git a/tests/llm/services/test_llm_service.py b/tests/llm/services/test_llm_service.py new file mode 100644 index 0000000000..9060963899 --- /dev/null +++ b/tests/llm/services/test_llm_service.py @@ -0,0 +1,27 @@ +# SPDX-FileCopyrightText: Copyright (c) 2023, NVIDIA CORPORATION & AFFILIATES. All rights reserved. +# SPDX-License-Identifier: Apache-2.0 +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import inspect +from abc import ABC + +import pytest + +from morpheus.llm.services.llm_service import LLMClient +from morpheus.llm.services.llm_service import LLMService + + +@pytest.mark.parametrize("cls", [LLMClient, LLMService]) +def test_is_abstract(cls: ABC): + assert inspect.isabstract(cls) From 2564a0a51e44aa69bca42fc2b65cd65d792e93bc Mon Sep 17 00:00:00 2001 From: David Gardner Date: Thu, 26 Oct 2023 16:03:13 -0700 Subject: [PATCH 2/3] workaround for https://github.com/nv-morpheus/Morpheus/issues/1317 --- docker/conda/environments/cuda11.8_dev.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/docker/conda/environments/cuda11.8_dev.yml b/docker/conda/environments/cuda11.8_dev.yml index 5785546684..9d25275e13 100644 --- a/docker/conda/environments/cuda11.8_dev.yml +++ b/docker/conda/environments/cuda11.8_dev.yml @@ -34,6 +34,7 @@ dependencies: - configargparse=1.5 - cuda-compiler=11.8 - cuda-nvml-dev=11.8 + - cuda-python>=11.8,<11.8.3 # workaround for https://github.com/nv-morpheus/Morpheus/issues/1317 - cuda-toolkit=11.8 - cudf=23.06 - cupy>=12.0.0 From e07a35f8b8f13d42361b4641435322bf594a03c2 Mon Sep 17 00:00:00 2001 From: David Gardner Date: Thu, 26 Oct 2023 16:16:58 -0700 Subject: [PATCH 3/3] More docstrings --- morpheus/llm/services/llm_service.py | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/morpheus/llm/services/llm_service.py b/morpheus/llm/services/llm_service.py index 4229955a2a..16fd6f0d9d 100644 --- a/morpheus/llm/services/llm_service.py +++ b/morpheus/llm/services/llm_service.py @@ -21,6 +21,10 @@ class LLMClient(ABC): + """ + Abstract interface for clients which are able to interact with LLM models. Concrete implementations of this class + will have an associated implementation of `LLMService` which is able to construct instances of this class. + """ @abstractmethod def generate(self, prompt: str) -> str: @@ -72,6 +76,9 @@ async def generate_batch_async(self, prompts: list[str]) -> list[str]: class LLMService(ABC): + """ + Abstract interface for services which are able to construct clients for interacting with LLM models. + """ @abstractmethod def get_client(self, model_name: str, **model_kwargs: dict[str, typing.Any]) -> LLMClient: @@ -84,6 +91,6 @@ def get_client(self, model_name: str, **model_kwargs: dict[str, typing.Any]) -> The name of the model to create a client for. model_kwargs : dict[str, typing.Any] - Additional keyword arguments to pass to the model when generating text. + Additional keyword arguments to pass to the model. """ pass