From 151e803adec20966b1024ffb553cbbb061f81fc2 Mon Sep 17 00:00:00 2001 From: Vladimir Blagojevic Date: Tue, 28 May 2024 13:51:26 +0200 Subject: [PATCH] More linting --- haystack_experimental/util/openapi.py | 42 +++++++-------------------- 1 file changed, 10 insertions(+), 32 deletions(-) diff --git a/haystack_experimental/util/openapi.py b/haystack_experimental/util/openapi.py index b51d985e..552892ca 100644 --- a/haystack_experimental/util/openapi.py +++ b/haystack_experimental/util/openapi.py @@ -18,7 +18,7 @@ from requests.adapters import HTTPAdapter from urllib3 import Retry -VALID_HTTP_METHODS = ["get", "put", "post", "delete", "options", "head","patch","trace"] +VALID_HTTP_METHODS = ["get", "put", "post", "delete", "options", "head", "patch", "trace"] MIN_REQUIRED_OPENAPI_SPEC_VERSION = 3 @@ -185,13 +185,7 @@ class HttpClientError(Exception): class Operation: """ Represents an operation in an OpenAPI specification.""" - def __init__( - self, - path: str, - method: str, - operation_dict: Dict[str, Any], - spec_dict: Dict[str, Any], - ): + def __init__(self, path: str, method: str, operation_dict: Dict[str, Any], spec_dict: Dict[str, Any]): if method.lower() not in VALID_HTTP_METHODS: raise ValueError(f"Invalid HTTP method: {method}") self.path = path @@ -393,9 +387,7 @@ def to_dict(self, *, resolve_references: Optional[bool] = False) -> Dict[str, An :param resolve_references: If True, resolve references in the specification. :return: A dictionary representation of the OpenAPI specification, optionally fully resolved. """ - if resolve_references: - return jsonref.replace_refs(self.spec_dict, proxies=False) - return self.spec_dict + return jsonref.replace_refs(self.spec_dict, proxies=False) if resolve_references else self.spec_dict class ClientConfiguration: @@ -463,10 +455,7 @@ def get_tools_definitions(self) -> List[Dict[str, Any]]: """ Get the tools definitions used as tools LLM parameter. """ - provider_to_converter = { - "anthropic": anthropic_converter, - "cohere": cohere_converter, - } + provider_to_converter = {"anthropic": anthropic_converter, "cohere": cohere_converter} converter = provider_to_converter.get(self.llm_provider, openai_converter) return converter(self.openapi_spec) @@ -474,13 +463,9 @@ def get_payload_extractor(self): """ Get the payload extractor for the LLM provider. """ - provider_to_arguments_field_name = { - "anthropic": "input", - "cohere": "parameters" - # add more providers here - } - arguments_field_name = provider_to_arguments_field_name.get(self.llm_provider, - "arguments") # default to OpenAI "arguments" + provider_to_arguments_field_name = {"anthropic": "input", "cohere": "parameters"} # add more providers here + # default to OpenAI "arguments" + arguments_field_name = provider_to_arguments_field_name.get(self.llm_provider, "arguments") return LLMFunctionPayloadExtractor(arguments_field_name=arguments_field_name) def _create_authentication_from_string( @@ -579,8 +564,7 @@ class ClientConfigurationBuilder: ClientConfigurationBuilder provides a fluent interface for constructing a `ClientConfiguration`. This builder allows for the step-by-step configuration of all necessary components to interact with an - API defined by an OpenAPI specification. The builder ensures that all configurations are set before building - a valid `ClientConfiguration` instance. + API defined by an OpenAPI specification. """ def __init__(self): @@ -667,10 +651,7 @@ def build(self) -> ClientConfiguration: class RequestBuilder: """ Builds an HTTP request based on an OpenAPI operation""" - def __init__( - self, - client_config: ClientConfiguration, - ): + def __init__(self, client_config: ClientConfiguration): self.openapi_parser = client_config.get_openapi_spec() self.http_client = client_config.get_http_client() self.auth_config = client_config.get_auth_config() or PassThroughAuthentication() @@ -758,10 +739,7 @@ class OpenAPIServiceClient: simplifies the process of (LLMs) with services defined by OpenAPI specifications. """ - def __init__( - self, - client_config: ClientConfiguration, - ): + def __init__(self, client_config: ClientConfiguration): self.openapi_spec = client_config.get_openapi_spec() self.http_client = client_config.get_http_client() self.request_builder = RequestBuilder(client_config)