Skip to content

Commit

Permalink
Clean up files
Browse files Browse the repository at this point in the history
  • Loading branch information
techleadhd committed Jun 25, 2023
1 parent 9101c1f commit e1d7cf3
Show file tree
Hide file tree
Showing 6 changed files with 18 additions and 8 deletions.
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
constants.py
__pycache__
persist/
.DS_Store
.chroma/
11 changes: 9 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,21 @@ Here's the [YouTube Video](https://youtu.be/9AXP7tCI9PI).

Install [Langchain](https://github.com/hwchase17/langchain) and other required packages.
```
pip install langchain openai chromadb tiktoken beautifulsoup4
pip install langchain openai chromadb tiktoken unstructured
```
Modify `constants.py` to use your own [OpenAI API key](https://platform.openai.com/account/api-keys).

Place your own data into `data.txt`.
Place your own data into `data/data.txt`.

## Example usage
Test reading `data/data.txt` file.
```
> python chatgpt.py "what is my dog's name"
Your dog's name is Sunny.
```

Test reading `data/cat.pdf` file.
```
> python chatgpt.py "what is my cat's name"
Your cat's name is Muffy.
```
8 changes: 3 additions & 5 deletions chatgpt.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,27 +7,25 @@
from langchain.document_loaders import DirectoryLoader, TextLoader
from langchain.embeddings import OpenAIEmbeddings
from langchain.indexes import VectorstoreIndexCreator
from langchain.indexes.vectorstore import VectorStoreIndexWrapper
from langchain.llms import OpenAI
from langchain.vectorstores import Chroma

import constants

os.environ["OPENAI_API_KEY"] = constants.APIKEY

# Enable to cache & reuse the model to disk (for repeated queries on the same data)
# Enable to save to disk & reuse the model (for repeated queries on the same data)
PERSIST = False

query = sys.argv[1]

if PERSIST and os.path.exists("persist"):
print("Reusing index...\n")
vectorstore = Chroma(persist_directory="persist", embedding_function=OpenAIEmbeddings())
from langchain.indexes.vectorstore import VectorStoreIndexWrapper
index = VectorStoreIndexWrapper(vectorstore=vectorstore)
else:
loader = TextLoader('data.txt')
# This code can also import folders, including various filetypes like PDFs using the DirectoryLoader.
# loader = DirectoryLoader(".", glob="*.txt")
loader = DirectoryLoader("data/")
if PERSIST:
index = VectorstoreIndexCreator(vectorstore_kwargs={"persist_directory":"persist"}).from_loaders([loader])
else:
Expand Down
2 changes: 1 addition & 1 deletion constants.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
APIKEY = "<your OpenAI API Key>"
APIKEY = "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"
Binary file added data/cat.pdf
Binary file not shown.
File renamed without changes.

0 comments on commit e1d7cf3

Please sign in to comment.