当我尝试在Llamaindex 0.6.5的git中运行示例代码时遇到了错误。如何正确导入“load_index_from_storage”?还是有别的选择
语言:python。IDE:VScode.
from llama_index import GPTVectorStoreIndex,
SimpleDirectoryReader, load_index_from_storage, StorageContext
from IPython.display import Markdown, display
import openai
import os
import sys
os.environ['OPENAI_API_KEY']= "sk-***"
documents = SimpleDirectoryReader('data').load_data()
index = GPTVectorStoreIndex.from_documents(documents)
# save index to disk
index.set_index_id("vector_index")
index.storage_context.persist('storage')
# rebuild storage context
storage_context =
StorageContext.from_defaults(persist_dir='storage')
# load index
index = load_index_from_storage(storage_context,
index_id="vector_index")
# set Logging to DEBUG for more detailed outputs
query_engine = index.as_query_engine()
response = query_engine.query("What did the author do growing up?")
print(response)
1条答案
按热度按时间hjzp0vay1#
这是根据llama_index文档更新的代码,用于问答。
以上代码适用于
llama_index==0.6.1