function getMessageFromResponse(response) {
  let content
  let role
  if (response?.object === 'response') {
    content = response?.output?.[0]?.content?.[0]?.text
    role = response?.output?.[0]?.role
  } else {
    content = response?.choices?.[0]?.message?.content
    role = response?.choices?.[0]?.message?.role
  }

  return { content, role }
}
Parses the response from OpenAI and extracts the message content and role.

@param {object} response The OpenAI SDK response object
@returns {{ content: string, role: string }} the message object with fields `content` and `role`