Created
July 31, 2023 13:22
-
-
Save pragatibaheti/60ee5008ed5af1c39a95482deb8084b3 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"] = '#unique_id' | |
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=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('pr_chatgpt_v1.json') | |
return index | |
def chatbot(input_text): | |
index = GPTSimpleVectorIndex.load_from_disk('pr_chatgpt_v1.json') | |
response = index.query(input_text, response_mode="compact") | |
return response.response | |
iface = gr.Interface(fn=chatbot, | |
inputs=gr.components.Textbox(lines=7, label="Enter your question to train the model further"), | |
outputs="text", | |
title="Custom-trained Chatbot with domain specific knowledge") | |
index = construct_index("docs") | |
iface.launch(share=True) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment