Find answers from the community

Updated 2 months ago

from_documents

ValueError: The constructor now takes in a list of Node objects. Since you are passing in a list of Document objects, please use from_documents instead.
Attachment
Screenshot_2023-06-16_215747.jpg
L
o
6 comments
This code is quite outdated actually πŸ˜…

You should use GPTVectorStoreIndex.from_documents(documents, service_context=service_context) instead

The service context holds all LLM and prompt helper settings

There's so no save_to_disk function anymore, it's index.storage_context.persist(persist_dir="./storage")

Definitely read the latest versions of the docs πŸ™πŸ’ͺ
https://gpt-index.readthedocs.io/en/latest/guides/primer/usage_pattern.html
from llama_index import SimpleDirectoryReader, GPTListIndex, GPTVectorStoreIndex, LLMPredictor, ServiceContext
from langchain.chat_models import ChatOpenAI
import gradio as gr
import sys
import os

os.environ["OPENAI_API_KEY"] = 'xxx'


def construct_index(directory_path):
max_input_size = 4096
num_outputs = 512
max_chunk_overlap = 0.08
chunk_size_limit = 600



llm_predictor = LLMPredictor(llm=ChatOpenAI(
temperature=0.7, model_name="gpt-3.5-turbo", max_tokens=num_outputs))

documents = SimpleDirectoryReader(directory_path).load_data()

index = GPTVectorStoreIndex.from_documents(documents,ServiceContext=ServiceContext)

index.storage_context.persist(persist_dir="./storage")

return index


def chatbot(input_text):
index = GPTVectorStoreIndex.from_documents(documents)
response = index.query(input_text, response_mode="compact")
return response.response


iface = gr.Interface(fn=chatbot,
inputs=gr.components.Textbox(
lines=7, label="Ask me anything about On-Dock Depot"),
outputs="text",
title="AI Chatbot trained On-Dock Depot processes")

index = construct_index("docs")
iface.launch(share=True)


def greet(name):
return "Hello " + name + "!!"


iface = gr.Interface(fn=greet, inputs="text", outputs="text")
iface.launch()
got this error
Attachment
image.png
Hmm weird. Maybe also try setting the os.environ key in the construct_index function as well?
but also unrelated, your code still has some minor error

Plain Text
def construct_index(directory_path):
    max_input_size = 4096
    num_outputs = 512
    max_chunk_overlap = 0.08
    chunk_size_limit = 600

    prompt_helper = PromptHelper(...)

    llm_predictor = LLMPredictor(llm=ChatOpenAI(
        temperature=0.7, model_name="gpt-3.5-turbo", max_tokens=num_outputs))

    documents = SimpleDirectoryReader(directory_path).load_data()
    
    service_context = ServiceContext.from_defaults(llm_predictor=llm_predictor, chunk_size=chunk_size_limit, prompt_helper=prompt_helper)

    index = GPTVectorStoreIndex.from_documents(documents, service_context=service_context)

    index.storage_context.persist(persist_dir="./storage")

    return index


def chatbot(input_text):
    index = load_index_from_storage(StorageContext.from_defaults(persist_dir="./storage"))
    response = index.as_query_engine(response_mode="compact").query(input_text)
    return response.response
I got it work thanks !
Add a reply
Sign up and join the conversation on Discord