8
8
</ head >
9
9
< body class ="bg-gray-100 p-8 ">
10
10
< div class ="max-w-4xl mx-auto bg-white p-6 rounded-lg shadow-md ">
11
- < h1 class ="text-2xl font-bold mb-4 "> Llama.cpp Control Vector Command Generator</ h1 >
11
+ < h1 class ="text-2xl font-bold mb-4 text-center "> Llama.cpp Control Vector Command Line Generator</ h1 >
12
12
13
- < div class ="mb-4 ">
14
- < label for ="controlVectorPath " class ="block mb-2 "> Control Vector Path:</ label >
15
- < input type ="text " id ="controlVectorPath " class ="w-full p-2 border rounded " placeholder ="/path/to/control /vectors ">
13
+ < div class ="mb-4 flex items-center ">
14
+ < label for ="controlVectorPath " class ="block mr-4 "> Control Vector Path:</ label >
15
+ < input type ="text " id ="controlVectorPath " class ="flex-1 p-2 border rounded " placeholder ="/path/to/vectors ">
16
16
</ div >
17
-
18
- < div class ="mb-4 ">
19
- < label for ="modelVectorName " class ="block mb-2 "> Model Vector Name:</ label >
20
- < input type ="text " id ="modelVectorName " class ="w-full p-2 border rounded " placeholder ="e.g., wizard-lm-2:8x22b ">
17
+
18
+ < div class ="mb-4 flex items-center ">
19
+ < label for ="modelVectorName " class ="block mr-4 "> Model Vector Name:</ label >
20
+ < input type ="text " id ="modelVectorName " class ="flex-1 p-2 border rounded " placeholder ="e.g., wizard-lm-2:8x22b ">
21
21
</ div >
22
22
23
23
< div id ="sliders " class ="space-y-4 "> </ div >
@@ -30,76 +30,120 @@ <h2 class="text-xl font-semibold mb-2">Generated Command:</h2>
30
30
31
31
< script >
32
32
const controlVectors = [
33
- { name : "character_focus " , options : [ "dialogue " , "narration " ] } ,
34
- { name : "compassion_vs_sadism " , options : [ "compassion " , "sadism " ] } ,
35
- { name : "empathy_vs_sociopathy " , options : [ "empathy " , "sociopathy " ] } ,
36
- { name : "honesty_vs_machiavellianism " , options : [ "honesty " , "machiavellianism " ] } ,
37
- { name : "humility_vs_narcissism" , options : [ "humility" , "narcissism" ] } ,
38
- { name : "language " , options : [ "ornate " , "simple " ] } ,
39
- { name : "optimism_vs_nihilism " , options : [ "optimism " , "nihilism " ] } ,
40
- { name : "storytelling " , options : [ "descriptive " , "explicit " ] }
33
+ { category : "Writing Style" , display_name : "Language (Simple vs Ornate)" , name : "language " , options : [ "simple " , "ornate " ] } ,
34
+ { category : "Writing Style" , display_name : "Storytelling (Explicit vs Descriptive)" , name : "storytelling " , options : [ "explicit " , "descriptive " ] } ,
35
+ { category : "Writing Style" , display_name : "Character Focus (Narration vs Dialogue)" , name : "character_focus " , options : [ "narration " , "dialogue " ] } ,
36
+ { category : "Dark Tetrad" , display_name : "Empathy vs Sociopathy" , name : "empathy_vs_sociopathy " , options : [ "empathy " , "sociopathy " ] } ,
37
+ { category : "Dark Tetrad" , display_name : "Humility vs Narcissism" , name : "humility_vs_narcissism" , options : [ "humility" , "narcissism" ] } ,
38
+ { category : "Dark Tetrad" , display_name : "Honesty vs Machiavellianism" , name : "honesty_vs_machiavellianism " , options : [ "honesty " , "machiavellianism " ] } ,
39
+ { category : "Dark Tetrad" , display_name : "Compassion vs Sadism" , name : "compassion_vs_sadism " , options : [ "compassion " , "sadism " ] } ,
40
+ { category : "Other" , display_name : "Optimism vs Nihilism" , name : "optimism_vs_nihilism " , options : [ "optimism " , "nihilism " ] }
41
41
] ;
42
42
43
43
const slidersContainer = document . getElementById ( 'sliders' ) ;
44
+ const categories = { } ;
44
45
const outputElement = document . getElementById ( 'output' ) ;
45
46
const controlVectorPathInput = document . getElementById ( 'controlVectorPath' ) ;
46
47
const modelVectorNameInput = document . getElementById ( 'modelVectorName' ) ;
47
-
48
+
48
49
controlVectors . forEach ( vector => {
50
+ if ( ! categories [ vector . category ] ) {
51
+ const categoryContainer = document . createElement ( 'div' ) ;
52
+ categoryContainer . classList . add ( "mb-6" , "p-4" , "border" , "border-gray-300" , "rounded" ) ;
53
+ const categoryTitle = document . createElement ( 'h3' ) ;
54
+ categoryTitle . textContent = vector . category ;
55
+ categoryTitle . classList . add ( "text-lg" , "font-bold" , "mb-4" ) ;
56
+ categoryContainer . appendChild ( categoryTitle ) ;
57
+ slidersContainer . appendChild ( categoryContainer ) ;
58
+ categories [ vector . category ] = categoryContainer ;
59
+ }
60
+
49
61
const sliderContainer = document . createElement ( 'div' ) ;
50
62
sliderContainer . innerHTML = `
51
63
<div class="flex items-center mb-2">
52
64
<input type="checkbox" id="${ vector . name } -active" class="mr-2" onchange="updateOutput()">
53
- <label class="mr-4">${ vector . name . replace ( / _ / g , ' ' ) } </label>
65
+ <label class="mr-4">${ vector . display_name } </label>
54
66
<span id="${ vector . name } -value" class="ml-auto">0</span>
55
67
<button id="${ vector . name } -reset" class="ml-2 px-2 py-1 bg-gray-200 rounded" onclick="resetSlider('${ vector . name } ')">Reset</button>
56
68
</div>
57
69
<input type="range" min="-100" max="100" value="0" class="w-full"
58
70
id="${ vector . name } " oninput="updateSliderValue('${ vector . name } ')">
59
71
` ;
60
- slidersContainer . appendChild ( sliderContainer ) ;
72
+ categories [ vector . category ] . appendChild ( sliderContainer ) ;
61
73
} ) ;
62
74
63
75
function updateSliderValue ( vectorName ) {
64
- const slider = document . getElementById ( vectorName ) ;
65
- const value = parseFloat ( slider . value ) / 100 ;
66
- document . getElementById ( `${ vectorName } -value` ) . textContent = value . toFixed ( 2 ) ;
67
- updateOutput ( ) ;
68
- }
69
-
70
- function resetSlider ( vectorName ) {
71
- const slider = document . getElementById ( vectorName ) ;
72
- slider . value = 0 ;
73
- document . getElementById ( `${ vectorName } -value` ) . textContent = '0' ;
74
- updateOutput ( ) ;
75
- }
76
-
77
- function updateOutput ( ) {
78
- const controlVectorPath = controlVectorPathInput . value . trim ( ) ;
79
- const modelVectorName = modelVectorNameInput . value . trim ( ) ;
80
- let command = '' ;
81
-
82
- controlVectors . forEach ( vector => {
83
- const isActive = document . getElementById ( `${ vector . name } -active` ) . checked ;
84
- if ( ! isActive ) return ;
85
-
86
- const slider = document . getElementById ( vector . name ) ;
87
- const value = parseFloat ( slider . value ) / 100 ;
88
-
89
- command += `--control-vector ${ controlVectorPath } /${ modelVectorName } -${ vector . name } __debias.gguf \\\n` ;
90
-
91
- if ( value !== 0 ) {
92
- const option = value > 0 ? vector . options [ 0 ] : vector . options [ 1 ] ;
93
- const absValue = Math . abs ( value ) ;
94
- command += `--control-vector-scaled ${ controlVectorPath } /${ modelVectorName } -${ vector . name } __${ option } .gguf ${ absValue . toFixed ( 2 ) } \\\n` ;
95
- }
96
- } ) ;
97
-
98
- outputElement . textContent = command ? command . trim ( ) : 'No control vectors selected' ;
99
- }
100
-
101
- controlVectorPathInput . addEventListener ( 'input' , updateOutput ) ;
102
- modelVectorNameInput . addEventListener ( 'input' , updateOutput ) ;
76
+ const slider = document . getElementById ( vectorName ) ;
77
+ const value = parseFloat ( slider . value ) / 100 ;
78
+ document . getElementById ( `${ vectorName } -value` ) . textContent = value . toFixed ( 2 ) ;
79
+ updateOutput ( ) ;
80
+ }
81
+
82
+ function resetSlider ( vectorName ) {
83
+ const slider = document . getElementById ( vectorName ) ;
84
+ slider . value = 0 ;
85
+ document . getElementById ( `${ vectorName } -value` ) . textContent = '0' ;
86
+ updateOutput ( ) ;
87
+ }
88
+
89
+ function updateOutput ( ) {
90
+ const controlVectorPath = controlVectorPathInput . value . trim ( ) ;
91
+ const modelVectorName = modelVectorNameInput . value . trim ( ) ;
92
+ let command = '' ;
93
+
94
+ controlVectors . forEach ( vector => {
95
+ const isActive = document . getElementById ( `${ vector . name } -active` ) . checked ;
96
+ const slider = document . getElementById ( vector . name ) ;
97
+ const sliderValueDisplay = document . getElementById ( `${ vector . name } -value` ) ;
98
+ const resetButton = document . getElementById ( `${ vector . name } -reset` ) ;
99
+
100
+ // Enable or disable the slider and reset button based on checkbox state
101
+ slider . disabled = ! isActive ;
102
+ resetButton . disabled = ! isActive ;
103
+ sliderValueDisplay . style . opacity = isActive ? '1' : '0.5' ; // Dim the value display when disabled
104
+
105
+ if ( ! isActive ) return ;
106
+
107
+ const value = parseFloat ( slider . value ) / 100 ;
108
+ const formattedPath = controlVectorPath ? `${ controlVectorPath } /` : "" ;
109
+ const modelName = modelVectorName || "XXXXX" ;
110
+
111
+ command += `--control-vector ${ formattedPath } ${ modelName } -${ vector . name } __debias.gguf \\\n` ;
112
+
113
+ if ( value !== 0 ) {
114
+ const option = value > 0 ? vector . options [ 1 ] : vector . options [ 0 ] ;
115
+ const absValue = Math . abs ( value ) ;
116
+
117
+ if ( Math . abs ( absValue - 1.0 ) < 0.005 ) {
118
+ command += `--control-vector ${ formattedPath } ${ modelName } -${ vector . name } __${ option } .gguf \\\n` ;
119
+ } else {
120
+ command += `--control-vector-scaled ${ formattedPath } ${ modelName } -${ vector . name } __${ option } .gguf ${ absValue . toFixed ( 2 ) } \\\n` ;
121
+ }
122
+ }
123
+ } ) ;
124
+
125
+ // Check if the last character is a backslash and remove it
126
+ if ( command . endsWith ( "\\\n" ) ) {
127
+ command = command . slice ( 0 , - 2 ) ;
128
+ }
129
+
130
+ outputElement . textContent = command ? command . trim ( ) : 'No control vectors selected' ;
131
+ }
132
+
133
+ // Set initial state of sliders based on checkbox state
134
+ document . addEventListener ( 'DOMContentLoaded' , ( ) => {
135
+ controlVectors . forEach ( vector => {
136
+ const isActive = document . getElementById ( `${ vector . name } -active` ) . checked ;
137
+ const slider = document . getElementById ( vector . name ) ;
138
+ const resetButton = document . getElementById ( `${ vector . name } -reset` ) ;
139
+ slider . disabled = ! isActive ;
140
+ resetButton . disabled = ! isActive ;
141
+ } ) ;
142
+ updateOutput ( ) ;
143
+ } ) ;
144
+
145
+ controlVectorPathInput . addEventListener ( 'input' , updateOutput ) ;
146
+ modelVectorNameInput . addEventListener ( 'input' , updateOutput ) ;
103
147
104
148
updateOutput ( ) ;
105
149
</ script >
0 commit comments