class_docstr: Stores an API request's inputs, outputs, and other metadata. Contains a method to make an API
  call.
class_docstr_tok: ["Stores","an","API","request","'s","inputs",",","outputs",",","and","other","metadata",".","Contains","a","method","to","make","an","API","call","."]
docstr: Calls the LangChain API and stores results.
docstr_tok: ["Calls","the","LangChain","API","and","stores","results","."]
code: def call_api(
      self,
      status_tracker: StatusTracker,
      callback_handlers: Optional[List[BaseCallbackHandler]],
  ):
      """
      Calls the LangChain API and stores results.
      """
      from langchain.schema import BaseRetriever
  
      from mlflow.langchain.utils import (
          lc_runnables_types,
          runnables_supports_batch_types,
      )
  
      _logger.debug(
          f"Request #{self.index} started with payload: {self.request_json}"
      )
  
      try:
          if isinstance(self.lc_model, BaseRetriever):
              # Retrievers are invoked differently than Chains
              docs = self.lc_model.get_relevant_documents(
                  **self.request_json
              )
              response = [
                  {
                      "page_content": doc.page_content,
                      "metadata": doc.metadata,
                  }
                  for doc in docs
              ]
          elif isinstance(self.lc_model, lc_runnables_types()):
              (
                  prepared_request_json,
                  did_perform_chat_conversion,
              ) = APIRequest._transform_request_json_for_chat_if_necessary(
                  self.request_json, self.lc_model
              )
              if isinstance(self.request_json, dict):
                  # This is a temporary fix for the case when spark_udf converts
                  # input into pandas dataframe with column name, while the model
                  # does not accept dictionaries as input, it leads to errors like
                  # Expected Scalar value for String field 'query_text'
                  try:
                      response = self.lc_model.invoke(
                          prepared_request_json,
                          config={"callbacks": callback_handlers},
                      )
                  except TypeError as e:
                      _logger.warning(
                          f"Failed to invoke {self.lc_model.__class__.__name__} "
                          f"with {self.request_json}. Error: {e!r}. Trying to "
                          "invoke with the first value of the dictionary."
                      )
                      self.request_json = next(
                          iter(self.request_json.values())
                      )
                      (
                          prepared_request_json,
                          did_perform_chat_conversion,
                      ) = APIRequest._transform_request_json_for_chat_if_necessary(
                          self.request_json, self.lc_model
                      )
  
                      response = self.lc_model.invoke(
                          prepared_request_json,
                          config={"callbacks": callback_handlers},
                      )
              elif isinstance(self.request_json, list) and isinstance(
                  self.lc_model, runnables_supports_batch_types()
              ):
                  response = self.lc_model.batch(
                      prepared_request_json,
                      config={"callbacks": callback_handlers},
                  )
              else:
                  response = self.lc_model.invoke(
                      prepared_request_json,
                      config={"callbacks": callback_handlers},
                  )
  
              if (
                  did_perform_chat_conversion
                  or self.convert_chat_responses
              ):
                  response = (
                      APIRequest._try_transform_response_to_chat_format(
                          response
                      )
                  )
          else:
              (
                  prepared_request_json,
                  did_perform_chat_conversion,
              ) = APIRequest._transform_request_json_for_chat_if_necessary(
                  self.request_json, self.lc_model
              )
              response = self.lc_model(
                  prepared_request_json,
                  return_only_outputs=True,
                  callbacks=callback_handlers,
              )
  
              if (
                  did_perform_chat_conversion
                  or self.convert_chat_responses
              ):
                  response = (
                      APIRequest._try_transform_response_to_chat_format(
                          response
                      )
                  )
              elif len(response) == 1:
                  # to maintain existing code, single output chains will still return
                  # only the result
                  response = response.popitem()[1]
              else:
                  self._prepare_to_serialize(response)
  
          _logger.debug(
              f"Request #{self.index} succeeded with response: {response}"
          )
          self.results.append((self.index, response))
          status_tracker.complete_task(success=True)
      except Exception as e:
          self.errors[
              self.index
          ] = f"error: {e!r} {traceback.format_exc()}\n request payload: {self.request_json}"
          status_tracker.increment_num_api_errors()
          status_tracker.complete_task(success=False)
  
imports: from __future__ import annotations
  import json
  import logging
  import queue
  import threading
  import time
  import traceback
  from concurrent.futures import ThreadPoolExecutor
  from dataclasses import dataclass
  from typing import Any, Dict, List, Literal, Optional, Set, Union
  import langchain.chains
  import pydantic
  from langchain.callbacks.base import BaseCallbackHandler
  from langchain.schema import AgentAction, AIMessage, HumanMessage, SystemMessage
  from langchain.schema import ChatMessage
  from packaging.version import Version
  import mlflow
  from mlflow.exceptions import MlflowException
label_desc: Use image node_id 2 for calling the APIRequest obj's underlying member method code with example usage: obj.call_api(status_tracker, callback_handlers) without return types