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.
@@ -1,4 +1,8 @@
1
1
  exports.experts = [
2
+ {
3
+ name: 'antd',
4
+ url: 'https://ant.design/llms-full.txt',
5
+ },
2
6
  {
3
7
  name: 'daisyui',
4
8
  url: 'https://daisyui.com/llms.txt',
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
- // chat
35
- const chatOptions = {
36
- model: model.modelID,
37
- messages: [
38
- { role: 'system', content: systemPrompt || defaultSystemPrompt },
39
- { role: 'user', content: answers.content },
40
- ],
41
- thinking: {
42
- type: model.modelThinking,
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
+ };