Skip to content

Instantly share code, notes, and snippets.

View inchoate's full-sized avatar

Jason Vertrees inchoate

View GitHub Profile

Here's my TL;DR on Azure Service Principals, with a full example of creating one to push docker images to Azure Container Registry.

First, you need an Azure Container Registry. So, go make one. And, once you're done go to its page in the UI and click Overview > JSON View. See that Resource ID? Copy that. That will become the scope or the Azure thing we want to give to give our principal access to. Scopes can be at various levels. In this example, I'm very finely scoping down to ONLY this container registry resource. This principal will have no permissions anywhere else. You can go up levels in the scope hierarchy if you want, and say, provide access to all resources in a resource group or even a subscription. My resource ID looks a bit like this: /subscriptions/1d6a...982f/resourceGroups/my-container-registry/providers/Microsoft.ContainerRegistry/registries/registryname. Also, store the name of your registry if you want to push an image to it later.

Second, you need to determine what permissions

@inchoate
inchoate / Azure-CLI-Bugs.md
Created May 12, 2023 21:00
Bugs in the Azure CLI

I found a bug in Azure's az CLI when it parses variables.

I was tagging a lot of resources and initially did this:

export ENV=demo
export VERSION=
export RG=rg-apps-${ENV}${VERSION}
export LOCATION=eastus
export SUBSCRIPTION="my-subscription-id"

If you've instantiated your CrewAI Crew as a class, using the convenient decorators (@agent, @task, for example) as shown in the documentation you probably ended up with something like this:

@crew
def crew(self) -> Crew:
    """Creates the crew"""
    return Crew(
        agents=self.agents,
        tasks=self.tasks,
        process=Process.sequential,
        full_output=True,
@inchoate
inchoate / sql-model-full-schema-dump.md
Last active March 30, 2025 04:02
Recipe for converting Pydantic models to SQLModel while still supporting the ability to fully emit nested schema and model data.

Emitting Fully Nested Python Schemas and Models with SQLModel

I ran into a problem while developing some cool tools. I had a nested Pydantic structure that I needed to migrate to SQLModel. But, I needed to retain the ability to emit fully nested schema and models -- which was lost. So, I had to write a few helper functions and models.

In the realm of modern web development and data-driven applications, managing complex data structures and their relationships can be a daunting task. SQLModel, a powerful library that bridges the gap between SQLAlchemy and Pydantic, offers an elegant solution for defining and interacting with SQL databases using Python. In this small write up, we dive into a practical demonstration of leveraging SQLModel to emit fully nested Python schemas and models. Surprisingly, this doesn't work out of the box.

Our focus is on a versatile script that illustrates how to dynamically generate and manipulate nested data structures. By defining SQLModel-based types, we can seamlessly map th

@inchoate
inchoate / filtered-query-engine.md
Last active August 10, 2024 12:32
Llama Index Filtered Query Engine Example

Selectively Querying Documents in Llama Index

Note: This gist has been updated to be far simpler than the original implementation, focusing on a more streamlined approach to selectively querying documents based on metadata.

Introduction

When working with Llama Index and other Retrieval-Augmented Generation (RAG) systems, most tutorials focus on ingesting and querying a single document. You typically read the document from a source, parse it, embed it, and store it in your vector store. Once there, querying is straightforward. But what if you have multiple documents and want to selectively query only one, such as Document #2 (doc_id=2), from your vector store?

This article demonstrates how to encapsulate the creation of a filtered query engine, which allows you to specify the nodes to query based on custom metadata. This approach provides a more structured and efficient way to retrieve relevant information, making it easier to manage and scale your querying process.

@inchoate
inchoate / timestamp_mixin.py
Last active August 8, 2024 11:08
SQLModel Timestamp Mixing - add the usual fields to your data model with ease
"""
Adding this SQLModel mixin will add created_at, updated_at, and deleted_at to your tables.
`created_at` will auto-populate upon creation. `updated_at` will do the right thing on updates.
Usage:
class YourModel(TimestampMixin):
...
At this point all classes inheriting from YourModel will have the usual fields added.
@inchoate
inchoate / geolocation_mixin.md
Created August 9, 2024 10:26
geolocation_mixin.py

Geolocation with SQLModel

Need to use postgis with SQLModel? This example will show you how.

This gist demonstrates how to integrate a geolocation field into your SQLModel projects by directly adding a geometry column representing a point on Earth. The GeolocationMixin class provides an easy way to store and serialize geospatial data, specifically using PostGIS to handle POINT geometry types.

To run this example, you'll need a PostGIS-enabled database. You can set up PostGIS using Docker with the following command:

docker run -d --rm \
@inchoate
inchoate / quick-vector-db-for-ai.md
Created August 10, 2024 12:07
Vector database for AI

Quick Setup: PostgreSQL with pgvector for AI Projects

If you need a working vector database for your AI project in no time, this guide is for you. Setting up PostgreSQL with pgvector is super easy, and Docker makes it even more convenient.

Step 1: Run PostgreSQL with pgvector

PostgreSQL is an excellent database, and Docker images make it easy to spin up a containerized version. To get PostgreSQL with pgvector installed and ready to go, run the following command:

docker run -d --rm \
@inchoate
inchoate / rename_field_in_json_postgres.sql
Created August 20, 2024 14:17
Example showing how to rename a field contained within a JSON column in postgres.
--
-- This nice little query renames `camp_id` to `organization_id` in the JSON column.
-- Note, it converts to and from JSONB to do this.
--
UPDATE public.data_camp_embeddings
SET metadata_ = jsonb_set(
-- Convert JSON to JSONB for easier manipulation, and remove the "camp_id" key
metadata_::jsonb - 'camp_id',
-- Insert "organization_id" key at the top level with the value from "camp_id"
'{organization_id}',
@inchoate
inchoate / enums_in_sqlmodel_with_postgres.md
Created August 22, 2024 19:34
Using Enums in SQLModel with Postgres

Working with Enums in SQLModel and PostgreSQL: A Tasty Example with Ice Cream Flavors

Introduction:
Enums are a great way to represent a fixed set of values in your database. In this example, we'll model an IceCreamShop that serves various flavors of ice cream using SQLModel and PostgreSQL. We'll demonstrate how to store these flavors using enums and how to query for specific flavors using SQLAlchemy's powerful querying capabilities.

import os
from enum import Enum
from typing import List, Optional