Last active
June 6, 2023 15:46
-
-
Save ashhadulislam/837626b460b4b5bf24bda41483be29eb to your computer and use it in GitHub Desktop.
This file contains hidden or 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 llama_index import SimpleDirectoryReader | |
from llama_index import GPTListIndex | |
from llama_index import GPTVectorStoreIndex | |
from llama_index import LLMPredictor, PromptHelper | |
from llama_index import ServiceContext, load_graph_from_storage | |
from llama_index import StorageContext, load_index_from_storage | |
from langchain import OpenAI | |
import gradio as gr | |
import sys | |
import os | |
os.environ["OPENAI_API_KEY"] = 'Your Open AI key' | |
# data/pdfs has all the pdf files you want to train your chatbot on | |
documents = SimpleDirectoryReader('data/pdfs').load_data() | |
index = GPTVectorStoreIndex.from_documents(documents) | |
llm_predictor = LLMPredictor(llm=OpenAI(temperature=0, model_name="text-davinci-003")) | |
from llama_index import GPTVectorStoreIndex | |
max_input_size = 4096 | |
num_output = 256 | |
max_chunk_overlap = 0.7 # now takes a value between 0 and 1, before, ints | |
prompt_helper = PromptHelper(max_input_size, num_output, max_chunk_overlap) | |
service_context = ServiceContext.from_defaults(llm_predictor=llm_predictor, prompt_helper=prompt_helper) | |
index = GPTVectorStoreIndex.from_documents( | |
documents, service_context=service_context | |
) | |
# save index | |
index.storage_context.persist("indices/ch1") | |
# rebuild storage context | |
storage_context = StorageContext.from_defaults(persist_dir='./indices/ch1') | |
# load index | |
index = load_index_from_storage(storage_context) | |
query_engine = index.as_query_engine() | |
response = query_engine.query("What are the prohibitions in currency dealing?") | |
# replace above with your question | |
print(response) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment