code: import torch
  from langchain.llms.base import LLM
  from llama_index import SimpleDirectoryReader, LangchainEmbedding, GPTListIndex, PromptHelper
  from llama_index import LLMPredictor, ServiceContext
  from transformers import pipeline
  from typing import Optional, List, Mapping, Any
  
  """
  使用自定义 LLM 模型，您只需要实现Langchain 中的LLM类。您将负责将文本传递给模型并返回新生成的标记。
  facebook/opt-iml-max-30b
  https://huggingface.co/facebook/opt-iml-max-30b/tree/main
  """
  
  
  
  # define prompt helper
  # set maximum input size
  max_input_size = 2048
  # set number of output tokens
  num_output = 256
  # set maximum chunk overlap
  max_chunk_overlap = 20
  prompt_helper = PromptHelper(max_input_size, num_output, max_chunk_overlap)
  
  
  class CustomLLM(LLM):
      model_name = "facebook/opt-iml-max-30b"
      pipeline = pipeline("text-generation", model=model_name, device="cuda:0", model_kwargs={"torch_dtype":torch.bfloat16})
  
      def _call(self, prompt: str, stop: Optional[List[str]] = None) -> str:
          prompt_length = len(prompt)
          response = self.pipeline(prompt, max_new_tokens=num_output)[0]["generated_text"]
  
          # only return newly generated tokens
          return response[prompt_length:]
  
      @property
      def _identifying_params(self) -> Mapping[str, Any]:
          return {"name_of_model": self.model_name}
  
      @property
      def _llm_type(self) -> str:
          return "custom"
  
  # define our LLM
  llm_predictor = LLMPredictor(llm=CustomLLM())
  
  service_context = ServiceContext.from_defaults(llm_predictor=llm_predictor, prompt_helper=prompt_helper)
  
  # Load the your data
  documents = SimpleDirectoryReader('./data').load_data()
  index = GPTListIndex.from_documents(documents, service_context=service_context)
  
  # Query and print response
  query_engine = index.as_query_engine()
  response = query_engine.query("<query_text>")
  print(response)
apis: llama_index.PromptHelper llama_index.ServiceContext.from_defaults llama_index.GPTListIndex.from_documents llama_index.SimpleDirectoryReader
extract_api: [((616, 675), 'llama_index.PromptHelper', 'PromptHelper', (['max_input_size', 'num_output', 'max_chunk_overlap'], {}), '(max_input_size, num_output, max_chunk_overlap)\n', (628, 675), False, 'from llama_index import SimpleDirectoryReader, LangchainEmbedding, GPTListIndex, PromptHelper\n'), ((1429, 1520), 'llama_index.ServiceContext.from_defaults', 'ServiceContext.from_defaults', ([], {'llm_predictor': 'llm_predictor', 'prompt_helper': 'prompt_helper'}), '(llm_predictor=llm_predictor, prompt_helper=\n    prompt_helper)\n', (1457, 1520), False, 'from llama_index import LLMPredictor, ServiceContext\n'), ((1602, 1673), 'llama_index.GPTListIndex.from_documents', 'GPTListIndex.from_documents', (['documents'], {'service_context': 'service_context'}), '(documents, service_context=service_context)\n', (1629, 1673), False, 'from llama_index import SimpleDirectoryReader, LangchainEmbedding, GPTListIndex, PromptHelper\n'), ((759, 872), 'transformers.pipeline', 'pipeline', (['"""text-generation"""'], {'model': 'model_name', 'device': '"""cuda:0"""', 'model_kwargs': "{'torch_dtype': torch.bfloat16}"}), "('text-generation', model=model_name, device='cuda:0', model_kwargs\n    ={'torch_dtype': torch.bfloat16})\n", (767, 872), False, 'from transformers import pipeline\n'), ((1550, 1581), 'llama_index.SimpleDirectoryReader', 'SimpleDirectoryReader', (['"""./data"""'], {}), "('./data')\n", (1571, 1581), False, 'from llama_index import SimpleDirectoryReader, LangchainEmbedding, GPTListIndex, PromptHelper\n')]