Код: Выделить всё
class ModelWrapper(AbstractLLMInterface):
"""The Claude 3 Sonnet model wrapper following the interface."""
def __init__(
self,
region: str = CONFIGS["GCP"]["REGION"],
project: str = get_gcp_project_id(),
model: str = CONFIGS["MODELS"]["SONNET_ID"],
) -> None:
"""Set up the claude client using the region and project."""
self.client: AnthropicVertex = AnthropicVertex(region=region, project_id=project)
self.model_name: str = model
self.role_key: str = "role"
self.content_key: str = "content"
self.user_key: str = "user"
llm_logger.debug(msg=f"Initialised sonnet client for {region}, {project} and {self.model_name}.")
def get_completion(self, user_prompt: str, system_prompt: str, history: List[Correspondence]) -> Iterator[str]:
"""
Fetch a response from the model.This requires an egress request to GCP and the
service for Anthropic model must be enabled in the VertexAI console.
"""
# This is where the API call to GCP service happens
return self.client.messages.stream(user_prompt, system_prompt, history)
Означает ли это, что любой модульный тест должен выполнять вызов API? Или класс спроектирован неправильно? Любая помощь будет оценена по достоинству.
Класс должен быть доступен для тестирования без вызова API.
Примечание
Я знаю, что изменение конструктора класса для принятия объекта AnthropicVertex делает издевательство тривиально простым. Но цель вопроса — проверить этот класс в том виде, в котором он существует, а не изменить его.Однако, если текущий дизайн класса нарушает какие-либо базовый принцип проектирования (например, SOLID), это то, что мне хотелось бы знать и понимать. Поэтому любая ссылка будет оценена.
Подробнее здесь: https://stackoverflow.com/questions/793 ... external-s