code: from llama_index.core.base.llms.types import (
      ChatMessage,
      ChatResponse,
      ChatResponseGen,
      MessageRole,
  )
  from llama_index.core.types import TokenGen
  
  
  def response_gen_from_query_engine(response_gen: TokenGen) -> ChatResponseGen:
      response_str = ""
      for token in response_gen:
          response_str += token
          yield ChatResponse(
              message=ChatMessage(role=MessageRole.ASSISTANT, content=response_str),
              delta=token,
          )
  
apis: llama_index.core.base.llms.types.ChatMessage
extract_api: [((378, 439), 'llama_index.core.base.llms.types.ChatMessage', 'ChatMessage', ([], {'role': 'MessageRole.ASSISTANT', 'content': 'response_str'}), '(role=MessageRole.ASSISTANT, content=response_str)\n', (389, 439), False, 'from llama_index.core.base.llms.types import ChatMessage, ChatResponse, ChatResponseGen, MessageRole\n')]