function getMessagesFromRequest(request, shim) {
  // There are a few different ways to pass messages to OpenAI SDK.
  //
  // For langchain and `chat.completions.create`, messages are passed
  // as an array of objects with `content` and `role` properties
  // to the `messages` field of the request.
  //
  // For `responses.create`, messages are passed as an array of objects
  // with `content` and `role` properties OR as a single string (implied
  // to be a user message) to the `input` field of the request.
  let messages = []

  if (Array.isArray(request?.input)) {
    // Handle array of input messages
    messages = request.input.filter(msg => msg?.content && msg?.role)
  } else if (typeof request?.input === 'string') {
    // Handle single string input as a user message
    messages = [{ content: request.input, role: 'user' }]
  } else if (Array.isArray(request?.messages)) {
    // Handle array of messages
    messages = request.messages.filter(msg => msg?.content && msg?.role)
  } else {
    shim.logger.warn('No valid messages found in OpenAI request object.')
  }

  return messages
}
Parses all messages from the OpenAI request object.

@param {object} request The OpenAI SDK request object
@param {Shim} shim instance of shim
@returns {Array<object>} an array of message objects with fields `content` and `role`