Note
The public copy of this repository does not include infrastructure code.
Otto is a platform designed to host a wide range of AI tools, data visualizations, and interactive solutions that address various efficiency needs across Justice Canada. Developed by data specialists, Otto streamlines processes, makes delivering valuable solutions easier, and enhances overall productivity for legal professionals.
Born out of the need to tackle data challenges that didn't fit neatly into existing corporate systems, Otto serves as a flexible hosting environment for:
- AI-powered tools for legal research and analysis
- Interactive data visualizations and dashboards
- Specialized data processing and management applications
- Custom-built solutions for specific departmental needs
Key Features and Benefits
Otto is designed to:
- Empower Data Specialists: Host and deploy diverse AI tools, specialized visuals, reports, and data applications.
- Enhance Accessibility: Provide non-technical users with simple, centralized interfaces to interact with complex AI and data tools.
- Promote Agility: Reduce hurdles in delivering solutions to users, enabling rapid implementation of new tools and visualizations.
- Foster Innovation: Encourage the development and implementation of cutting-edge AI and data solutions.
- Build Community: Serve as an open-source platform that encourages collaboration from developers across Justice Canada.
- Adapt Flexibly: Meet the changing needs of the Justice department with scalable capacity to handle varying demand.
- Ensure Security: Protect data and ensure compliance with Justice department standards.
As a platform for AI and data services, Otto helps legal professionals improve the efficiency and accuracy of legal research, analysis, and decision-making. It's an open-source, flexible tool for creating, hosting, and deploying a wide array of data and AI applications within the Justice Canada ecosystem.
- About Otto
- Table of Contents
- Development setup
- Contributing
- Deploy to Azure
- Resetting the database
- License and contact
Requirements:
- Visual Studio Code (VScode) with Dev Containers extension
- WSL
- Docker or Rancher Desktop (with Hyper-V and WSL2 enabled)
- Git for Windows
Note
Note that the installation may take 5-10 minutes (longer if you are connected to VPN).
- Using Git for Windows, clone this repository somewhere in your C:\ drive.
- Start Docker / Rancher Desktop.
- In VScode, "Dev Containers: Open Folder in Container..." and select the directory you cloned this repo to.
- Wait for the containers to build. The first time the containers build, this might take a while.
- Open a terminal in your VScode devcontainer. Run
bash dev_setup.shand follow the instructions. - You can now run the server from the "Run and debug" sidebar in VScode or just run (from ./django)
python manage.py runserverin the VScode terminal. - You will also have to start Celery to process tasks such as file translation or document loading. Run (from ./django)
celery -A otto worker -l INFO --pool=gevent --concurrency=16 -Q light,embed,heavyor run theDjango: Server + Celerydebug configuration in VSCode. Note that Celery requires a manual restart when files have changed. - Go to http://localhost:8000 and login to Otto using your Justice account.
After the initial setup, you will rarely have to build the dev containers again. You can just:
- Start Docker Desktop.
- Open VScode, and if the devcontainer is not already opened, run "Dev Containers: Open Folder in Container..."
- Start the Django server & Celery worker.
Requirements:
- Visual Studio Code (VScode) with Dev Containers extension
- WSL
This assumes some knowledge of Linux / ability to troubleshoot. Not every step is explained in full detail.
- Create or edit the file in your Windows user directory
.wslconfig. The first two lines are essential when using Justice laptops. The other lines should be modified based on your system specifications.
[wsl2]
networkingMode=VirtioProxy
localhostForwarding=false
memory=8GB
processors=4
swap=10GB
Shutdown WSL to ensure it picks up the changes: wsl --shutdown
2. Install WSL Ubuntu. e.g. for Ubuntu 24.04 LTS, in PowerShell, run wsl --install Ubuntu-24.04 then set as your default with wsl -s Ubuntu-24.04.
3. Open a Ubuntu terminal. Create a default user with sudo permissions. Follow the steps in the GitHub documentation to add a SSH key.
4. Configure your shell (.zshrc or .bashrc) to auto-start ssh-agent:
# Start SSH agent if not running
if [ -z "$SSH_AUTH_SOCK" ]; then
eval "$(ssh-agent -s)"
ssh-add ~/.ssh/id_ed25519 # or your key
fi
- Start a new shell and, somewhere in your home directory, git clone the repo using SSH:
git clone git@github.com:justice-bac/otto.git - In VScode, run command "WSL: Open Folder in WSL". Select the repo folder in your WSL filesystem. You may need to install the devcontainers extension in WSL VSCode.
- You should be prompted to reopen the folder in a container. Do so, then continue from step 4 in the "With Docker or Rancher Desktop" instructions.
After the initial setup, you will rarely have to build the dev containers again. You can just:
- Open VScode. If the devcontainer is not already opened, open the WSL folder, then "Reopen in container".
- Start the Django server & Celery worker.
All the commands you need to load data into Otto are in django/initial_setup.sh.
If you do not want to reset all your data (e.g. to preserve previously loaded Laws or Libraries), you can run individual commands.
For reset_app_data, you can specify the objects to reset. For example, to reset only the apps and groups data:
python manage.py reset_app_data apps groupsTo reset the libraries and clear out the vector store, run the following command. This will delete all the data in the vector store!
python manage.py reset_app_data librariesTo populate the Corporate Q&A library, run the following command. However, please be aware that this will ingest data and generate costs.
python manage.py load_corporate_libraryThe following command1 will automatically translate (or use existing translations) for text flagged as requiring translation (See the Translations section).
You should generate translations before making a PR if your branch has modified or added any text strings.
python manage.py load_app_localizationOtto now uses a small npm workspace to pin and vendor selected browser-side third-party assets (for example docx-preview and jszip) into Django's static asset tree.
From the repo root:
npm install
npm run vendor:syncThis updates the checked-in files under django/otto/static/thirdparty/ using the versions pinned in package-lock.json.
For the legislation search app to function, we must load the XML files into the database.
You can use the management GUI from the user dropdown if you are an Otto admin.
To enable the celery scheduler for local testing run the following command (from ./django):
celery -A otto beat --loglevel=info --scheduler django_celery_beat.schedulers:DatabaseScheduler- Don't push commits directly to
main. - Always branch off
mainto create a feature branch, e.g.git checkout -b chatbot-error-messages - Before opening a pull request (PR), make sure your branch is up to date with the source branch by running
git merge origin/main; resolve any conflicts. - Link your PR to an issue. If no issue exists, create one first to discuss the proposed changes.
- Run integration tests before opening a PR (see the instructions below). If the tests don't pass on your machine, they won't pass in the PR checks either.
- Write more tests if you have added new functionality (or are addressing a bug that wasn't previously caught by the tests).
- Use conventional commits for commit messages and PR titles, e.g.:
fix: chatbot not displaying errorsfor a bug fixfeat: upload document previewfor a new featurechore: upgrade llama-index versionrefactor(librarian): extract document sync logic into utilsfix(chat_next): preserve tool-call streaming state
- To indicate that the PR isn't ready to merge, create a
Draft PR - Get someone else to review your PR before merging it.
After your PR is merged:
- On your workstation,
git checkout mainandgit pull - Delete the branch that was just merged, e.g.
git branch -D chatbot-error-messages - Create a new feature branch, if you are ready to do so.
Otto uses pre-commit to automatically enforce code quality standards and maintain consistency across the codebase.
The pre-commit hooks are automatically installed when you run bash dev_setup.sh. If you need to install them manually:
pre-commit installThe following checks run automatically before each commit:
- Black: Python code formatter that ensures consistent code style
- isort: Organizes Python imports alphabetically and by section
- djLint: Formats and lints Django/Jinja templates for consistency
- Terraform fmt: Formats Terraform configuration files
If any of these checks fail, your commit will be blocked until you fix the issues. In most cases (Black, isort, and djLint), the tools will automatically fix the issues for you - just stage the changes and commit again.
Warning
Only skip hooks if you have a good reason and understand the implications. In rare cases where you need to bypass these checks, you can use:
git commit --no-verify # Skip pre-commit hooksYou can manually run the hooks at any time:
pre-commit run --all-files # Run all pre-commit hooks on all files
pre-commit run black --all-files # Run only Black on all filesTranslations happen in 3 different levels:
- Model Level
- Python Code Level
- Template Level
For any model that require translation:
-
Create a translation.py in your app directory.
-
Create a translation option class for every model to translate.
-
Register the model and the translation option class (See otto/translation.py for example).
-
Make sure to create new migrations and apply the changes
python manage.py makemigrations #create new migrations python manage.py migrate # apply changes
-
Provide default and translated values in fixtures if necessary (See otto/fixtures/*.yaml)
For more information see official documentation of django-modeltranslation
Import the gettext module as its shorter alias of '_'
from django.utils.translation import gettext as _Translate strings using the _() function
from django.http import HttpResponse
from django.utils.translation import gettext as _
def my_view(request):
output = _("Welcome to my site.")
return HttpResponse(output)For more information see official documentation of django
-
Make sure your code is ready for translation by having
{% load i18n %}toward the top of your template code and surrounding any text with thetranstag or theblocktranstag{% load i18n %} <title>{% trans "This is the title." %}</title> {% blocktrans with numeric_value=thing.property %}This string will have {{ numeric_value }} inside.{% endblocktrans %}
For more information, including how to translate your javascript code, see official documentation of django
Run collectstatic before running tests. You don't have to do this often, only when static files have changed. From the repo root:
python django/manage.py collectstatic --noinputIn PowerShell, from the repo root, paste this one-liner to run tests and display the results:
python -m coverage run --source=django -m pytest django/tests; python -m coverage html; python -m coverage reportYou can view the results in more detail by opening htmlcov/index.html in your browser.
Writing tests of the views ensures that pages will at least load (no server error).
A test of a view can be found in /django/otto/tests/test_views.py:
@pytest.mark.django_db
def test_homepage():
client = Client()
response = client.get(reverse("index"))
assert response.status_code == 200
soup = BeautifulSoup(response.content, "html.parser")
text = soup.get_text()
assert "Otto" in textYou should also test your functions separately (unit tests).
Unit tests must be located in /django/tests/. Here is a simple test:
def test_token_counter():
n = num_tokens_from_string("A")
assert n == 1Please log any actions user take while interacting with Otto using the structlog library and its info function.
from structlog import get_logger
...
logger = get_logger(__name__)
...
logger.info("Insert logging message here")You can also log any relevant information by adding a key/pair value to the log dictionary
logger.info("Insert logging message here", x=1, y=2)You should log errors using the error() function, critical messages using critical() and debugging messages using debug() 2
logger.error("")
logger.critical("")
logger.debug("")If you are having migration issues and/or have run out of options for debugging your branch, try resetting your database.
Warning
This will delete all of your data - be warned!
python manage.py reset_database
If things are even more messed up:
- Delete all your Docker containers, images and volumes
- Ensure you are sync'd with origin.
- Open the folder in VScode to rebuild the container from scratch.
AGPL license due to PyMuPDF dependency.
For details, please see LICENSE.txt.
Footnotes
-
To run the command you will need to have the gettext binaries installed. ↩
-
To see debug messages, make sure to set LOG_LEVEL to DEBUG and/or CELERY_DEBUG_LEVEL to DEBUG ↩