Skip to content

Instantly share code, notes, and snippets.

View Aschen's full-sized avatar
💭
:trollface:

Adrien Maret Aschen

💭
:trollface:
View GitHub Profile
@Aschen
Aschen / vcr.ts
Created July 8, 2024 07:43
VCR for methods
const YAML = require('yaml')
import Path from 'node:path'
import { existsSync, mkdirSync, readFileSync, writeFileSync } from 'node:fs'
import { createHash } from 'node:crypto'
export function vcr({
instance,
methods,
mode = 'cache',
verbose = true,
@Aschen
Aschen / summary-prompt.txt
Created May 14, 2024 21:15
Summary prompt
Tu possède un excellent esprit d'analyse et de synthèse et tu es capable d'extraire les informations pertinente d'un document pour les résumer.
Voici le document:
# BEGIN
// Document content
# END DOCUMENT
Répond en suivant ce format YAML:
```yaml
@Aschen
Aschen / summary-prompt.txt
Last active May 14, 2024 21:13
Document Summary Prompt
Tu possède un excellent esprit d'analyse et de synthèse et tu es capable d'extraire les informations pertinente d'un document pour les résumer.
Voici le document:
# BEGIN
// Document content
# END DOCUMENT
Répond en suivant ce format YAML:
```yaml
import { encoding_for_model } from 'tiktoken'
// Choose the model, it can be 'gpt4' for example
const tokenEncoder = encoding_for_model('text-embedding-ada-002')
// Contains an array of Uint32 ([-0.102, 0.62, ..])
const tokens = tokenEncoder.encode(text)
// Number of tokens
console.log(tokens.length)
@Aschen
Aschen / README.md
Last active October 24, 2024 16:54
Scrape a page and convert it to Markdown

Scrape a page and convert it to Markdown

Install dependencies: npm install playwright cheerio node-html-markdown

Install firefox browser: npx playwright install firefox

Run the script: tsx html-to-md.ts https://mistral.ai/fr/news/mixtral-8x22b/

@Aschen
Aschen / class.ts
Created January 22, 2024 17:24
Method vs member holding a function
class Foobar {
private name = 'foobar'
getName = () => {
return this.name
}
}
class Barfoo {
private name = 'barfoor'
@Aschen
Aschen / agent-llm.js
Created November 8, 2023 19:45
Assistant OpenAI benchmark
function createTask (req, res) {
const newTask = req.body;
verifyTask(newTask);
const savedTask = database.addTask(newTask);
res.status(201).send(`Task ${savedTask.metadata.id} saved successfully`);
}
function addTask(newTask) {
const tasks = readTasksFromFile();
const taskWithId = { ...newTask, metadata: { id: generateId() } };
@Aschen
Aschen / start.sh
Created October 15, 2023 09:00
WebHook development: HTTP echo server
node -e "const h = require('http');const s = h.createServer();const l = console.log;s.on('request', (rq, rs) => {let b = [];rq.on('data', (c) => {b.push(c);}).on('end', () => {b = Buffer.concat(b).toString();l('==== '+rq.method+' '+rq.url);l('> Headers');l(rq.headers);l('> Body');l(b);rs.end();});}).listen(8000);"
@Aschen
Aschen / README.md
Created October 3, 2023 09:43
Return await vs return promise

Result:

Error: whoops
    at last (/Users/adrien/projects/didask/odc/test.ts:43:9)
    at middle (/Users/adrien/projects/didask/odc/test.ts:47:16)
    at first (/Users/adrien/projects/didask/odc/test.ts:51:16)
    at run (/Users/adrien/projects/didask/odc/test.ts:56:11)
    at Object.<anonymous> (/Users/adrien/projects/didask/odc/test.ts:68:1)
 at Module._compile (node:internal/modules/cjs/loader:1256:14)
@Aschen
Aschen / README.md
Last active July 30, 2023 12:48
Performance differences for classification (BART) between Transformers.js and Transformers (Python)

Performance differences for classification (BART) between Transformers.js and Transformers (Python)

This is a GIST for this issue in Transformer.js repository

Trying to classify the following texts as street address:

  • '1 rue de la paix',
  • 'Karlstraße 12, 80333 Munich, DE',
  • 'Startups da América Latina demonstraram capacidade de gerar valor econômico diz fundo alemão',
  • "But what if one day, you come up with a great idea to combine those, for instance to use some Python libraries in your application, but you just do not have any idea how to integrate it with your Node.js application. Of course you can always build API on top of Python backend(Flack, etc), but in that case you need to build, host and manage one more application, when you just need to run a single Python script. That's why I want to give you step by step instructions on how to achieve this.\n",