code: def _convert_text_completion_chunks_to_chat(
      chunks: Iterator[llama_types.CreateCompletionStreamResponse],
  ) -> Iterator[llama_types.ChatCompletionChunk]:
      for i, chunk in enumerate(chunks):
          if i == 0:
              yield {
                  "id": "chat" + chunk["id"],
                  "model": chunk["model"],
                  "created": chunk["created"],
                  "object": "chat.completion.chunk",
                  "choices": [
                      {
                          "index": 0,
                          "delta": {
                              "role": "assistant",
                          },
                          "finish_reason": None,
                      }
                  ],
              }
          yield {
              "id": "chat" + chunk["id"],
              "model": chunk["model"],
              "created": chunk["created"],
              "object": "chat.completion.chunk",
              "choices": [
                  {
                      "index": 0,
                      "delta": {
                          "content": chunk["choices"][0]["text"],
                      }
                      if chunk["choices"][0]["finish_reason"] is None
                      else {},
                      "finish_reason": chunk["choices"][0][
                          "finish_reason"
                      ],
                  }
              ],
          }
  
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 13 for calling a global function with example usage: _convert_text_completion_chunks_to_chat(chunks) without return types