viho 0.1.0 → 0.2.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/README.md +127 -29
- package/bin/viho-ask.js +2 -8
- package/bin/viho-chat.js +2 -8
- package/bin/viho-expert.js +2 -8
- package/bin/viho-model.js +77 -6
- package/package.json +3 -3
- package/src/experts/antd.md +23127 -0
- package/src/experts/experts.js +4 -0
- package/src/llm.js +30 -11
- package/src/util.js +37 -0
package/src/experts/experts.js
CHANGED
package/src/llm.js
CHANGED
|
@@ -31,17 +31,36 @@ exports.ask = async (llm, model, systemPrompt) => {
|
|
|
31
31
|
console.log(cli.colors.gray(answers.content));
|
|
32
32
|
console.log();
|
|
33
33
|
|
|
34
|
-
//
|
|
35
|
-
const
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
34
|
+
// model type
|
|
35
|
+
const modelType = model.modelType || 'openai';
|
|
36
|
+
|
|
37
|
+
// chat options based on model type
|
|
38
|
+
let chatOptions;
|
|
39
|
+
if (modelType === 'openai') {
|
|
40
|
+
chatOptions = {
|
|
41
|
+
model: model.modelID,
|
|
42
|
+
messages: [
|
|
43
|
+
{ role: 'system', content: systemPrompt || defaultSystemPrompt },
|
|
44
|
+
{ role: 'user', content: answers.content },
|
|
45
|
+
],
|
|
46
|
+
thinking: {
|
|
47
|
+
type: model.modelThinking,
|
|
48
|
+
},
|
|
49
|
+
};
|
|
50
|
+
} else if (modelType === 'gemini api' || modelType === 'gemini vertex') {
|
|
51
|
+
chatOptions = {
|
|
52
|
+
contents: [
|
|
53
|
+
{
|
|
54
|
+
role: 'user',
|
|
55
|
+
parts: [{ text: answers.content }],
|
|
56
|
+
},
|
|
57
|
+
],
|
|
58
|
+
};
|
|
59
|
+
// Add system instruction if provided
|
|
60
|
+
if (systemPrompt && systemPrompt !== defaultSystemPrompt) {
|
|
61
|
+
chatOptions.systemInstruction = systemPrompt;
|
|
62
|
+
}
|
|
63
|
+
}
|
|
45
64
|
|
|
46
65
|
// callback options
|
|
47
66
|
const callbackOptions = {
|
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
|
+
// llm
|
|
14
|
+
const { OpenAIAPI, GeminiAPI, GeminiVertex } = require('viho-llm');
|
|
15
|
+
|
|
13
16
|
// model
|
|
14
17
|
const { getModelByName } = require('./model.js');
|
|
15
18
|
|
|
@@ -58,3 +61,37 @@ exports.preLLMAsk = async (type, db, modelName) => {
|
|
|
58
61
|
// r
|
|
59
62
|
return model;
|
|
60
63
|
};
|
|
64
|
+
|
|
65
|
+
/**
|
|
66
|
+
* initLLM
|
|
67
|
+
* @param {*} model
|
|
68
|
+
* @returns
|
|
69
|
+
*/
|
|
70
|
+
exports.initLLM = (model) => {
|
|
71
|
+
const modelType = model.modelType || 'openai';
|
|
72
|
+
|
|
73
|
+
if (modelType === 'openai') {
|
|
74
|
+
return OpenAIAPI({
|
|
75
|
+
apiKey: model.apiKey,
|
|
76
|
+
baseURL: model.baseURL,
|
|
77
|
+
});
|
|
78
|
+
} else if (modelType === 'gemini api') {
|
|
79
|
+
return GeminiAPI({
|
|
80
|
+
apiKey: model.apiKey,
|
|
81
|
+
modelName: model.modelID, // Use modelID for API calls
|
|
82
|
+
});
|
|
83
|
+
} else if (modelType === 'gemini vertex') {
|
|
84
|
+
return GeminiVertex({
|
|
85
|
+
projectId: model.projectId,
|
|
86
|
+
location: model.location,
|
|
87
|
+
modelName: model.modelID, // Use modelID for API calls
|
|
88
|
+
});
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
// fallback to openai
|
|
92
|
+
console.log(cli.colors.yellow(`Unknown model type: ${modelType}, falling back to OpenAI`));
|
|
93
|
+
return OpenAIAPI({
|
|
94
|
+
apiKey: model.apiKey,
|
|
95
|
+
baseURL: model.baseURL,
|
|
96
|
+
});
|
|
97
|
+
};
|