-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
69 lines (61 loc) · 1.88 KB
/
index.js
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
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
const {
SENTENCE_FILE_PATH,
FORMULAIC_API_KEY,
FORMULAIC_API_URL,
FORMULAIC_FORMULA_ID,
LLAMAFILE_API_KEY,
LLAMAFILE_API_URL,
} = require("./config");
const { SentenceData, ModelData } = require("./DataClasses");
const { readData } = require("./DataReader");
const SentenceDomainRepository = require("./SentenceDomainRepository");
const {
SentenceDomainService,
FormulaicProvider,
LlamaFileProvider,
} = require("./SentenceService");
const main = async () => {
const db = new SentenceDomainRepository("cv-sentence.db"); // Pass db path
// await initializeDatabase(db);
const fileData = await readData(SENTENCE_FILE_PATH);
const SENTENCES = fileData.map((record) => {
if (!record.sentence) {
throw new Error("Sentence value is required");
}
return new SentenceData(record.sentence, record.sentence_domain);
});
const formulaicProvider = new FormulaicProvider(
FORMULAIC_API_KEY,
FORMULAIC_API_URL
);
const llamaFileProvider = new LlamaFileProvider(
LLAMAFILE_API_KEY,
LLAMAFILE_API_URL
);
const models = await formulaicProvider.getModels();
const formulaId = FORMULAIC_FORMULA_ID;
console.log("models", models);
for (const model of models) {
const provider = formulaicProvider;
const sentenceDomainService = new SentenceDomainService(provider);
for (const sentence of SENTENCES) {
// check if the sentence already exists in the database
const existingSentence = await db.getSentence(sentence.value, model.id);
if (existingSentence) {
console.log("Sentence/model already exists: ");
continue;
}
try {
const computedDomain = await sentenceDomainService.getSentenceDomain(
sentence,
model,
formulaId
);
} catch (error) {
console.error("Error getting sentence domain:", error);
}
}
}
db.close();
};
main();