class_docstr: OpenAPIServiceConnector connects to OpenAPI services, allowing for the invocation of methods specified in
  an OpenAPI specification of that service. It integrates with ChatMessage interface, where messages are used to
  determine the method to be called and the parameters to be passed. The message payload should be a JSON formatted
  string consisting of the method name and the parameters to be passed to the method. The method name and parameters
  are then used to invoke the method on the OpenAPI service. The response from the service is returned as a
  ChatMessage.
  
  Before using this component, one needs to register functions from the OpenAPI specification with LLM.
  This can be done using the OpenAPIServiceToFunctions component.
docstr: Processes a list of chat messages to invoke a method on an OpenAPI service. It parses the last message in the
  list, expecting it to contain an OpenAI function calling descriptor (name & parameters) in JSON format.
  
  :param messages: A list of `ChatMessage` objects representing the chat history.
  :type messages: List[ChatMessage]
  :param service_openapi_spec: The OpenAPI JSON specification object of the service.
  :type service_openapi_spec: JSON object
  :return: A dictionary with a key `"service_response"`, containing the response from the OpenAPI service.
  :rtype: Dict[str, List[ChatMessage]]
  :raises ValueError: If the last message is not from the assistant or if it does not contain the correct payload
  to invoke a method on the service.
code: def run(
      self,
      messages: List[ChatMessage],
      service_openapi_spec: Dict[str, Any],
  ) -> Dict[str, List[ChatMessage]]:
      """
      Processes a list of chat messages to invoke a method on an OpenAPI service. It parses the last message in the
      list, expecting it to contain an OpenAI function calling descriptor (name & parameters) in JSON format.
  
      :param messages: A list of `ChatMessage` objects representing the chat history.
      :type messages: List[ChatMessage]
      :param service_openapi_spec: The OpenAPI JSON specification object of the service.
      :type service_openapi_spec: JSON object
      :return: A dictionary with a key `"service_response"`, containing the response from the OpenAPI service.
      :rtype: Dict[str, List[ChatMessage]]
      :raises ValueError: If the last message is not from the assistant or if it does not contain the correct payload
      to invoke a method on the service.
      """
  
      last_message = messages[-1]
      if not last_message.is_from(ChatRole.ASSISTANT):
          raise ValueError(f"{last_message} is not from the assistant.")
  
      function_invocation_payloads = self._parse_message(last_message)
  
      # instantiate the OpenAPI service for the given specification
      openapi_service = OpenAPI(service_openapi_spec)
      self._authenticate_service(openapi_service)
  
      response_messages = []
      for method_invocation_descriptor in function_invocation_payloads:
          service_response = self._invoke_method(
              openapi_service, method_invocation_descriptor
          )
          response_messages.append(
              ChatMessage.from_user(str(service_response))
          )
  
      return {"service_response": response_messages}
  
file_path: haystack/haystack/components/connectors/openapi_service.py
imports: import json
  import logging
  from typing import List, Dict, Any, Optional
  from haystack import component
  from haystack.dataclasses import ChatMessage, ChatRole
  from haystack.lazy_imports import LazyImport
label_desc: Use image node_id 2 for calling the OpenAPIServiceConnector obj's underlying member method code with example usage: obj.run(messages, service_openapi_spec) and returns: dict