-
Notifications
You must be signed in to change notification settings - Fork 136
/
Copy pathindex.ts
77 lines (65 loc) · 2.26 KB
/
index.ts
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
70
71
72
73
74
75
76
77
import ollama from "ollama";
import inquirer, { QuestionCollection} from "inquirer";
const qrepeat = 5;
const allmodels = await ollama.list();
function processModelNames(
allmodels: { name: string; details: { parameter_size: string } }[],
) {
// Extract names and process
const names = allmodels
.map((model) => `${model.name}:${model.details.parameter_size}`)
.map((name) => {
const splitname = name.split(":")
return `${splitname[0]} - ${splitname[2]}`
} )
.filter((value, index, self) => self.indexOf(value) === index)
.sort();
return names;
}
async function getSelectedModel(names: string[]) {
const questions: QuestionCollection = [
{
type: "list",
name: "selectedName",
message: "Select a model name:",
choices: names,
},
];
const answer = await inquirer.prompt(questions);
return answer.selectedName;
}
async function getSelectedQuants(name: string, size: string, allmodels: { name: string, details: { parameter_size: string, quantization_level: string}}[]) {
const modelNames = allmodels.filter((model) => model.name.split(":")[0] === name && model.details.parameter_size === size).map((model) => model.name);
return modelNames;
}
async function getUserPrompt(): Promise<string> {
const questions: QuestionCollection = [
{
type: "input",
name: "userPrompt",
message: "Enter a prompt you want to test:",
},
];
const answer = await inquirer.prompt(questions);
return answer.userPrompt;
}
const names = processModelNames(allmodels.models);
const selected = await getSelectedModel(names);
const modelName = selected.split(" - ")[0];
const selectedSize = selected.split(" - ")[1];
const quants = await getSelectedQuants(modelName, selectedSize, allmodels.models);
const userPrompt = await getUserPrompt();
for (const quant of quants) {
for (let index = 0; index < qrepeat; index++) {
let format = ""
if (userPrompt.toLowerCase().includes("json")) {
format = "json"
}
const output = await ollama.generate({model: quant, prompt: userPrompt, format: format});
console.log(`\n${quant} round ${index + 1}:\n${output.response}\nGenerated in ${(output.eval_duration / 1000000000).toFixed(2)} seconds\n`);
if (index < qrepeat - 1) {
console.log('--------\n');
}
}
console.log('========\n');
}