run-llama / llama_index

LlamaIndex is a data framework for your LLM applications
https://docs.llamaindex.ai
MIT License
36.75k stars 5.27k forks source link

error TypeError: __init__() got an unexpected keyword argument 'llm_predictor' at GPTSimpleVectorIndex #955

Closed ainteligencia closed 1 year ago

ainteligencia commented 1 year ago

for the following error TypeError: init() got an unexpected keyword argument 'llm_predictor'

the code executed is functional

from llama_index import GPTSimpleVectorIndex, PromptHelper,LLMPredictor from langchain import OpenAI llm_predictor = LLMPredictor(llm=OpenAI(temperature=0.1, model_name="text-davinci-002")) max_input_size = 4096 num_output = 256 max_chunk_overlap = 20 prompt_helper = PromptHelper(max_input_size, num_output, max_chunk_overlap)

custom_LLM_index = GPTSimpleVectorIndex( documents, llm_predictor=llm_predictor, prompt_helper=prompt_helper

barabum0 commented 1 year ago

Changing

index = GPTSimpleVectorIndex(documents, llm_predictor=llm_predictor, prompt_helper=prompt_helper)

To

service_context = ServiceContext.from_defaults(llm_predictor=llm_predictor, prompt_helper=prompt_helper)
index = GPTSimpleVectorIndex.from_documents(documents, service_context=service_context)

And importing

from llama_index import ServiceContext

Helped!

Disiok commented 1 year ago

Thanks @barabum0 for the help! We made some breaking API changes in 0.5.0, will make sure docs are clear about this!

kongweigen commented 1 year ago

多谢,已解决