This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const hasCircularReference = (graph, startUID) => { | |
const visited = new Set() | |
const stack = [startUID] | |
while (stack.length > 0) { | |
let currentUID = stack.pop() | |
if (visited.has(currentUID)) { | |
return true | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import readline from 'readline' | |
import chalk from 'chalk' | |
import OpenAI from 'openai' | |
import { LocalIndex } from 'vectra' | |
import { fileURLToPath } from 'url' | |
import path, { dirname } from 'path' | |
const __filename = fileURLToPath(import.meta.url) | |
const __dirname = dirname(__filename) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// These methods were made by chat gpt and have not been tested. | |
const cosineSimilarity = (vecA, vecB) => { | |
if (vecA.length !== vecB.length) { | |
throw new Error("Vectors must be of the same length."); | |
} | |
let dotProduct = vecA.reduce((sum, val, i) => sum + val * vecB[i], 0); | |
let normA = vecA.reduce((sum, val) => sum + val * val, 0); | |
let normB = vecB.reduce((sum, val) => sum + val * val, 0); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const tokenize = (text) => | |
text.toLowerCase().split(/\W+/).filter(token => token.length > 0) | |
const buildVocabulary = (sentences) => { | |
const vocabulary = new Set() | |
sentences.forEach(sentence => { | |
tokenize(sentence).forEach(token => { | |
vocabulary.add(token) | |
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// This is a basic diff mechanism, it is not going to work for characters that take up more than | |
// one byte. It is also not going to normalise text. | |
// these are things that *should happen* in the future, but for now they are going to be ignored. | |
// returns the insert position & the text to insert as well as the delete position & the text to delete | |
// one of the problems with this kind of diff is that you can't tell in some cases where the insert | |
// actually occurred. | |
// for this you will need to take into account the cursor start & end. | |
export const diff = (a, b) => { | |
if (a === b) { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
path { | |
fill: none; | |
stroke: rgba(52, 53, 60, 1); | |
stroke-width: 4; | |
stroke-linecap: round; | |
} | |
svg > text { | |
font-family: 'Geist', sans-serif !important; | |
fill: rgb(201, 213, 229); |