CSE.

COMMON SENSE ENGINEERING

Insights

  • PDF Chatbot

    I have been trying to find a way to use ChatGPT to “chat” with a local collection of documents, ideally PDFs, TXTs and potentially other formats. It turns out there are a lot of YouTube videos on the topic…and a bunch of approaches, but it seems to basically come down to:

    • Read the documents
    • Convert them into “chunks” of text that can be ingested into GPT
    • Convert these chunks into “embeddings”
    • Add the “embeddings” to a Vector Data Store
    • Ask a question
      • Query the Vector Data Store for a semantic match
      • Send that match to the LLM
    • Present the answer to the user
    • Potentially, add the question/answer pair to a buffer/memory to use in an ongoing conversation.

    In a video by Alejandro Ao, he provided this miro.com illustration of the process:

    Alejandro credits the origin of the diagram to Benny Cheung here.

    Here are the three videos that form the basis of my early research:

    Alejandro Ao
    TechLead
    Liam Ottley

    And their code repositories:

    The three developers each take a similar approach, but their details are different. All three leverage LangChain functions. They generally use OpenAI for the Large Language Model (LLM). They use a number of options for the Vector Data Store:

    • Pinecone
    • FAISS
    • ChromaBD
    • DuckDB ( I see this mentioned but I am not certain it is a Vector Data Store)

    The LLM is needed to answer the questions, but also to create the “embeddings” from the document chunks. This incurs a fee from OpenAI if you use their APIs (but the cost is honestly pretty low). You can use alternatives. Alejandro mentions using “instructor-xl” (intro) as it currently ranks higher than OpenAI (text-embedding-ada-002) on the Massive Text Embedding Benchmark leaderboard.

    My changes

    Some of the things I want to modify include

    • Include a persistent vector database – Creating the embeddings is an “expensive” process. After experimentation, I would like to keep the database around so I can query later.
    • Multiple databases – I have several different topics I want to research and want to keep these seperate.
    • Question both the local docs as well as the broader training data available to models like GPT-4
    • Provide a web GUI
    Alejandro’s WebGUI build with StreamLit

    PrivateGPT

    As I have been tweaking with the various “Chat with your PDF” tutorials, I came across Matthew Berman’s video introduction to Iván Martínez’s PrivateGPT. While the idea here is to use local LLMs like GPT4All for a 100% private implementation, it has many of the features I was looking for. With the help of some community member ideas, I was able to tweak it to use OpenAI’s API for embeddings and queries. The bit it is missing (currently) is a WebGUI.

    Another informational video was from Venelin Valkov on using GPT4All on free and local LLMs.

  • MazeVR – Pac-Man distraction

    Tristan heard about my project and pointed me to this Code Bullet video.

  • MazeVR Dev Log – Day 3

    Once I established the Quest template for Unity, I went back to basic Unity development to experiment with building a maze programmatically. The problem with developing for Quest on a Mac is that you can’t leverage the “play” mode in Unity to test/debug your app. (With a Windows PC, when you “play” a VR app, you can use the Unity Dev console while interacting with the HMD and controllers. Not on the Max)

    ChatGPT seems to be well versed in the idea of building mazes. I assume this is because it is a classic exercise with a multitude of examples within its training data. I was able to build a maze out of prefab walls and floor tiles (which I can attempt to make fancier later) and it takes dimensions as inputs as well.

    While Snipes is not really about solving the maze, I still wanted to experiment with things like knowing and visualizing the solution. Again, ChatGPT provided side to solve the maze and help place markers along the path.

    • Maze logic
    • Maze Solver
    • Enemy
      • Movement
      • Shooters
    • Walking through walls
      • CharacterController vs Rigid Body
    • Jumping
      • Reading the “A” button
      • Justin’s Code vs ChapGPT rewrite
      • Toggle the Maze Solver markers

  • Dev Logging

    I wanted to stat a Dev Log for a VR project I am working on but was always frustrated that individual posts in WordPress are presented in reverse chronological order, making is so a “story” appears to run backwards. I asked ChatGPT for some ideas and it suggested:

    1. Using a Plugin: There are plugins like “Post Types Order” and “WP Query Order” that allow you to easily change the order of posts in categories through the WordPress admin interface.
    2. Modify the Theme’s functions.php File: You can also change the order by adding code to your theme’s functions.php file.
    3. Create a Category Template: If you want to change the order only for specific categories, you can create a category template. Create a file called category-your_category_slug.php in your theme’s directory and use a custom query to display posts in chronological order.

    Initially, I thought the idea of a plugin was easier than trying to hack the functions.php file, but each of the plugins I looked at (briefly) seemed to offer “drag & drop” resorting, but I just wanted to change the sort order by date. (I may regret this as I now realize if I update a post, I need to remember to maintain the old date to keep the order)

    Just for the record, the one plugin I tried was “Post Types Order” and to be fair, I played with it for all of 5 minutes.

    While trying to find a code syntax highlighter, I stumbled across “Code Snippets”, a plugin that allows you to effectively update the functions.php from the admin panel. With this, I added the code snippet that ChatGPT provided with option 2:

    function chronologically_ordered_category( $query ) {
        if ( $query->is_category() && $query->is_main_query() ) {
            $query->set( 'orderby', 'date' );
            $query->set( 'order', 'ASC' );
        }
    }
    add_action( 'pre_get_posts', 'chronologically_ordered_category' );
    

    With this, when my Categories are viewed, they are in the desired chronological order.

  • MazeVR Dev Log – Day 2

    My first step in building this app was to reacquaint myself with building apps for the Oculus Quest 2 using Unity. I had experimented build some VR apps, most notably a recreation of my 1990’s tribute to Asteroids known as SpaceRocks. As this work was done back in December of 2021, I needed a lot of refeshing.

    Much of my “education” came from two prolific YouTubers:

    One of challenges of experimenting with VR development on Unity is the amount of “setting up” you need to accomplish to start off each new project. While i guess you can do the set up and save a copy to use later as a starting point, I was hoping for a better way. In one of Justin’s videos, he mentioned that you can make a custom “template” which can be used as a starting point.

    When you create a Unity project and start using it, they get big (huge) very quickly. Most of these are “library” files that can be recreated during a build. In fact, if you are using GitHub, the vast majority of files can be ignored. Here is a .gitinore file that can be used to minimize the number of files that need to be synced (thanks to GitHub and ChatGPT)

    # This .gitignore file should be placed at the root of your Unity project directory
    #
    # Get latest from https://github.com/github/gitignore/blob/main/Unity.gitignore
    #
    /[Ll]ibrary/
    /[Tt]emp/
    /[Oo]bj/
    /[Bb]uild/
    /[Bb]uilds/
    /[Ll]ogs/
    /[Uu]ser[Ss]ettings/
    
    # MemoryCaptures can get excessive in size.
    # They also could contain extremely sensitive data
    /[Mm]emoryCaptures/
    
    # Recordings can get excessive in size
    /[Rr]ecordings/
    
    # Uncomment this line if you wish to ignore the asset store tools plugin
    # /[Aa]ssets/AssetStoreTools*
    
    # Autogenerated Jetbrains Rider plugin
    /[Aa]ssets/Plugins/Editor/JetBrains*
    
    # Visual Studio cache directory
    .vs/
    
    # Gradle cache directory
    .gradle/
    
    # Autogenerated VS/MD/Consulo solution and project files
    ExportedObj/
    .consulo/
    *.csproj
    *.unityproj
    *.sln
    *.suo
    *.tmp
    *.user
    *.userprefs
    *.pidb
    *.booproj
    *.svd
    *.pdb
    *.mdb
    *.opendb
    *.VC.db
    
    # Unity3D generated meta files
    *.pidb.meta
    *.pdb.meta
    *.mdb.meta
    
    # Unity3D generated file on crash reports
    sysinfo.txt
    
    # Builds
    *.apk
    *.aab
    *.unitypackage
    *.app
    
    # Crashlytics generated file
    crashlytics-build.properties
    
    # Packed Addressables
    /[Aa]ssets/[Aa]ddressable[Aa]ssets[Dd]ata/*/*.bin*
    
    # Temporary auto-generated Android Assets
    /[Aa]ssets/[Ss]treamingAssets/aa.meta
    /[Aa]ssets/[Ss]treamingAssets/aa/*

    Building a Template

    To build the template, I started with Justin’s “How to make VR Games 2022”

    Key elements include:

    • Install XR Interaction Toolkit
    • XR Plugin Management
    • Install the XR Interaction defaults (Samples)
    • Set up a basic scene
    • Enable the Locomotion systems

    From here, I wanted to build an actual template. ChatGPT said this is not a formally supported process, but Google found these sites:

    I built a template (here) and it worked (at least on my Mac)

    The file get placed here:

    • MacOS: /Applications/Unity/Hub/Editor/2021.3.15f1/Unity.app/Contents/Resources/PackageManager/ProjectTemplates
    • PC: Unity\Hub\Editor\2021.1.7f1\Editor\Data\Resources\PackageManager\ProjectTemplates
    • MazeVR Dev Log – Day 1

      Back in 1982, my college roommate (Skull) had been awarded the Darin Scholarship at RPI. As part of the scholarship, he was given a state of the art IBM PC. While I am sure there was considerable scholarly work done on that PC, a great amount of time was spent playing the game “Snipes”.

      The description on the “MyAbandonware” site is very accurate:

      Imagine yourself a big maze. You’re alone, completely alone. The only thing you now is that you must conquer the maze by killing all your enemies, the snipes. And not only the snipes, but also their hives. Strategy, fast thinking and sharp reflexes are the key to victory. The only key.

      The game is, as mentioned earlier, pretty simple. You control your creature with the arrow keys and shoot with A, W, D and S in the appropriate directions. And when you panic, press the spacebar for some extra velocity. How much easier can it get? But not only simplicity is an important aspect of a game. Replayability is another great thing.

      In Snipes this is achieved by letting the computer generate a new maze every time. You specify the amount of snipes, hives and difficulty before you start and of you go. Because you can configure everything there are a total of 26×9 difficulty levels. Ranging from A1 (easy, nothing special, 3 hives, a maximum of 10 snipes and five lives) to Z9 (hard, reflecting bullets, electric walls, ghosts, 10 hives, a maximum of 150 snipes and two lives). What more do you want?

      While I loved Snipes on the PC, I wondered if it would translate to the world of VR. I like the idea a programmatically build maze that can add to replayability. And it clearly would not need much in the way of graphic arts.

      And while I don’t think I will be able to make much use of David Ellsworth‘s reverse engineered code on Github (referenced in the Wikipedia article), it may help me better understand the “A-Z:1-9” level definitions. Actually, in his blog post he suggests he would map out the levels.

      I hope to document my journey building (or at least experimenting) with this in VR.

    • Leveraging AI for side hustles

      With the release of ChatGPT 4 and other technologies like Midjourney 5 (AI image generation), there are a bunch of people out there suggesting you can build a passive income company leveraging this tech.

      This morning I signed up for a paid account with Midjourney and developed the steampunk banner for CSEng.com in 2 minutes. Pretty cool.

      Just this morning as well, someone on Twitter suggested using ChatGPT to be an entrepreneurial guru, gave it a budget and told it to provide a business plan:

      Here is the prompt they provided:

      I started a similar thread and it thinks I should write an ebook on VR or 3D Printing. I need to explain that I think those markets are pretty saturated and not particularly “evergreen”. I also started a discussion using it to build a territory plan for my efforts at Tricentis.

      And I started watching a bunch of videos from a guy names Alex Sheffy discussing his ideas for passive business ideas on Etsy, like this:

      Some of Alex’s favorite tools include:

      • ChatGPT
      • Etsy.com
      • Figma – graphics/prototyping
      • Photopea – free photoshop
      • Midjourney – AI powered image generator