code: from llama_index.core.llms import ChatMessage
  from llama_index.llms.huggingface import HuggingFaceLLM
  from llama_index.core.prompts import PromptTemplate
  from projectgurukul.custom_models import model_utils
  import logging
  
  def get_tinyllama_llm(context_window = 2048, max_new_tokens = 256, system_prompt = ""):
      def messages_to_prompt(messages: ChatMessage):
          messages_dict = [
                      {"role": message.role.value, "content": message.content}
                      for message in messages
                  ]
          prompt =  huggingllm._tokenizer.apply_chat_template(messages_dict, tokenize=False, add_generation_prompt=True)
          logging.debug(prompt)
          return prompt
  
  
      device, dtype = model_utils.get_device_and_dtype()
  
      # This will wrap the default prompts that are internal to llama-index
      query_wrapper_prompt = PromptTemplate(
          f"<|system|>{system_prompt}"+"<|user|>{query_str}<|assistant|>")
  
      huggingllm = HuggingFaceLLM(
          context_window=context_window,
          is_chat_model=True,
          model_name="TinyLlama/TinyLlama-1.1B-Chat-v1.0",
          tokenizer_name="TinyLlama/TinyLlama-1.1B-Chat-v1.0",
          max_new_tokens=max_new_tokens,
          stopping_ids=[2, 50256],
          generate_kwargs={'do_sample': False},
          model_kwargs={"torch_dtype": dtype},
          query_wrapper_prompt=query_wrapper_prompt,
          device_map = device,
          system_prompt=system_prompt
      )
  
      huggingllm.messages_to_prompt = messages_to_prompt
      return huggingllm
  
  
  
  def get_phi2_llm(context_window = 2048, max_new_tokens = 256, system_prompt = ""):
  
      role_maps = {
          "system" :"Instructions",
          "user" :"User Instructions"
      }
      def messages_to_prompt(messages: ChatMessage):
          prompt = ""
          for message in messages:
              role = message.role.value
              role = role_maps[role] if role in role_maps else role
              prompt += f"\n{role}:: {message.content}\n\n"
          prompt += "Response ::"
          logging.debug(prompt)
          return prompt
      device, dtype = model_utils.get_device_and_dtype()
  
      # This will wrap the default prompts that are internal to llama-index
      query_wrapper_prompt = PromptTemplate("Instruct: {query_str}\nOutput: ")
  
      huggingllm = HuggingFaceLLM(
          context_window=context_window,
          is_chat_model=True,
          model_name="microsoft/phi-2",
          tokenizer_name="microsoft/phi-2",
          max_new_tokens=max_new_tokens,
          stopping_ids=[50256],
          generate_kwargs={'do_sample': False},
          model_kwargs={"torch_dtype": dtype, "trust_remote_code" :True},
          query_wrapper_prompt=query_wrapper_prompt,
          messages_to_prompt = messages_to_prompt,
          device_map = device,
          system_prompt=system_prompt
      )
      return huggingllm
apis: llama_index.llms.huggingface.HuggingFaceLLM llama_index.core.prompts.PromptTemplate
extract_api: [((720, 754), 'projectgurukul.custom_models.model_utils.get_device_and_dtype', 'model_utils.get_device_and_dtype', ([], {}), '()\n', (752, 754), False, 'from projectgurukul.custom_models import model_utils\n'), ((857, 942), 'llama_index.core.prompts.PromptTemplate', 'PromptTemplate', (["(f'<|system|>{system_prompt}' + '<|user|>{query_str}<|assistant|>')"], {}), "(f'<|system|>{system_prompt}' +\n    '<|user|>{query_str}<|assistant|>')\n", (871, 942), False, 'from llama_index.core.prompts import PromptTemplate\n'), ((964, 1375), 'llama_index.llms.huggingface.HuggingFaceLLM', 'HuggingFaceLLM', ([], {'context_window': 'context_window', 'is_chat_model': '(True)', 'model_name': '"""TinyLlama/TinyLlama-1.1B-Chat-v1.0"""', 'tokenizer_name': '"""TinyLlama/TinyLlama-1.1B-Chat-v1.0"""', 'max_new_tokens': 'max_new_tokens', 'stopping_ids': '[2, 50256]', 'generate_kwargs': "{'do_sample': False}", 'model_kwargs': "{'torch_dtype': dtype}", 'query_wrapper_prompt': 'query_wrapper_prompt', 'device_map': 'device', 'system_prompt': 'system_prompt'}), "(context_window=context_window, is_chat_model=True,\n    model_name='TinyLlama/TinyLlama-1.1B-Chat-v1.0', tokenizer_name=\n    'TinyLlama/TinyLlama-1.1B-Chat-v1.0', max_new_tokens=max_new_tokens,\n    stopping_ids=[2, 50256], generate_kwargs={'do_sample': False},\n    model_kwargs={'torch_dtype': dtype}, query_wrapper_prompt=\n    query_wrapper_prompt, device_map=device, system_prompt=system_prompt)\n", (978, 1375), False, 'from llama_index.llms.huggingface import HuggingFaceLLM\n'), ((2079, 2113), 'projectgurukul.custom_models.model_utils.get_device_and_dtype', 'model_utils.get_device_and_dtype', ([], {}), '()\n', (2111, 2113), False, 'from projectgurukul.custom_models import model_utils\n'), ((2216, 2268), 'llama_index.core.prompts.PromptTemplate', 'PromptTemplate', (['"""Instruct: {query_str}\nOutput: """'], {}), '("""Instruct: {query_str}\nOutput: """)\n', (2230, 2268), False, 'from llama_index.core.prompts import PromptTemplate\n'), ((2284, 2724), 'llama_index.llms.huggingface.HuggingFaceLLM', 'HuggingFaceLLM', ([], {'context_window': 'context_window', 'is_chat_model': '(True)', 'model_name': '"""microsoft/phi-2"""', 'tokenizer_name': '"""microsoft/phi-2"""', 'max_new_tokens': 'max_new_tokens', 'stopping_ids': '[50256]', 'generate_kwargs': "{'do_sample': False}", 'model_kwargs': "{'torch_dtype': dtype, 'trust_remote_code': True}", 'query_wrapper_prompt': 'query_wrapper_prompt', 'messages_to_prompt': 'messages_to_prompt', 'device_map': 'device', 'system_prompt': 'system_prompt'}), "(context_window=context_window, is_chat_model=True,\n    model_name='microsoft/phi-2', tokenizer_name='microsoft/phi-2',\n    max_new_tokens=max_new_tokens, stopping_ids=[50256], generate_kwargs={\n    'do_sample': False}, model_kwargs={'torch_dtype': dtype,\n    'trust_remote_code': True}, query_wrapper_prompt=query_wrapper_prompt,\n    messages_to_prompt=messages_to_prompt, device_map=device, system_prompt\n    =system_prompt)\n", (2298, 2724), False, 'from llama_index.llms.huggingface import HuggingFaceLLM\n'), ((654, 675), 'logging.debug', 'logging.debug', (['prompt'], {}), '(prompt)\n', (667, 675), False, 'import logging\n'), ((2015, 2036), 'logging.debug', 'logging.debug', (['prompt'], {}), '(prompt)\n', (2028, 2036), False, 'import logging\n')]