-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathaddembed.js
More file actions
28 lines (24 loc) · 892 Bytes
/
addembed.js
File metadata and controls
28 lines (24 loc) · 892 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
import { getEmbed } from "./getEmbed.js";
import { CSV } from "https://js.sabae.cc/CSV.js";
import { IEEE32 } from "https://code4fukui.github.io/IEEE754/IEEE32.js";
import { Base64URL } from "https://code4fukui.github.io/Base64URL/Base64URL.js";
const fn = Deno.args[0] || "./data.txt";
const data = (await Deno.readTextFile(fn)).split("\n");
const format = Deno.args[1] || "base64"; // "json";
const convert = (format, array) => {
if (format == "json") {
return array.join(",");
} else if (format == "base64") {
return Base64URL.encode(IEEE32.encode(array));
} else {
throw new Error("unknown format: " + format);
}
};
const list = [];
for (const item of data) {
if (!item) continue;
const res = await getEmbed(item);
console.log(item, res);
list.push({ text: item, vec: convert(format, res) });
await Deno.writeTextFile("data.csv", CSV.stringify(list));
}