viho 0.0.5 → 0.0.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/bin/viho-ask.js +6 -2
- package/bin/viho-chat.js +5 -2
- package/bin/viho-model.js +39 -16
- package/package.json +2 -2
- package/bin/util.js +0 -103
package/bin/viho-ask.js
CHANGED
|
@@ -5,7 +5,9 @@ const cli = require('qiao-cli');
|
|
|
5
5
|
const LLM = require('qiao-llm');
|
|
6
6
|
|
|
7
7
|
// util
|
|
8
|
-
const {
|
|
8
|
+
const { ask } = require('../src/llm.js');
|
|
9
|
+
const { getModels } = require('../src/model.js');
|
|
10
|
+
const { getDB, printLogo } = require('../src/util.js');
|
|
9
11
|
const db = getDB();
|
|
10
12
|
|
|
11
13
|
// cmd
|
|
@@ -24,7 +26,8 @@ cli.cmd
|
|
|
24
26
|
}
|
|
25
27
|
|
|
26
28
|
// check
|
|
27
|
-
const
|
|
29
|
+
const models = await getModels(db);
|
|
30
|
+
const model = models.find((m) => m.modelName === modelName);
|
|
28
31
|
if (!model) {
|
|
29
32
|
console.log(cli.colors.red(`Model not found: ${modelName}`));
|
|
30
33
|
return;
|
|
@@ -39,5 +42,6 @@ cli.cmd
|
|
|
39
42
|
// logo
|
|
40
43
|
printLogo();
|
|
41
44
|
|
|
45
|
+
// ask
|
|
42
46
|
await ask(llm, model);
|
|
43
47
|
});
|
package/bin/viho-chat.js
CHANGED
|
@@ -5,7 +5,9 @@ const cli = require('qiao-cli');
|
|
|
5
5
|
const LLM = require('qiao-llm');
|
|
6
6
|
|
|
7
7
|
// util
|
|
8
|
-
const {
|
|
8
|
+
const { ask } = require('../src/llm.js');
|
|
9
|
+
const { getModels } = require('../src/model.js');
|
|
10
|
+
const { getDB, printLogo } = require('../src/util.js');
|
|
9
11
|
const db = getDB();
|
|
10
12
|
|
|
11
13
|
// cmd
|
|
@@ -24,7 +26,8 @@ cli.cmd
|
|
|
24
26
|
}
|
|
25
27
|
|
|
26
28
|
// check
|
|
27
|
-
const
|
|
29
|
+
const models = await getModels(db);
|
|
30
|
+
const model = models.find((m) => m.modelName === modelName);
|
|
28
31
|
if (!model) {
|
|
29
32
|
console.log(cli.colors.red(`Model not found: ${modelName}`));
|
|
30
33
|
return;
|
package/bin/viho-model.js
CHANGED
|
@@ -2,7 +2,8 @@
|
|
|
2
2
|
const cli = require('qiao-cli');
|
|
3
3
|
|
|
4
4
|
// util
|
|
5
|
-
const {
|
|
5
|
+
const { getModels, setModels } = require('../src/model.js');
|
|
6
|
+
const { getDB, printLogo } = require('../src/util.js');
|
|
6
7
|
const db = getDB();
|
|
7
8
|
|
|
8
9
|
// actions
|
|
@@ -64,21 +65,23 @@ async function modelAdd() {
|
|
|
64
65
|
console.log();
|
|
65
66
|
|
|
66
67
|
// check
|
|
67
|
-
const
|
|
68
|
-
const
|
|
69
|
-
|
|
68
|
+
const modelName = answers.modelName;
|
|
69
|
+
const models = await getModels(db);
|
|
70
|
+
const isModelExists = models.some((model) => model.modelName === modelName);
|
|
71
|
+
if (isModelExists) {
|
|
70
72
|
console.log(cli.colors.red('Model name already exists'));
|
|
71
73
|
return;
|
|
72
74
|
}
|
|
73
75
|
|
|
74
76
|
// set
|
|
75
|
-
|
|
77
|
+
models.push(answers);
|
|
78
|
+
await setModels(db, models);
|
|
76
79
|
console.log(cli.colors.green('Model added'));
|
|
77
80
|
console.log();
|
|
78
81
|
|
|
79
82
|
// list
|
|
80
|
-
const
|
|
81
|
-
console.log(
|
|
83
|
+
const allModels = await getModels(db);
|
|
84
|
+
console.log(allModels);
|
|
82
85
|
} catch (e) {
|
|
83
86
|
console.log(cli.colors.red('Error: Failed to add model'));
|
|
84
87
|
console.log();
|
|
@@ -95,10 +98,10 @@ async function modelList() {
|
|
|
95
98
|
printLogo();
|
|
96
99
|
|
|
97
100
|
// list
|
|
98
|
-
const
|
|
101
|
+
const models = await getModels(db);
|
|
99
102
|
console.log(cli.colors.cyan('Configured models:'));
|
|
100
103
|
console.log();
|
|
101
|
-
console.log(
|
|
104
|
+
console.log(models);
|
|
102
105
|
} catch (e) {
|
|
103
106
|
console.log(cli.colors.red('Error: Failed to list models'));
|
|
104
107
|
console.log();
|
|
@@ -124,14 +127,34 @@ async function modelRemove() {
|
|
|
124
127
|
console.log();
|
|
125
128
|
|
|
126
129
|
// del
|
|
127
|
-
const
|
|
128
|
-
|
|
130
|
+
const models = await getModels(db);
|
|
131
|
+
const modelNameToRemove = answers.modelName;
|
|
132
|
+
|
|
133
|
+
// check if model exists
|
|
134
|
+
const modelExists = models.some((model) => model.modelName === modelNameToRemove);
|
|
135
|
+
if (!modelExists) {
|
|
136
|
+
console.log(cli.colors.red(`Model not found: ${modelNameToRemove}`));
|
|
137
|
+
console.log();
|
|
138
|
+
return;
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
const newModels = models.filter((model) => model.modelName !== modelNameToRemove);
|
|
142
|
+
await setModels(db, newModels);
|
|
143
|
+
|
|
144
|
+
// clear default if removed model was default
|
|
145
|
+
const defaultModel = await db.config('default');
|
|
146
|
+
if (defaultModel === modelNameToRemove) {
|
|
147
|
+
await db.config('default', null);
|
|
148
|
+
console.log(cli.colors.yellow('Removed model was set as default. Please set a new default.'));
|
|
149
|
+
console.log();
|
|
150
|
+
}
|
|
151
|
+
|
|
129
152
|
console.log(cli.colors.green('Model removed'));
|
|
130
153
|
console.log();
|
|
131
154
|
|
|
132
155
|
// list
|
|
133
|
-
const
|
|
134
|
-
console.log(
|
|
156
|
+
const allModels = await getModels(db);
|
|
157
|
+
console.log(allModels);
|
|
135
158
|
} catch (e) {
|
|
136
159
|
console.log(cli.colors.red('Error: Failed to remove model'));
|
|
137
160
|
console.log();
|
|
@@ -158,8 +181,8 @@ async function modelDefault() {
|
|
|
158
181
|
console.log();
|
|
159
182
|
|
|
160
183
|
// get keys
|
|
161
|
-
const
|
|
162
|
-
const keys =
|
|
184
|
+
const models = await getModels(db);
|
|
185
|
+
const keys = models.map((model) => model.modelName);
|
|
163
186
|
|
|
164
187
|
// check keys
|
|
165
188
|
if (!keys || !keys.length) {
|
|
@@ -172,7 +195,7 @@ async function modelDefault() {
|
|
|
172
195
|
if (!keys.includes(answers.modelName)) {
|
|
173
196
|
console.log(cli.colors.red('Model not found. Available models:'));
|
|
174
197
|
console.log();
|
|
175
|
-
console.log(
|
|
198
|
+
console.log(models);
|
|
176
199
|
return;
|
|
177
200
|
}
|
|
178
201
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "viho",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.6",
|
|
4
4
|
"description": "A lightweight CLI tool for managing and interacting with AI models",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"ai",
|
|
@@ -43,5 +43,5 @@
|
|
|
43
43
|
"qiao-config": "^5.0.1",
|
|
44
44
|
"qiao-llm": "^0.2.5"
|
|
45
45
|
},
|
|
46
|
-
"gitHead": "
|
|
46
|
+
"gitHead": "2a10a0acfc92501a023e93f7f268e6f8ad57f9fc"
|
|
47
47
|
}
|
package/bin/util.js
DELETED
|
@@ -1,103 +0,0 @@
|
|
|
1
|
-
// os
|
|
2
|
-
const os = require('os');
|
|
3
|
-
|
|
4
|
-
// path
|
|
5
|
-
const path = require('path');
|
|
6
|
-
|
|
7
|
-
// qiao
|
|
8
|
-
const cli = require('qiao-cli');
|
|
9
|
-
|
|
10
|
-
// db
|
|
11
|
-
const DB = require('qiao-config');
|
|
12
|
-
|
|
13
|
-
/**
|
|
14
|
-
* getDB
|
|
15
|
-
* @returns
|
|
16
|
-
*/
|
|
17
|
-
exports.getDB = () => {
|
|
18
|
-
const dbPath = path.resolve(os.homedir(), './viho.json');
|
|
19
|
-
return DB(dbPath);
|
|
20
|
-
};
|
|
21
|
-
|
|
22
|
-
/**
|
|
23
|
-
* printLogo
|
|
24
|
-
*/
|
|
25
|
-
exports.printLogo = () => {
|
|
26
|
-
console.log(
|
|
27
|
-
cli.colors.green(`
|
|
28
|
-
██╗ ██╗██╗██╗ ██╗ ██████╗
|
|
29
|
-
██║ ██║██║██║ ██║██╔═══██╗
|
|
30
|
-
██║ ██║██║███████║██║ ██║
|
|
31
|
-
╚██╗ ██╔╝██║██╔══██║██║ ██║
|
|
32
|
-
╚████╔╝ ██║██║ ██║╚██████╔╝
|
|
33
|
-
╚═══╝ ╚═╝╚═╝ ╚═╝ ╚═════╝
|
|
34
|
-
`),
|
|
35
|
-
);
|
|
36
|
-
};
|
|
37
|
-
|
|
38
|
-
/**
|
|
39
|
-
* ask
|
|
40
|
-
* @param {*} llm
|
|
41
|
-
* @param {*} model
|
|
42
|
-
*/
|
|
43
|
-
exports.ask = async (llm, model) => {
|
|
44
|
-
// ask
|
|
45
|
-
const questions = [
|
|
46
|
-
{
|
|
47
|
-
type: 'editor',
|
|
48
|
-
name: 'content',
|
|
49
|
-
message: 'Your question:',
|
|
50
|
-
},
|
|
51
|
-
];
|
|
52
|
-
const answers = await cli.ask(questions);
|
|
53
|
-
|
|
54
|
-
// answers
|
|
55
|
-
console.log();
|
|
56
|
-
console.log(cli.colors.gray('Question:'));
|
|
57
|
-
console.log(cli.colors.gray(answers.content));
|
|
58
|
-
console.log();
|
|
59
|
-
|
|
60
|
-
// chat
|
|
61
|
-
const chatOptions = {
|
|
62
|
-
model: model.modelID,
|
|
63
|
-
messages: [
|
|
64
|
-
{ role: 'system', content: 'You are a helpful AI assistant' },
|
|
65
|
-
{ role: 'user', content: answers.content },
|
|
66
|
-
],
|
|
67
|
-
thinking: {
|
|
68
|
-
type: model.modelThinking,
|
|
69
|
-
},
|
|
70
|
-
};
|
|
71
|
-
|
|
72
|
-
// callback options
|
|
73
|
-
const callbackOptions = {
|
|
74
|
-
firstThinkingCallback: () => {
|
|
75
|
-
console.log();
|
|
76
|
-
console.log(cli.colors.gray('[Thinking...]'));
|
|
77
|
-
console.log();
|
|
78
|
-
},
|
|
79
|
-
thinkingCallback: (msg) => {
|
|
80
|
-
process.stdout.write(cli.colors.gray(msg));
|
|
81
|
-
},
|
|
82
|
-
firstContentCallback: () => {
|
|
83
|
-
console.log();
|
|
84
|
-
console.log(cli.colors.cyan('[Response]'));
|
|
85
|
-
console.log();
|
|
86
|
-
},
|
|
87
|
-
contentCallback: (msg) => {
|
|
88
|
-
process.stdout.write(msg);
|
|
89
|
-
},
|
|
90
|
-
endCallback: () => {
|
|
91
|
-
console.log();
|
|
92
|
-
console.log();
|
|
93
|
-
},
|
|
94
|
-
errorCallback: (error) => {
|
|
95
|
-
console.log();
|
|
96
|
-
console.log(cli.colors.red('Error:'));
|
|
97
|
-
console.log(error);
|
|
98
|
-
},
|
|
99
|
-
};
|
|
100
|
-
|
|
101
|
-
// go
|
|
102
|
-
await llm.chatWithStreaming(chatOptions, callbackOptions);
|
|
103
|
-
};
|