Skip to content

Instantly share code, notes, and snippets.

@changjonathanc
changjonathanc / o3pro-mcp.md
Created June 21, 2025 10:45
i asked o3 pro to explain model context protocol

Below is a consolidated reference to the current Model‑Context Protocol (MCP) features that govern how I think, reason, and format replies—excluding the tool catalog itself.


1. Instruction‑layer hierarchy

  • System → Developer → User: Every response is shaped by this ordered stack. Higher‑layer rules always override lower‑layer rules.
  • Guarantees that user‑level preferences are honored unless they conflict with developer or system‑level safety or policy constraints.

2. Multi‑channel response model

@changjonathanc
changjonathanc / anthropic_oauth.py
Created June 21, 2025 03:51
Anthropic OAuth CLI - Simplified Claude Code spoof demo
#!/usr/bin/env python3
import argparse
import base64
import hashlib
import json
import os
import secrets
import sys
import time
@changjonathanc
changjonathanc / server.py
Created June 4, 2025 14:47
Codex /root/server.py
import asyncio
import logging
import os
import pty
import pwd
import subprocess
from contextlib import asynccontextmanager
import uvicorn
from fastapi import FastAPI, HTTPException, Request, Response
import torch
def precompute_freqs_cis(dim: int, end: int, theta: float = 10000.0, dtype=torch.float32, mod=True):
freqs = 1.0 / (theta ** (torch.arange(0, dim, 2)[: (dim // 2)].float() / dim))
t = torch.arange(end, device=freqs.device) # type: ignore
angles = torch.outer(t, freqs) # type: ignore
if mod:
angles = angles % (2 * torch.pi)
# Now convert angles to the desired lower precision
angles = angles.to(dtype)
"""Generates a document causal attention mask based on a document ID tensor"""
from typing import List, Union
import torch
from torch import Tensor
from torch.nn.attention.flex_attention import _mask_mod_signature, or_masks
from attn_gym.masks import causal_mask
@changjonathanc
changjonathanc / M1_GPU.md
Last active January 24, 2022 17:12
Run huggingface transformers on M1 Macs, on GPU!

Run huggingface transformers on M1 Macs, on GPU

  • Requirement: macOS 12 Monterey

  • First, install a conda env with M1 support

wget https://github.com/conda-forge/miniforge/releases/latest/download/Miniforge3-MacOSX-arm64.sh
chmod +x ~/Downloads/Miniforge3-MacOSX-arm64.sh
sh ~/Downloads/Miniforge3-MacOSX-arm64.sh
@changjonathanc
changjonathanc / number token.py
Created October 1, 2021 15:38
tokens that are numbers in gpt2 tokenizer
from transformers import AutoTokenizer, AutoModelWithLMHead
tokenizer = AutoTokenizer.from_pretrained("gpt2")
# model = AutoModelWithLMHead.from_pretrained("gpt2")
import re
nums = []
@changjonathanc
changjonathanc / parse-c4-date-from-url.ipynb
Created September 21, 2021 07:35
parse-c4-date-from-url.ipynb
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@changjonathanc
changjonathanc / mc4-timestamp-analysis.ipynb
Created September 17, 2021 15:22
mc4-timestamp-analysis.ipynb
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
from tqdm.auto import tqdm
import time
class LengthedGeneratorWrapper:
"""wraps an infinite generator with length for tqdm"""
def __init__(self, infinite_generator, len):
self.generator = infinite_generator
self.len = len
def __len__(self):
return self.len