| #!/usr/bin/env bash | |
| set -euo pipefail | |
| bold() { printf "\033[1m%s\033[0m\n" "$*"; } | |
| info() { printf "• %s\n" "$*"; } | |
| warn() { printf "\033[33m! %s\033[0m\n" "$*"; } | |
| err() { printf "\033[31m✗ %s\033[0m\n" "$*" >&2; } | |
| ok() { printf "\033[32m✓ %s\033[0m\n" "$*"; } | |
| require_macos() { |
| name: Weekly Changelog | |
| on: | |
| schedule: | |
| - cron: "0 9 * * 1" # Every Monday at 9:00 AM UTC | |
| workflow_dispatch: | |
| jobs: | |
| generate-changelog: | |
| runs-on: ubuntu-latest |
| # Create a new worktree and branch from within current git directory. | |
| ga() { | |
| if [[ -z "$1" ]]; then | |
| echo "Usage: ga [branch name]" | |
| exit 1 | |
| fi | |
| local branch="$1" | |
| local base="$(basename "$PWD")" | |
| local path="../${base}--${branch}" |
Extracting financial disclosure reports and police blotter narratives using OpenAI's Structured Output
tl;dr this demo shows how to call OpenAI's gpt-4o-mini model, provide it with URL of a screenshot of a document, and extract data that follows a schema you define. The results are pretty solid even with little effort in defining the data — and no effort doing data prep. OpenAI's API could be a cost-efficient tool for large scale data gathering projects involving public documents.
OpenAI announced Structured Outputs for its API, a feature that allows users to specify the fields and schema of extracted data, and guarantees that the JSON output will follow that specification.
For example, given a Congressional financial disclosure report, with assets defined in a table like this:
| export default { | |
| async fetch(request, env, ctx) { | |
| const url = new URL(request.url); | |
| // Modify the request to point to the Google Tag Manager endpoint | |
| url.hostname = env.GTM_HOST; | |
| // Create a new headers object based on the original request headers | |
| const modifiedHeaders = new Headers(request.headers); |
| import { GetProgramAccountsFilter, PublicKey, TransactionMessage, VersionedTransaction } from "@solana/web3.js"; | |
| import { connection } from "../src/connection"; | |
| import config from "../src/lib/Config"; | |
| import { TOKEN_2022_PROGRAM_ID, TOKEN_PROGRAM_ID, createBurnCheckedInstruction, createCloseAccountInstruction, getAssociatedTokenAddressSync, unpackAccount, unpackMint } from "@solana/spl-token"; | |
| // Not really tested more than two but you can probably fit more in. | |
| const maxMintsPerTx = 2; | |
| // Replace this with your own keypair | |
| const owningAccount = config.keypair; | |
| // This creates a tx like this: https://solscan.io/tx/5PegaAnFzaEdVWYfzHFVTzJyZr8wHKRhijgtXyGhNzaQj4HfW5U8BqaaHNhGkCbZRDePns5cnFJAb18RCx4cuLqB |
| import { | |
| Instruction, | |
| SwapInstructionsResponse | |
| } from "@jup-ag/api"; | |
| import { | |
| AddressLookupTableAccount, | |
| ComputeBudgetProgram, | |
| Connection, | |
| Keypair, | |
| PublicKey, |
| require('dotenv').config(); | |
| const sgMail = require('@sendgrid/mail'); | |
| const sgClient = require('@sendgrid/client'); | |
| const express = require('express') | |
| const expressFileUpload = require('express-fileupload'); | |
| const app = express(); | |
| sgMail.setApiKey(process.env.SENDGRID_API_KEY); | |
| sgClient.setApiKey(process.env.SENDGRID_API_KEY); | |
| app.use(express.urlencoded({ |
Installing node through Homebrew can cause problems with npm for globally installed packages. To fix it quickly, use the solution below. An explanation is also included at the end of this document.
This solution fixes the error caused by trying to run npm update npm -g. Once you're finished, you also won't need to use sudo to install npm modules globally.
Before you start, make a note of any globally installed npm packages. These instructions will have you remove all of those packages. After you're finished you'll need to re-install them.