Skip to content

Instantly share code, notes, and snippets.

@cfortuner
cfortuner / ai-plugin.json
Last active April 16, 2023 22:26
An example of a supporting commands in a ChatGPT plugin.
{
"schema_version": "v1",
"name_for_human": "Commands API",
"name_for_model": "Commands API",
"description_for_human": "An API for managing and executing user commands in a chat-based social app.",
"description_for_model": "This API allows users to list and run commands.",
"auth": {
"type": "none"
},
"api": {
import fs from "fs";
import axios from "axios";
import {
CharacterTextSplitter,
Document,
EmbeddedDocument,
Embeddings,
HTMLLoader,
JSONParser,
OpenAI,
@cfortuner
cfortuner / Prompt.ts
Created February 23, 2023 17:11
Promptable Prompt class
import { injectVariables } from "@utils/inject-variables";
import { NoopParser, Parser } from "@prompts/Parser";
import { ExtractFormatObject } from "@utils/type-utils";
import { ModelProviderType } from "dist";
export type PromptVariables<T extends string> = ExtractFormatObject<T>;
export interface PromptConfiguration {
stop?: string[] | string | undefined;
temperature?: number | undefined;
maxTokens?: number | undefined;
@cfortuner
cfortuner / stream-completions-nextjs-to-client.ts
Last active February 15, 2023 23:42
stream-completions-nextjs-to-client
import axios from "axios";
import { NextApiRequest, NextApiResponse } from "next";
export default async function handler(
req: NextApiRequest,
res: NextApiResponse
) {
const oaiRes = await axios.post(
"https://api.openai.com/v1/completions",
{
@cfortuner
cfortuner / stream-completions.ts
Created February 15, 2023 20:51
Stream completions OAI -> Client
const config = new Configuration({
apiKey,
});
const openai = new OpenAIApi(config);
const res: any = await openai.createCompletion(
{
prompt: "Write a poem about dogs",
model: "text-davinci-003",
@cfortuner
cfortuner / summarize-chunks.ts
Last active February 4, 2023 00:45
GPT-3 summarization of a long document
// Load the file
const filepath = "./data/startup-mistakes.txt";
let doc = fs.readFileSync(filepath, "utf8");
// Split the doc by the separator
const separator = "\n\n";
const texts = doc.split(separator);
const chunkSize = 1000;
const chunkOverlap = 100;
@cfortuner
cfortuner / README.md
Last active April 9, 2021 18:46
k-means in js

two methods

  • randomly choose k obj from data and use a inital means
  • randomly assign bucket to each obs

centroid becomes the new mean

  • find mean location within cluster
    • centroid algo
@cfortuner
cfortuner / Problem.md
Last active March 15, 2021 22:25
JS to validate xml

Tag Parsing

Implement an algorithm that validates XML tags and returns a boolean indicating if they're valid.

Here are the features we'd like to implement (in order of importance):

  • support open (<x>) and close (</x>)
  • support self-closing tags (<x/>)
  • support "boolean" attributes (<x special></x>)
  • support "valued" attributes (<x number="10"></x>)
@cfortuner
cfortuner / Binary Protocol for ECSY
Created February 18, 2021 02:55
My custom binary protocol for my main game update messages using ECSY and https://github.com/cfortuner/binary-message-buffer
/**
* write
*
* A world snapshot consists of the following bits in order:
* 1. server world timestamp (ms)
* 2. server frame
* 3. all network entity snapshots
* a) network id
* b) entity was removed bit
* b) all network component snapshots
@cfortuner
cfortuner / magic.py
Last active March 24, 2019 04:45
Playing around with python magic methods
class Provider():
_client_attribute_names = ['get_data', 'update_data']
def __init__(self):
self._client = Client() # assumes some client exists
self._factories = {
'get_data': factory_method #Add your factory method here
}