Skip to content

Instantly share code, notes, and snippets.

@adriancooney
adriancooney / route.ts
Created April 29, 2023 16:38
Create a ReadableStream from a OpenAI GPT3/4 LangChain chain for Edge streaming
import { OpenAI } from "langchain/llms/openai";
import { PromptTemplate } from "langchain/prompts";
import { LLMChain } from "langchain/chains";
import { streamCall } from "./stream-call"
export const config = {
runtime: "edge",
};
export async function GET(request: Request) {
interface SemaHandle {
release(): void;
}
function createSema(concurrency: number): { acquire(): Promise<SemaHandle> } {
let handles: string[] = [];
const queue: ((value: unknown) => void)[] = [];
function createHandle(): string {
const handle = nanoid();
When the yogurt took over, we all made the same jokes – “Finally, our rulers will have culture,” “Our society has curdled,” “Our government is now the cream of the crop,” and so on. But when we weren’t laughing about the absurdity of it all, we looked into each others’ eyes with the same unasked question – how did we ever get to the point where we were, in fact, ruled by a dairy product?
Oh, as a matter of record, we knew how it happened. Researchers at the Adelman Institute for Biological Technology in Dayton had been refining the process of DNA computing for years. In a bid to increase efficiency and yield, scientists took one of their most computationally advanced strains and grafted it into Lactobacillus delbrueckii subspecies bulgaricus, commonly used to ferment yogurt. Initial tests appeared to be failures, and acting under the principal of “waste not, want not,” one of the researchers sneaked some of the bacillus out of the lab to use for her homemade yogurt.
A week later, during breakfast, the yogur