Skip to content

Commit

Permalink
Merge pull request #1318 from dagardner-nv/david-fea-sherlock-llm-ser…
Browse files Browse the repository at this point in the history
…vice

Docstrings for LLMService & LLMClient
  • Loading branch information
dagardner-nv authored Oct 27, 2023
2 parents 986bb23 + e07a35f commit 40e1b84
Show file tree
Hide file tree
Showing 3 changed files with 80 additions and 1 deletion.
1 change: 1 addition & 0 deletions docker/conda/environments/cuda11.8_dev.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
53 changes: 52 additions & 1 deletion morpheus/llm/services/llm_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,33 +13,84 @@
# limitations under the License.

import logging
import typing
from abc import ABC
from abc import abstractmethod

logger = logging.getLogger(__name__)


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:
"""
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):
"""
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) -> 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.
"""
pass
27 changes: 27 additions & 0 deletions tests/llm/services/test_llm_service.py
Original file line number Diff line number Diff line change
@@ -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)

0 comments on commit 40e1b84

Please sign in to comment.