Skip to content

Instantly share code, notes, and snippets.

View thesephist's full-sized avatar
🍷
Ridin' in a getaway car

Linus Lee thesephist

🍷
Ridin' in a getaway car
View GitHub Profile
@thesephist
thesephist / rankedSummarize.ts
Created December 26, 2023 22:52
Ranked summarize with Cascade.
import { cascade } from "../src/cascade.ts";
export const summarize = cascade
.chatCompletion("summarize", {
model: "gpt-3.5-turbo",
renderPrompt: (context: { title: string; content: string }) => [
{
type: "user",
content: [
`Write a one sentence summary about ${context.title}.\n\n${context.content}.`,
@thesephist
thesephist / pull-all.lisp
Last active December 12, 2023 08:52
A Klisp script to run "git pull" en masse on all of my folders. Run with `pull-all ~/src`, etc.
; pull-all
;
; Run "git pull" en masse on all git repositories with a default remote under a
; specific directory.
(defn indent (s bit)
(-> s
(split '\n')
(map (fn (line)
(if (empty? line)
@thesephist
thesephist / gpt2_xl_perplexities.py
Created September 4, 2023 20:23
Code (most of it) for my GPT2 perplexities visualizer UI: https://twitter.com/thesephist/status/1617747154231259137
import torch
import torch.nn as nn
import torch.nn.functional as F
from transformers import GPT2Tokenizer, GPT2LMHeadModel
ppl_model_name = 'gpt2-xl' if device == 'cuda' else 'gpt2'
ppl_tokenizer = GPT2Tokenizer.from_pretrained(ppl_model_name)
load_opts = {
'device_map': 'auto',
// Code to measure selection rects
// NOTE: this isn't actually JS... it's Oak. But I think the code is readable if you know JS :/
// NOTE: I *think* this event listener only works when attached to `document`.
with document.addEventListener('selectionchange') fn handleSelectionChange {
if active := document.activeElement {
? -> ?
_ -> if active.classList.contains('textarea-itself') {
false -> ?
@thesephist
thesephist / prepare_data.py
Created December 15, 2022 01:57
Data prep script to fine-tune GPT-3 on my past writing
#!/usr/bin/env python
import os
import json
from tqdm import tqdm
from transformers import GPT2TokenizerFast
os.environ['TOKENIZERS_PARALLELISM'] = 'false'
FILENAME = './thesephist.jsonl'
@thesephist
thesephist / options.oak
Created November 14, 2022 22:09
Collection of useful Stable Diffusion prompt modifiers
{ name: 'Lighting', options: [
'golden hour, warm glow'
'blue hour, twilight, ISO12000'
'midday, direct lighting, overhead sunlight'
'overcast, whitebox, flat lighting, diffuse'
'dreamlike diffuse ethereal lighting'
'dramatic lighting, dramatic shadows, illumination'
'studio lighting, professional lighting, well-lit'
'flash photography'
'low-key lighting, dimly lit'

ask CLI

ask is a little CLI I made to interact with OpenAI's GPT-3 (text-davinci-002) from my shell/terminal. The instruction fine-tuning on that model makes it particularly ideal for just asking questions and making requests.

With this CLI, I can do something like:

$ ask 'Write a haskell function that reverses a string'
reverseString :: String -> String
reverseString = foldl (\acc x -> x : acc) []
@thesephist
thesephist / generate-pushid.js
Created September 26, 2022 13:14 — forked from mikelehen/generate-pushid.js
JavaScript code for generating Firebase Push IDs
/**
* Fancy ID generator that creates 20-character string identifiers with the following properties:
*
* 1. They're based on timestamp so that they sort *after* any existing ids.
* 2. They contain 72-bits of random data after the timestamp so that IDs won't collide with other clients' IDs.
* 3. They sort *lexicographically* (so the timestamp is converted to characters that will sort properly).
* 4. They're monotonically increasing. Even if you generate more than one in the same timestamp, the
* latter ones will sort after the former ones. We do this by using the previous random bits
* but "incrementing" them by 1 (only in the case of a timestamp collision).
*/
@thesephist
thesephist / compress-pdfs.sh
Created September 16, 2022 07:36
Bash one-liner (with Oak and Rush) to compress all PDFs in a folder
rush mv *.pdf 'o-{{name}}.pdf && ls *.pdf | oak pipe "print(line), exec('/usr/local/bin/gs', ['-sDEVICE=pdfwrite', '-dCompatibilityLevel=1.4', '-dPDFSETTINGS=/ebook', '-dNOPAUSE', '-dQUIET', '-dBATCH', '-sOutputFile=' + str.trimStart(line, 'o-'), line], '').stdout |> str.trim()"
@thesephist
thesephist / afterglow.md
Last active August 11, 2022 00:18
Prompt: ""Afterglow" is a speculative science fiction novel about a world attempting to rebuild after an apocalyptic nuclear attack on semiconductor foundries in Taiwan causes worldwide silicon shortages and geopolitical turmoil. The novel is praised particularly for its detailed and creative worldbuilding. Write a detailed plot summary of the e…

"Afterglow" is a speculative science fiction novel by Greg Egan about a world attempting to rebuild after an apocalyptic nuclear attack on semiconductor foundries in Taiwan causes worldwide silicon shortages and geopolitical issues.

  1. Synopsis

The novel is set in the year 2040, in the aftermath of a nuclear attack on semiconductor foundries in Taiwan that has left the world without access to silicon. The attack has caused widespread economic and political upheaval, and the novel follows the efforts of a group of scientists, engineers, and entrepreneurs to develop new technologies and rebuild the world.

  1. Characters

The novel follows a large cast of characters, including: