Skip to content

Instantly share code, notes, and snippets.

View simonw's full-sized avatar

Simon Willison simonw

View GitHub Profile
@simonw
simonw / pyproject.toml
Last active July 25, 2023 19:40
sqlite-utils-litecli plugin
[project]
name = "sqlite-utils-litecli"
version = "0.1"
dependencies = [
"litecli"
]
[project.entry-points.sqlite_utils]
litecli = "sqlite_utils_litecli"
@simonw
simonw / interactive_llama2.py
Created July 24, 2023 19:32
Interactive Llama 2
from transformers import AutoTokenizer
import transformers
import torch
model = "meta-llama/Llama-2-7b-chat-hf"
print("AutoTokenizer.from_pretrained(model)")
tokenizer = AutoTokenizer.from_pretrained(model)
@simonw
simonw / pyproject.toml
Created July 22, 2023 18:29
sqlite-utils hello world plugin
[project]
name = "sqlite-utils-hello-world"
version = "0.1"
[project.entry-points.sqlite_utils]
hello_world = "sqlite_utils_hello_world"
@simonw
simonw / rotating-emoji-globe.html
Created July 19, 2023 23:48
Rotating emoji globe
<!DOCTYPE html>
<html>
<head>
<title>Globe Emoji Animation</title>
<style>h1 { font-size: 70vh; text-align: center; padding: 0; margin: 0 }</style>
</head>
<body>
<h1>🌎</h1>
<script>
const globeEmojis = ['🌎', '🌍', '🌏'];
@simonw
simonw / explain-selected.js
Last active July 13, 2023 04:53
JavaScript function to explain selected text on the page using GPT 3.5
(function() {
const OPENAI_API_KEY = 'sk-...';
let selectedText = window.getSelection().toString().trim();
if (selectedText.length > 0) {
let body = JSON.stringify({
model: 'gpt-3.5-turbo',
messages: [{role: 'system', content: 'explain this succinctly' },{ role: 'user', content: selectedText }]
});
fetch('https://api.openai.com/v1/chat/completions', {
method: 'POST',
@simonw
simonw / server_sent_events.py
Created July 10, 2023 18:25
Tiny ASGI app demonstrating server-sent events
import asyncio
from pprint import pprint
async def app(scope, receive, send):
if scope["type"] == "http":
if scope["path"] == "/":
await homepage(send)
elif scope["path"] == "/subscribe":
await subscribe(scope, send)
@simonw
simonw / datasette_llm.py
Created July 10, 2023 17:59
datasette-llm plugin prototype - adds a "datasette llm" command to Datasette which mirrors the "llm" command from LLM.
from datasette import hookimpl
from llm.cli import cli as llm_cli
@hookimpl
def register_commands(cli):
cli.add_command(llm_cli, name="llm")
import llm
import random
import time
from typing import Optional
from pydantic import field_validator
@llm.hookimpl
def register_models(register):
register(Markov())
<div class="group w-full text-gray-800 dark:text-gray-100 border-b border-black/10 dark:border-gray-900/50 dark:bg-gray-800">
<div class="text-base gap-4 md:gap-6 md:max-w-2xl lg:max-w-xl xl:max-w-3xl p-4 md:py-6 flex lg:px-0 m-auto">
<div class="w-[30px] flex flex-col relative items-end">
<div class="relative flex">
<span style="box-sizing: border-box; display: inline-block; overflow: hidden; width: initial; height: initial; background: none; opacity: 1; border: 0px none; margin: 0px; padding: 0px; position: relative; max-width: 100%;">
<span style="box-sizing: border-box; display: block; width: initial; height: initial; background: none; opacity: 1; border: 0px none; margin: 0px; padding: 0px; max-width: 100%;">
<img style="display: block; max-width: 100%; width: initial; height: initial; background: none; opacity: 1; border: 0px none; margin: 0px; padding: 0px;" alt="" aria-hidden="true" src="data:image/svg+xml,%3csvg%20
xmlns=%27http://www.w3.org/2000/svg%27%20version=%271.1%27
{"ISO 693-3":"aaa","Language Name":"Ghotuo","Language Family":"Niger-Congo","Subgrouping":"Atlantic-Congo","ASR":false,"TTS":false,"LID":true,"":"https://www.ethnologue.com/language/aaa"}
{"ISO 693-3":"aab","Language Name":"Arum","Language Family":"Niger-Congo","Subgrouping":"Atlantic-Congo","ASR":false,"TTS":false,"LID":true,"":"https://www.ethnologue.com/language/aab"}
{"ISO 693-3":"aac","Language Name":"Ari","Language Family":"Trans-New Guinea","Subgrouping":"Gogodala-Suki","ASR":false,"TTS":false,"LID":true,"":"https://www.ethnologue.com/language/aac"}
{"ISO 693-3":"aad","Language Name":"Amal","Language Family":"Sepik","Subgrouping":"Iwam","ASR":false,"TTS":false,"LID":true,"":"https://www.ethnologue.com/language/aad"}
{"ISO 693-3":"aaf","Language Name":"Aranadan","Language Family":"Dravidian","Subgrouping":"Southern","ASR":false,"TTS":false,"LID":true,"":"https://www.ethnologue.com/language/aaf"}
{"ISO 693-3":"aai","Language Name":"Miniafia Oyan","Language Family":"Austronesian","Subgrouping":"Malayo-Pol