code: def _chunk_sources(
      sources, chunk=True, chunk_size=512, language=None, db_type=None
  ):
      assert db_type is not None
  
      if not isinstance(
          sources, (list, tuple, types.GeneratorType)
      ) and not callable(sources):
          # if just one document
          sources = [sources]
      if not chunk:
          [
              x.metadata.update(dict(chunk_id=0))
              for chunk_id, x in enumerate(sources)
          ]
          if db_type in ["chroma", "chroma_old"]:
              # make copy so can have separate summarize case
              source_chunks = [
                  Document(
                      page_content=x.page_content,
                      metadata=copy.deepcopy(x.metadata) or {},
                  )
                  for x in sources
              ]
          else:
              source_chunks = sources  # just same thing
      else:
          if language and False:
              # Bug in langchain, keep separator=True not working
              # https://github.com/hwchase17/langchain/issues/2836
              # so avoid this for now
              keep_separator = True
              separators = RecursiveCharacterTextSplitter.get_separators_for_language(
                  language
              )
          else:
              separators = ["\n\n", "\n", " ", ""]
              keep_separator = False
          splitter = RecursiveCharacterTextSplitter(
              chunk_size=chunk_size,
              chunk_overlap=0,
              keep_separator=keep_separator,
              separators=separators,
          )
          source_chunks = splitter.split_documents(sources)
  
          # currently in order, but when pull from db won't be, so mark order and document by hash
          [
              x.metadata.update(dict(chunk_id=chunk_id))
              for chunk_id, x in enumerate(source_chunks)
          ]
  
      if db_type in ["chroma", "chroma_old"]:
          # also keep original source for summarization and other tasks
  
          # assign chunk_id=-1 for original content
          # this assumes, as is currently true, that splitter makes new documents and list and metadata is deepcopy
          [
              x.metadata.update(dict(chunk_id=-1))
              for chunk_id, x in enumerate(sources)
          ]
  
          # in some cases sources is generator, so convert to list
          return list(sources) + source_chunks
      else:
          return source_chunks
  
imports: import copy
  import os
  import types
  import uuid
  from typing import Any, Dict, List, Union, Optional, Tuple, Mapping
  import time
  import queue
  import pathlib
  from datetime import datetime
  from langchain.schema import BasePromptTemplate
  from langchain.chains import LLMChain
  from langchain.chains import MapReduceDocumentsChain, StuffDocumentsChain, ReduceDocumentsChain
  from langchain.chains.combine_documents.base import BaseCombineDocumentsChain
  from langchain.chains.summarize import map_reduce_prompt, LoadingCallable, _load_stuff_chain, _load_map_reduce_chain, _load_refine_chain
  from langchain.schema.language_model import BaseLanguageModel
  from src.utils import hash_file, get_sha
  from langchain.callbacks.base import BaseCallbackHandler, Callbacks
  from langchain.schema import LLMResult
  from langchain.text_splitter import RecursiveCharacterTextSplitter
  from langchain.docstore.document import Document
  import logging
  from typing import Any, Dict, Optional
  from langchain_core.pydantic_v1 import BaseModel, root_validator
label_desc: Use image node_id 1 for calling a global function with example usage: _chunk_sources(sources, chunk, chunk_size, language, db_type) and returns: unknown, source_chunks