LlamaIndex默认会调用OpenAI的text-davinci-002模型对应的API,用于获得大模型输出,这种方式在很多情况下对国内用户不太方便,如果本地有大模型可以部署,可以按照以下方式在LlamaIndex中使用本地的LLM和Embedding(这里LLM使用chatglm2-6b,Embedding使用m3e-base):
import torch
from transformers import AutoModel, AutoTokenizer
from llama_index.llms import HuggingFaceLLM
from llama_index import VectorStoreIndex, ServiceContext
from llama_index import LangchainEmbedding, ServiceContext
from langchain.embeddings.huggingface import HuggingFaceEmbeddings
from llama_index import VectorStoreIndex, SimpleDirectoryReader
from llama_index import Prompt,