diff --git a/examples/flows/chat/chat-with-pdf/.env.example b/examples/flows/chat/chat-with-pdf/chat_with_pdf/.env.example similarity index 100% rename from examples/flows/chat/chat-with-pdf/.env.example rename to examples/flows/chat/chat-with-pdf/chat_with_pdf/.env.example diff --git a/examples/flows/chat/chat-with-pdf/chat_with_pdf/main.py b/examples/flows/chat/chat-with-pdf/chat_with_pdf/main.py index dddbc77e8d9..58bbee1134b 100644 --- a/examples/flows/chat/chat-with-pdf/chat_with_pdf/main.py +++ b/examples/flows/chat/chat-with-pdf/chat_with_pdf/main.py @@ -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: @@ -64,4 +64,4 @@ def main(): if __name__ == "__main__": - main_loop("https://arxiv.org/pdf/1810.04805.pdf") + main() diff --git a/examples/tutorials/e2e-development/chat-with-pdf.md b/examples/tutorials/e2e-development/chat-with-pdf.md index f7e846fbc70..ee65647c929 100644 --- a/examples/tutorials/e2e-development/chat-with-pdf.md +++ b/examples/tutorials/e2e-development/chat-with-pdf.md @@ -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= +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= -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= @@ -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.