I am getting the same error every time. I have tried a lot of solutions but i cant get it to work.
I am using the new version of llama_index v=0.6.35 i believe.
I always get the following error:
**
Error: One of nodes or index_struct must be provided.
**
from llama_index.indices.loading import load_index_from_storage
from llama_index import (
GPTVectorStoreIndex,
SimpleDirectoryReader,
LLMPredictor,
ServiceContext,
StorageContext,
VectorStoreIndex,
)
from langchain import OpenAI
import gradio as gr
import os
import openai
import json
os.environ["OPENAI_API_KEY"] = "--APIKEY--"
openai.api_key = "--APIKEY--"
def construct_index(directory_path):
num_outputs = 512
llm_predictor = LLMPredictor(
llm=OpenAI(
temperature=0.7, model_name="text-davinci-003", max_tokens=num_outputs
)
)
service_context = ServiceContext.from_defaults(llm_predictor=llm_predictor)
docs = SimpleDirectoryReader(directory_path).load_data()
index = GPTVectorStoreIndex.from_documents(docs, service_context=service_context)
index.storage_context.persist(persist_dir="index")
return index
def chatbot(input_text):
print(input_text)
storage_context = StorageContext(
vector_store="index/vector_store.json",
index_store="index/index_store.json",
graph_store="index/graph_store.json",
docstore="index/docstore.json",
)
print("I have passed the storage_context")
try:
index = GPTVectorStoreIndex(storage_context=storage_context)
index.load()
print("I have passed the index")
response = index.query(input_text, response_mode="compact")
return response.response
except Exception as e:
print(f"Error: {e}")
return None
iface = gr.Interface(
fn=chatbot,
inputs=gr.inputs.Textbox(lines=7, label="Enter your text"),
outputs=gr.outputs.Textbox(label="Response"),
title="Custom-trained AI Chatbot",
)
index = construct_index("docs")
iface.launch(share=False)
I am not able to resolve this. I have seen a lot of post only talking about it.
This is the first time i am doing a project like this one:
I got the tutorial from this post: https://medium.com/@sohaibshaheen/train-chatgpt-with-custom-data-and-create-your-own-chat-bot-using-macos-fb78c2f9646d
Any help is really appreciated.