i have problem with compatibility between Langchain and Gradio or gpt_index. I'm trying to create ChatBot with OpenAI model learned by my own documents.
Langchain version = 0.0.148. With this version is working gpt_index with this code:
from gpt_index import SimpleDirectoryReader, GPTListIndex, GPTSimpleVectorIndex, LLMPredictor, PromptHelper
from langchain import OpenAI
#import gradio as gr
import sys
import os
os.environ["OPENAI_API_KEY"] = 'XXXX'
def construct_index(directory_path):
max_input_size = 4096
num_outputs = 512
max_chunk_overlap = 20
chunk_size_limit = 600
prompt_helper = PromptHelper(max_input_size, num_outputs, max_chunk_overlap, chunk_size_limit=chunk_size_limit)
llm_predictor = LLMPredictor(llm=OpenAI(temperature=0.7, model_name="text-davinci-003", 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="My AI Chatbot")
#
index = construct_index("Doc")
#iface.launch(share=True)
But i can't install gradio, i have this message:langchain 0.0.148 requires pydantic<2,>=1, but you have pydantic 2.5.3 which is incompatible.
Can you help me? Thanks
I tried install langchain version 0.0.353. With this version i can install gradio, but gpt_index doesn't work