Skip to content

Instantly share code, notes, and snippets.

View josiahbryan's full-sized avatar

Josiah Bryan josiahbryan

View GitHub Profile
@josiahbryan
josiahbryan / Wangdd22RelayClient.js
Last active July 17, 2022 01:44
Simple controller for use with the Wangdd22 Ethernet Relay
//
// Simple controller for use with the Wangdd22 Ethernet Relay, available on Amazon for ~$35
//
// See https://www.amazon.com/dp/B01MRQTFMJ?psc=1&ref=ppx_yo2ov_dt_b_product_details
//
// Special thanks to commentors on the product listing:
// Python Client: https://www.amazon.com/gp/customer-reviews/RAEHN60VSX3LV/ref=cm_cr_dp_d_rvw_ttl?ie=UTF8&ASIN=B01MRQTFMJ
// Config format: https://www.amazon.com/gp/customer-reviews/R19ZMADG7S2GX2/ref=cm_cr_dp_d_rvw_ttl?ie=UTF8&ASIN=B01MRQTFMJ
//
// This client just turns on/off the relays, doesn't handle config, but could easily be added thanks to the info
/**
* This is a simple wrapper script that orchestrates the PlanetScale API
* so we can synchronize our schema changes via DDL to a dev branch and
* automatically release them.'
*
* This was created for my own project using my own ORM (https://github.com/josiahbryan/yass-orm)
* but the PlanetScale API operations below should be easily reusable
* for other scenarios.
*
* The main flow looks something like:
/**
* Coax an LLM into generated grounded JSON based on key/value-level perplexity checks with a custom
* `yup` validation test for perplexity, model fallbacks, and a customizable failure injection callback
* to inject grounding instructions on request for exact paths (e.g. for specific keys, if perplexity too high).
*
* Contributing to the community as an example of how to coax an LLM into generating JSON that conforms
* to a schema with key-level perplexity checks and fallback models for retries.
*
* Write up at: https://dev.to/josiahbryan/tackling-json-perplexity-in-llm-outputs-a-weekend-project-jm8
*
/* eslint-disable no-unused-vars */
import Logger, { chalk } from 'shared/utils/Logger';
import { jsonSafeParse } from 'shared/utils/jsonSafeParse';
import { jsonSafeStringify } from 'shared/utils/jsonSafeStringify';
import { normalizeDecimals } from 'shared/utils/normalizeDecimals';
import { dedupBy } from 'shared/utils/dedupBy';
import { setProperty } from 'dot-prop';
import { annotateLogProbs } from './annotateLogProbs';
const propPathArrayToString = (pathArray) => {
@josiahbryan
josiahbryan / annotateLogProbs.js
Created April 20, 2024 01:16
Convert an array of logprobs to perplexity and jointProb values
export const annotateLogProbs = (logprobs) => {
if (!logprobs?.length) {
// Fix people not deconstructing for us
if (logprobs?.content?.length) {
// eslint-disable-next-line no-param-reassign
logprobs = logprobs.content;
} else {
return {};
}
}
@josiahbryan
josiahbryan / Dockerfile
Created May 23, 2024 18:33
Dockerfile/K8 Setup example for running Puppeteer
FROM --platform=linux/amd64 node:20.11.1 as base
# Note: The --platform arg above is required for building on Apple Silicon (Mx) Macs
# Thanks to <https://dev.to/docker/unable-to-locate-package-google-chrome-stable-b62> for the tip.
USER root
WORKDIR /root
# Most of this apt-get setup is based on https://blog.apify.com/puppeteer-docker/
# Install the latest Chrome dev package and necessary fonts and libraries
@josiahbryan
josiahbryan / orbFocusOnNode.js
Created May 24, 2024 02:10
Focus the Orb View on a Specific Node
// These 3x d3 imports ARE provided by the orb package itself, that's why I've silenced eslint here for these 3 lines
// eslint-disable-next-line import/no-extraneous-dependencies
import { zoomIdentity } from 'd3-zoom';
// eslint-disable-next-line import/no-extraneous-dependencies
import { select } from 'd3-selection';
// eslint-disable-next-line import/no-extraneous-dependencies
import { easeLinear } from 'd3-ease';
export function orbFocusOnNode(orb, orbNode, { onRendered } = {}) {
// The VAST majority of this function is based off of code in the Orb library already,