Skip to content

Commit

Permalink
Fix bugs in chat-with-pdf doc and code
Browse files Browse the repository at this point in the history
  • Loading branch information
ttthree committed Sep 15, 2023
1 parent 51dc151 commit d3f8238
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 16 deletions.
4 changes: 2 additions & 2 deletions examples/flows/chat/chat-with-pdf/chat_with_pdf/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ def print_stream_and_return_full_answer(stream):


def main_loop(url: str):
load_dotenv(os.path.join(os.path.dirname(__file__), ".env"))
load_dotenv(os.path.join(os.path.dirname(__file__), ".env"), override=True)

history = []
while True:
Expand All @@ -64,4 +64,4 @@ def main():


if __name__ == "__main__":
main_loop("https://arxiv.org/pdf/1810.04805.pdf")
main()
43 changes: 29 additions & 14 deletions examples/tutorials/e2e-development/chat-with-pdf.md
Original file line number Diff line number Diff line change
Expand Up @@ -61,24 +61,27 @@ You would typically expect the chatbot to be intelligent enough to decipher that

A "rewrite_question" step is performed before feeding the question to "find_context" step.

### Take a look at the chatbot in action!
You should be able to run the console app by:
```shell
python chat_with_pdf/main.py https://arxiv.org/pdf/1810.04805.pdf
```
> Note: https://arxiv.org/pdf/1810.04805.pdf is the paper about one of the most famous earlier LLMs: BERT.
It looks like below if everything goes fine:
![chatbot console](../../flows/chat/chat-with-pdf/assets/chatbot_console.gif)

Now, let's delve into the actual code that implements the chatbot.

### Configurations
Despite being a minimalistic LLM application, there are several aspects we may want to adjust or experiment with in the future. We'll store these in environment variables for ease of access and modification. In the subsequent sections, we'll guide you on how to experiment with these configurations to enhance your chat application's quality.

Create a .env file in this directory and populate it with the following content. We can use the load_dotenv() function to import these into our environment variables later on. We'll delve into what these variables represent when discussing how each step of the process is implemented.
Create a .env file in the chat_with_pdf directory (same directory with the main.py) and populate it with the following content. We can use the load_dotenv() function to import these into our environment variables later on. We'll delve into what these variables represent when discussing how each step of the process is implemented.

Rename the .env.example file in chat-with-pdf directory and modify per your need.

> If you're using Open AI, your .env should look like:
```ini
OPENAI_API_KEY=<open_ai_key>
EMBEDDING_MODEL_DEPLOYMENT_NAME=text-embedding-ada-002
CHAT_MODEL_DEPLOYMENT_NAME=gpt-3.5-turbo
PROMPT_TOKEN_LIMIT=3000
MAX_COMPLETION_TOKENS=256
CHUNK_SIZE=1024
CHUNK_OVERLAP=64
VERBOSE=False
```
Note: if you have an org id, it can be set via OPENAI_ORG_ID=<your_org_id>

Check out [example env file](.env.example).
> If you're using Azure Open AI, you .env should look like:
```ini
OPENAI_API_TYPE=azure
OPENAI_API_BASE=<AOAI_endpoint>
Expand All @@ -94,6 +97,18 @@ VERBOSE=False
```
Note: CHAT_MODEL_DEPLOYMENT_NAME should point to a chat model like gpt-3.5-turbo or gpt-4

### Take a look at the chatbot in action!
You should be able to run the console app by:
```shell
python chat_with_pdf/main.py https://arxiv.org/pdf/1810.04805.pdf
```
> Note: https://arxiv.org/pdf/1810.04805.pdf is the paper about one of the most famous earlier LLMs: BERT.
It looks like below if everything goes fine:
![chatbot console](../../flows/chat/chat-with-pdf/assets/chatbot_console.gif)

Now, let's delve into the actual code that implements the chatbot.

### Implementation of each steps
#### Download pdf: [download.py](../../flows/chat/chat-with-pdf/chat_with_pdf/download.py)
The downloaded PDF file will be stored into a temp folder.
Expand Down

0 comments on commit d3f8238

Please sign in to comment.