October 31, 2023 - Programming

You can view the source code for this project here.

BACKGROUND

With AI as the current hot topic and seemingly every company throwing this word around, it only makes sense to dive into some of the use-cases. We know that you can use LLM’s to query the internet, but I wanted to find out how to utilize AI to query information about my business or even personal filesystem.

It turns out there are a couple of different ways we could go about this, but the best package at the moment is known as langchain. Essentially langchain does all of the heavy lifting and enables us to create applications that are context-aware, as the developer’s phrase it.

EXECUTION

Creating the application was rather simple and if you take a look at the source code you’ll see it’s less than 50 lines. In addition, more than half of this code is ‘nice-to-have’ and not necessary for the application to run!

Below I’ve posted the startup process in order to utilize on this application yourself.

  • Clone the repository by running git clone https://github.com/delfortrie/langchain_sql.git
  • I recommend setting up a virtual environment for this project ( step 3 & 4 )
  • Run python3 -m venv environment_name in the root directory of the project
  • Activate the virtual environment in Linux or Mac by running source path/to/environment_name/bin/activate
  • Install the project dependencies by running pip install -r path/to/requirements.txt
  • Open the .environment file and add your OpenAI API key to the OPEN_API_KEY variable
  • Rename the .environment file to .env
  • Run the application with streamlit run app.py in the terminal

The reason I suggest running this project in a virtual environment is because there are a handful of packages that are required for this application to run correctly. It’s always best practice to contain a program as much as possible, especially with new packages such as langchain.

Streamlit is a neat little package that we can use to create the entire front-end GUI for us. While it’s not necessarily production-grade, It’s super simple to interact with and it allows us to develop the back-end without having to worry about the ‘look and feel’ – which is perfect for this project!

TROUBLESHOOTING

While building this application within PyCharm I came across an issue with a required package crashing my system. I can’t remember the package off the top of my head but this is why we use a virtual environment!!!

  1. I created a new environment and installed the packages.
  2. System crashed again (recreated issue).
  3. Read the log files to determine which package caused the crash.
  4. Tested another IDE (VS Code) to try and recreate the issue again. VS Code worked well, and so the issue is isolated to PyCharm.
  5. Temp solution was to move the project to VS Code IDE.

If this project was going to be production-grade, then a solution would be necessary to find out WHY the package was causing PyCharm to crash. But in this situation – a personal project – I determined that it was acceptable to port the project over to VS Code (and IDE I am familiar with as well) and continue working on the project there.

0 Comment

Leave a Reply