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: Returns:
      A 2-element tuple containing:
  
          1. The new request.
          2. A boolean indicating whether or not the request was transformed from the OpenAI
          chat format.
docstr_tok: ["Returns",":","A","2-element","tuple","containing",":","1",".","The","new","request",".","2",".","A","boolean","indicating","whether","or","not","the","request","was","transformed","from","the","OpenAI","chat","format","."]
code: def _transform_request_json_for_chat_if_necessary(
      request_json, lc_model
  ):
      """
      Returns:
          A 2-element tuple containing:
  
              1. The new request.
              2. A boolean indicating whether or not the request was transformed from the OpenAI
              chat format.
      """
      input_fields = APIRequest._get_lc_model_input_fields(lc_model)
      if "messages" in input_fields:
          # If the chain accepts a "messages" field directly, don't attempt to convert
          # the request to LangChain's Message format automatically. Assume that the chain
          # is handling the "messages" field by itself
          return request_json, False
  
      def json_dict_might_be_chat_request(json: Dict):
          return (
              "messages" in request_json
              and
              # Additional keys can't be specified when calling LangChain invoke() / batch()
              # with chat messages
              len(request_json) == 1
          )
  
      if isinstance(
          request_json, dict
      ) and json_dict_might_be_chat_request(request_json):
          try:
              return (
                  APIRequest._convert_chat_request_or_throw(
                      request_json
                  ),
                  True,
              )
          except pydantic.ValidationError:
              return request_json, False
      elif isinstance(request_json, list) and all(
          json_dict_might_be_chat_request(json) for json in request_json
      ):
          try:
              return (
                  [
                      APIRequest._convert_chat_request_or_throw(
                          json_dict
                      )
                      for json_dict in request_json
                  ],
                  True,
              )
          except pydantic.ValidationError:
              return request_json, False
      else:
          return request_json, 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 3 for calling the APIRequest obj's underlying member method code with example usage: obj._transform_request_json_for_chat_if_necessary(request_json, lc_model) and returns: request_json,  False, unknown, APIRequest,  True, request_json,  False, request_json,  False, unknown,  True, request_json,  False