viho 0.0.8 → 0.1.0
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 +3 -8
- package/bin/viho-chat.js +3 -10
- package/bin/viho-expert.js +78 -0
- package/bin/viho-model.js +1 -1
- package/bin/viho-version.js +4 -1
- package/bin/viho.js +9 -0
- package/package.json +3 -2
- package/src/experts/daisyui.md +2228 -0
- package/src/experts/experts.js +6 -0
- package/src/llm.js +25 -2
- package/src/util.js +24 -0
package/src/llm.js
CHANGED
|
@@ -1,12 +1,20 @@
|
|
|
1
|
+
// path
|
|
2
|
+
const path = require('path');
|
|
3
|
+
|
|
1
4
|
// qiao
|
|
2
5
|
const cli = require('qiao-cli');
|
|
6
|
+
const { readFile } = require('qiao-file');
|
|
7
|
+
|
|
8
|
+
// prompt
|
|
9
|
+
const defaultSystemPrompt = 'You are a helpful AI assistant';
|
|
3
10
|
|
|
4
11
|
/**
|
|
5
12
|
* ask
|
|
6
13
|
* @param {*} llm
|
|
7
14
|
* @param {*} model
|
|
15
|
+
* @param {*} systemPrompt
|
|
8
16
|
*/
|
|
9
|
-
exports.ask = async (llm, model) => {
|
|
17
|
+
exports.ask = async (llm, model, systemPrompt) => {
|
|
10
18
|
// ask
|
|
11
19
|
const questions = [
|
|
12
20
|
{
|
|
@@ -27,7 +35,7 @@ exports.ask = async (llm, model) => {
|
|
|
27
35
|
const chatOptions = {
|
|
28
36
|
model: model.modelID,
|
|
29
37
|
messages: [
|
|
30
|
-
{ role: 'system', content:
|
|
38
|
+
{ role: 'system', content: systemPrompt || defaultSystemPrompt },
|
|
31
39
|
{ role: 'user', content: answers.content },
|
|
32
40
|
],
|
|
33
41
|
thinking: {
|
|
@@ -67,3 +75,18 @@ exports.ask = async (llm, model) => {
|
|
|
67
75
|
// go
|
|
68
76
|
await llm.chatWithStreaming(chatOptions, callbackOptions);
|
|
69
77
|
};
|
|
78
|
+
|
|
79
|
+
/**
|
|
80
|
+
* expertAsk
|
|
81
|
+
* @param {*} llm
|
|
82
|
+
* @param {*} model
|
|
83
|
+
* @param {*} expertName
|
|
84
|
+
*/
|
|
85
|
+
exports.expertAsk = async (llm, model, expertName) => {
|
|
86
|
+
// llms.txt
|
|
87
|
+
const txtPath = path.resolve(__dirname, `./experts/${expertName}.md`);
|
|
88
|
+
const txtContent = await readFile(txtPath);
|
|
89
|
+
|
|
90
|
+
const systemPrompt = `${defaultSystemPrompt}. You are an expert on ${expertName}. Use the following documentation to answer questions:\n\n${txtContent}`;
|
|
91
|
+
await exports.ask(llm, model, systemPrompt);
|
|
92
|
+
};
|
package/src/util.js
CHANGED
|
@@ -10,6 +10,9 @@ const cli = require('qiao-cli');
|
|
|
10
10
|
// db
|
|
11
11
|
const DB = require('qiao-config');
|
|
12
12
|
|
|
13
|
+
// model
|
|
14
|
+
const { getModelByName } = require('./model.js');
|
|
15
|
+
|
|
13
16
|
/**
|
|
14
17
|
* getDB
|
|
15
18
|
* @returns
|
|
@@ -34,3 +37,24 @@ exports.printLogo = () => {
|
|
|
34
37
|
`),
|
|
35
38
|
);
|
|
36
39
|
};
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
* preLLMAsk
|
|
43
|
+
* @param {*} type
|
|
44
|
+
* @param {*} db
|
|
45
|
+
* @param {*} modelName
|
|
46
|
+
* @returns
|
|
47
|
+
*/
|
|
48
|
+
exports.preLLMAsk = async (type, db, modelName) => {
|
|
49
|
+
// model
|
|
50
|
+
const model = await getModelByName(db, modelName);
|
|
51
|
+
if (!model) return;
|
|
52
|
+
|
|
53
|
+
// logo
|
|
54
|
+
exports.printLogo();
|
|
55
|
+
console.log(cli.colors.cyan(`Welcome to viho ${type}! Using model: ${model.modelName}`));
|
|
56
|
+
console.log(cli.colors.gray('Press Ctrl+C to exit\n'));
|
|
57
|
+
|
|
58
|
+
// r
|
|
59
|
+
return model;
|
|
60
|
+
};
|