-
Notifications
You must be signed in to change notification settings - Fork 0
/
command_line_generator.html
151 lines (128 loc) · 7.79 KB
/
command_line_generator.html
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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Llama.cpp Control Vector Command Generator</title>
<script src="https://cdn.tailwindcss.com"></script>
</head>
<body class="bg-gray-100 p-8">
<div class="max-w-4xl mx-auto bg-white p-6 rounded-lg shadow-md">
<h1 class="text-2xl font-bold mb-4 text-center">Llama.cpp Control Vector Command Line Generator</h1>
<div class="mb-4 flex items-center">
<label for="controlVectorPath" class="block mr-4">Control Vector Path:</label>
<input type="text" id="controlVectorPath" class="flex-1 p-2 border rounded" placeholder="/path/to/vectors">
</div>
<div class="mb-4 flex items-center">
<label for="modelVectorName" class="block mr-4">Model Vector Name:</label>
<input type="text" id="modelVectorName" class="flex-1 p-2 border rounded" placeholder="e.g., wizard-lm-2:8x22b">
</div>
<div id="sliders" class="space-y-4"></div>
<div class="mt-6">
<h2 class="text-xl font-semibold mb-2">Generated Command:</h2>
<pre id="output" class="bg-gray-200 p-4 rounded overflow-x-auto whitespace-pre-wrap"></pre>
</div>
</div>
<script>
const controlVectors = [
{ category: "Writing Style", display_name: "Language (Simple vs Ornate)", name: "language", options: ["simple", "ornate"] },
{ category: "Writing Style", display_name: "Storytelling (Explicit vs Descriptive)", name: "storytelling", options: ["explicit", "descriptive"] },
{ category: "Writing Style", display_name: "Character Focus (Narration vs Dialogue)", name: "character_focus", options: ["narration", "dialogue"] },
{ category: "Dark Tetrad", display_name: "Empathy vs Sociopathy", name: "empathy_vs_sociopathy", options: ["empathy", "sociopathy"] },
{ category: "Dark Tetrad", display_name: "Humility vs Narcissism", name: "humility_vs_narcissism", options: ["humility", "narcissism"] },
{ category: "Dark Tetrad", display_name: "Honesty vs Machiavellianism", name: "honesty_vs_machiavellianism", options: ["honesty", "machiavellianism"] },
{ category: "Dark Tetrad", display_name: "Compassion vs Sadism", name: "compassion_vs_sadism", options: ["compassion", "sadism"] },
{ category: "Other", display_name: "Optimism vs Nihilism", name: "optimism_vs_nihilism", options: ["optimism", "nihilism"] }
];
const slidersContainer = document.getElementById('sliders');
const categories = {};
const outputElement = document.getElementById('output');
const controlVectorPathInput = document.getElementById('controlVectorPath');
const modelVectorNameInput = document.getElementById('modelVectorName');
controlVectors.forEach(vector => {
if (!categories[vector.category]) {
const categoryContainer = document.createElement('div');
categoryContainer.classList.add("mb-6", "p-4", "border", "border-gray-300", "rounded");
const categoryTitle = document.createElement('h3');
categoryTitle.textContent = vector.category;
categoryTitle.classList.add("text-lg", "font-bold", "mb-4");
categoryContainer.appendChild(categoryTitle);
slidersContainer.appendChild(categoryContainer);
categories[vector.category] = categoryContainer;
}
const sliderContainer = document.createElement('div');
sliderContainer.innerHTML = `
<div class="flex items-center mb-2">
<input type="checkbox" id="${vector.name}-active" class="mr-2" onchange="updateOutput()">
<label class="mr-4">${vector.display_name}</label>
<span id="${vector.name}-value" class="ml-auto">0</span>
<button id="${vector.name}-reset" class="ml-2 px-2 py-1 bg-gray-200 rounded" onclick="resetSlider('${vector.name}')">Reset</button>
</div>
<input type="range" min="-100" max="100" value="0" class="w-full"
id="${vector.name}" oninput="updateSliderValue('${vector.name}')">
`;
categories[vector.category].appendChild(sliderContainer);
});
function updateSliderValue(vectorName) {
const slider = document.getElementById(vectorName);
const value = parseFloat(slider.value) / 100;
document.getElementById(`${vectorName}-value`).textContent = value.toFixed(2);
updateOutput();
}
function resetSlider(vectorName) {
const slider = document.getElementById(vectorName);
slider.value = 0;
document.getElementById(`${vectorName}-value`).textContent = '0';
updateOutput();
}
function updateOutput() {
const controlVectorPath = controlVectorPathInput.value.trim();
const modelVectorName = modelVectorNameInput.value.trim();
let command = '';
controlVectors.forEach(vector => {
const isActive = document.getElementById(`${vector.name}-active`).checked;
const slider = document.getElementById(vector.name);
const sliderValueDisplay = document.getElementById(`${vector.name}-value`);
const resetButton = document.getElementById(`${vector.name}-reset`);
// Enable or disable the slider and reset button based on checkbox state
slider.disabled = !isActive;
resetButton.disabled = !isActive;
sliderValueDisplay.style.opacity = isActive ? '1' : '0.5'; // Dim the value display when disabled
if (!isActive) return;
const value = parseFloat(slider.value) / 100;
const formattedPath = controlVectorPath ? `${controlVectorPath}/` : "";
const modelName = modelVectorName || "XXXXX";
command += `--control-vector ${formattedPath}${modelName}-${vector.name}__debias.gguf \\\n`;
if (value !== 0) {
const option = value > 0 ? vector.options[1] : vector.options[0];
const absValue = Math.abs(value);
if (Math.abs(absValue - 1.0) < 0.005) {
command += `--control-vector ${formattedPath}${modelName}-${vector.name}__${option}.gguf \\\n`;
} else {
command += `--control-vector-scaled ${formattedPath}${modelName}-${vector.name}__${option}.gguf ${absValue.toFixed(2)} \\\n`;
}
}
});
// Check if the last character is a backslash and remove it
if (command.endsWith("\\\n")) {
command = command.slice(0, -2);
}
outputElement.textContent = command ? command.trim() : 'No control vectors selected';
}
// Set initial state of sliders based on checkbox state
document.addEventListener('DOMContentLoaded', () => {
controlVectors.forEach(vector => {
const isActive = document.getElementById(`${vector.name}-active`).checked;
const slider = document.getElementById(vector.name);
const resetButton = document.getElementById(`${vector.name}-reset`);
slider.disabled = !isActive;
resetButton.disabled = !isActive;
});
updateOutput();
});
controlVectorPathInput.addEventListener('input', updateOutput);
modelVectorNameInput.addEventListener('input', updateOutput);
updateOutput();
</script>
</body>
</html>