Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 18 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,23 +9,37 @@
```python
conda install onnxruntime -c conda-forge
```
See this [thread](https://github.com/microsoft/onnxruntime/issues/11037) for additonal help if needed.
See this [thread](https://github.com/microsoft/onnxruntime/issues/11037) for additional help if needed.

- For Windows users, follow the guide [here](https://github.com/bycloudai/InstallVSBuildToolsWindows?tab=readme-ov-file) to install the Microsoft C++ Build Tools. Be sure to follow through to the last step to set the enviroment variable path.
- For Windows users, follow the guide [here](https://github.com/bycloudai/InstallVSBuildToolsWindows?tab=readme-ov-file) to install the Microsoft C++ Build Tools. Be sure to follow through to the last step to set the environment variable path.


2. Now run this command to install dependenies in the `requirements.txt` file.
2. Now run this command to install dependencies in the `requirements.txt` file.

```python
pip install -r requirements.txt
```

3. Install markdown depenendies with:
3. Install markdown dependencies with:

```python
pip install "unstructured[md]"
```

4. Install NLTK tokenizers

```
python -m nltk.downloader tokenizers
```

5. Generate an [OpenAI](https://platform.openai.com/settings) API key and save it to the `.env` file

```
OPENAI_API_KEY=
```

For the API key to function correctly, you will need to put some money on your account. The minimum of 5$ will suffice.

## Create database

Create the Chroma DB.
Expand All @@ -42,6 +56,4 @@ Query the Chroma DB.
python query_data.py "How does Alice meet the Mad Hatter?"
```

> You'll also need to set up an OpenAI account (and set the OpenAI key in your environment variable) for this to work.

Here is a step-by-step tutorial video: [RAG+Langchain Python Project: Easy AI/Chat For Your Docs](https://www.youtube.com/watch?v=tcqEUSNCn8I&ab_channel=pixegami).
14 changes: 12 additions & 2 deletions query_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,16 @@
from langchain_openai import OpenAIEmbeddings
from langchain_openai import ChatOpenAI
from langchain.prompts import ChatPromptTemplate
from dotenv import load_dotenv
import openai
import os

# Load environment variables. Assumes that project contains .env file with API keys
load_dotenv()
#---- Set OpenAI API key
# Change environment variable name from "OPENAI_API_KEY" to the name given in
# your .env file.
openai.api_key = os.environ['OPENAI_API_KEY']

CHROMA_PATH = "chroma"

Expand Down Expand Up @@ -41,10 +51,10 @@ def main():
print(prompt)

model = ChatOpenAI()
response_text = model.predict(prompt)
response_text = model.invoke(prompt)

sources = [doc.metadata.get("source", None) for doc, _score in results]
formatted_response = f"Response: {response_text}\nSources: {sources}"
formatted_response = f"Response: {response_text.content}\nSources: {sources}"
print(formatted_response)


Expand Down