Demo of Approximate Retrieval capability of LLMs appplied to build a product for Mindful Exploration of Urban Events.
Project description
What is this?
The project marries Consious Urban Exploration(it is also kind of a productization of being "Here In The Moment" and Travel) and the "new" AI for infra. Its a seed for an idea on how to explore our neighborhoods and being Here in the moment. "Here" can be at home or really anywhere you are in your city, because no matter how you got there its where you are now.
Awareness and being conscious of this moment are two ideas close to my heart(Meditation is key to getting there.). I also love to travel but one can also be a "traveller" within their city(One might say we all travel on the weekend) exploring big places like NYC.
I live in Hoboken, NJ so this is only content from there and intended to present a PoC.
Tech stack
This repo is just the front end(FastAPI, Jinja, Bootstap CSS, Swiper.js). The API and Data pipes that uses AI(OpenAI, Pydantic, OpenRouteService) and generates the data indexed into a DB(in Sqlite!) is here
What it looks like?
(I am about to deploy the docker to the cloud, but here are some screenshots from the local docker container to explain the idea)
Landing Page: Drop a pin within the area(no location permissions requested)
Next: The "Conscious Exploration" bits of :)
Also importantly: The use of modern AI: A pipeline to retrieve structured info from unstructured text and use RAG(embeddings and the like) to enrich and classify the content... So it does not appear like a smorgasbord of information.
The stack that uses AI and generates the DB(in Sqlite!) is here
What this repo contains?
The front end which calls the backend(here and all the opsy stuff to get it onto a cloud(Ongoing).
Stuff specific to building the demo(Opsy)
Docs are a WIP so things may not work in the short term as expected
Building and Distributing the Wheel.
There were a lot of package install errors(Oh debian linux how precise you are) and wrangling with the initial pyproject.toml dependencies that needed rust/c++ etc. Often there were errors and it took a fair bit of time building them from wheels/sdists, so I removed the deps that were not needed to build these packages, cutting down immensely on the size of the final installed binaries. This took a while...
Iteration Loop(code=>build=>deploy
):
- Build the wheel of the
drop_backed
project. Update it in theherenow_demo
. Both of these should be installable via pip.
A thing to note is that
poetry build
's wheels don't exclude any deps from the pyproject.toml as explained here, but we can useextras
in poetry and set the optional=true on them so that later pip does not install them unless we ask.
- Once tested(from local docker), the builds will be tagged. We can copy them from the containers and push to pypi.
- Use a second docker container to install these builds and deploy!
Docker 1(DockerfileBuild): Tests if the wheels can be built and installed using pip:
- Write code, test, once done prune unwanted deps in
drop_backend
.
- Run build.py to copy the code for docker build to find in its context:
python build.py --pot-source=local --demo-source=local --pot-dir=/Users/sid/workspace/drop/ --demo-dir=/Users/sid/workspace/herenow_demo/
This creates a sandbox where the code for both projects is copied and then in that sandbox the script bumps the major/minor/patch version in pyproject.toml in
drop_backend
examplex.y.z
becomes alphax.y.(z+1)-alpha
. This will be useful later.
- run
docker build ...
to build thedrop_backend
project like so:
docker build --target backend-builder \
--build-arg DROP_BACKEND_DIR=drop_PoT \
--build-arg HERENOW_DEMO_DIR=herenow_demo \
-t backend-image -f DockerfileBuild /tmp/subdir
-
2.1. Log into docker:
docker run -p 8000:8000 -it --entrypoint /bin/bash herenow_demo
-
2.2. Fire up the python interpreter and try
import drop_backend
and just look around to see if everything is fine. -
2.3. Succeed? No -> Go back to step 0 and repeat.
- Now run the remaining docker build command:
docker build --target app-builder \
--build-arg DROP_BACKEND_DIR=drop_PoT
--build-arg HERENOW_DEMO_DIR=herenow_demo \
-t app-image -f DockerfileBuild
/tmp/subdir
- 3.1. It runs the configure_demo.py script runs and fills in the name of the built wheel of
drop_backend
in the pyproject.toml of herenow_demo. This is needed because the wheel name is not trivial to know until the wheel is built. - 3.2It will create the wheel of herenow_demo and install it in the docker container.
- Did you scuced No -> Fix the code and error on local host and go to step 3.
- Log into the docker container:
docker run -p 8000:8000 -it --entrypoint /bin/bash herenow_demo
- Try running the adhoc gunicorn command like so for the final test:
gunicorn herenow_demo.main:app --bind 0.0.0.0:8000 --workers 1 \
--worker-class uvicorn.workers.UvicornWorker \
-e SQLITE_DB_PATH='sqlite:////app/drop.db' \
-e RELOAD_WEBAPP=True \
-e SECRET_KEY='supersecret-key' \
-e ORS_API_ENDPOINT='http://127.0.0.1:8080/ors/v2/directions/{profile}' \
-e ALLOWED_ORIGINS='http://127.0.0.1:8000,http://localhost:8000'
- Browse to http://localhost:8000/presence/where
Check in the tags, preprep for docker build
Now use the tag from last step for both the projects.
- The tag for
drop_backend
is likely:
sid@Sids-MacBook-Pro:~/workspace/herenow_demo$ docker run --rm app-image bash -c "cat /backend/pyproject.toml|grep -C2 drop_backend"
[tool.poetry]
name = "drop_backend"
version = "1.0.7-alpha"
description = "API and Command line tools for building drop"
authors = ["Sid <itissid@gmail.com>"]
packages = [{ include = "drop_backend", from = "src" }]
- Add this tag to your local drop_backend's pyproject.toml
version
. Do apoetry update
andpoetry build
to make sure the wheel is built locally. - Now publish publish the wheel to pypi using
poetry publish
.
Use the alpha version of the wheel you just pushed for the next step. Note if you did every thing right the local dist/ should have the same file as one on docker and on pypi:
sid@Sids-MacBook-Pro:~/workspace/herenow_demo$ docker run --rm app-image bash -c "cat pyproject.toml|grep drop_backend"
file = "/backend/dist/drop_backend-1.0.7a0-py3-none-any.whl"
- Now use 1.0.7a0 built above and add this to the pyproject.toml of
herenow_demo
and do apoetry update
andpoetry build
to make sure the wheel is built locally. You can also bump the version ofherenow_demo
itself. - Build
herenow_demo
usingpoetry build
and push the wheel to pypi usingpoetry publish
- Lastly add tags for these versions to git repos of both the projects and push them to github.
Docker 2(DockerfileDeploy): This will be the container that will host the app and the SQLite DB.
- Build the DockerfileDeploy.
docker build \
--build-arg SQLITE_DB_PATH="sqlite:////app/drop.db" \
--build-arg RELOAD_WEBAPP="True" \
--build-arg SECRET_KEY="somthingsupersecret-key" \
--build-arg ORS_API_ENDPOINT="http://127.0.0.1:8080/ors/v2/directions/{profile}" \
--build-arg ALLOWED_ORIGINS="http://127.0.0.1:8000,http://localhost:8000" \
-t herenow_demo_deploy .
- Run the container:
docker run -p 8000:8000 -d herenow_demo_deploy
- Check on the browser one last time!
- Now that both the deps are in the container, push to registry.
Next(Deploy docker to cloud)
TODO
Notes
While building the above i realized that I am actually doing a mini release strategy. Something that github or gitlab can probably help me do, were this to ever become a product.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Hashes for herenow_demo-1.0.0a0-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 96f913832d0d506e50ec850f0ae47a2dc7c0d0492275dec8dce77da0fb2a9b62 |
|
MD5 | c466f83b9594028a0c086f345809b838 |
|
BLAKE2b-256 | e47c7fd83ad0a7f686375354702d7dc09f4744f897dbbd4fdee738e567f596d0 |