Hi, I’ve created a chatbot with a custom knowledge base by following the instructions on this page: How to Train an AI Chatbot With Custom Knowledge Base Using ChatGPT API | Beebom. However, I’m experiencing an issue where the output is always partial and seems to cut off after a certain length, and I’m not sure what condition is causing it. I have attached an image to show an example of this, along with the code.
from gpt_index import SimpleDirectoryReader, GPTListIndex, GPTSimpleVectorIndex, LLMPredictor, PromptHelper
from langchain.chat_models import ChatOpenAI
import gradio as gr
import sys
import os
os.environ["OPENAI_API_KEY"] = '________'
def construct_index(directory_path):
max_input_size = 4096
num_outputs = 2000
max_chunk_overlap = 20
chunk_size_limit = 1024
max_length = 5000
prompt_helper = PromptHelper(max_input_size, num_outputs, max_chunk_overlap, chunk_size_limit=chunk_size_limit)
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 = GPTSimpleVectorIndex(documents, llm_predictor=llm_predictor, prompt_helper=prompt_helper)
index.save_to_disk('index.json')
return index
def chatbot(input_text):
index = GPTSimpleVectorIndex.load_from_disk('index.json')
response = index.query(input_text, response_mode="compact")
return response.response
iface = gr.Interface(fn=chatbot,
inputs=gr.inputs.Textbox(lines=7, label="Enter your text"),
outputs="text",
title="Custom-trained AI Chatbot")
index = construct_index("docs")
iface.launch(share=True)
Does anyone know how to fix this problem of partial output? Thank you very much!