code: def _convert_completion_to_chat(
      completion_or_chunks: Union[
          llama_types.CreateCompletionResponse,
          Iterator[llama_types.CreateCompletionStreamResponse],
      ],
      stream: bool = False,
  ) -> Union[
      llama_types.CreateChatCompletionResponse,
      Iterator[llama_types.ChatCompletionChunk],
  ]:
      if stream:
          chunks: Iterator[llama_types.CreateCompletionStreamResponse] = completion_or_chunks  # type: ignore
          return _convert_text_completion_chunks_to_chat(chunks)
      else:
          completion: llama_types.Completion = completion_or_chunks  # type: ignore
          return _convert_text_completion_to_chat(completion)
  
imports: from __future__ import annotations
  import os
  import json
  import ctypes
  import dataclasses
  from typing import Any, Dict, Iterator, List, Optional, Tuple, Union, Protocol
  import llama_cpp.llama
  import llama_cpp.llama_types
  import llama_cpp.llama_grammar
  from ._utils import suppress_stdout_stderr
label_desc: Use image node_id 14 for calling a global function with example usage: _convert_completion_to_chat(completion_or_chunks, stream) and returns: _convert_text_completion_chunks_to_chat, _convert_text_completion_to_chat