aico-ai 1.0.7 → 1.0.9
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/index.js +9 -1
- package/lib/ai-service.js +22 -13
- package/package.json +1 -1
package/index.js
CHANGED
|
@@ -46,10 +46,18 @@ async function init() {
|
|
|
46
46
|
config.providers[provider].apiKey = apiKey;
|
|
47
47
|
}
|
|
48
48
|
|
|
49
|
+
const defaultModels = {
|
|
50
|
+
groq: 'llama-3.3-70b-versatile',
|
|
51
|
+
openai: 'gpt-4o-mini',
|
|
52
|
+
deepseek: 'deepseek-chat',
|
|
53
|
+
ollama: 'llama3',
|
|
54
|
+
gemini: 'gemini-1.5-flash'
|
|
55
|
+
};
|
|
56
|
+
|
|
49
57
|
const { model } = await prompt({
|
|
50
58
|
type: 'input',
|
|
51
59
|
name: 'model',
|
|
52
|
-
message:
|
|
60
|
+
message: `Model name (default: ${defaultModels[provider]}):`,
|
|
53
61
|
initial: ''
|
|
54
62
|
});
|
|
55
63
|
if (model) config.providers[provider].model = model;
|
package/lib/ai-service.js
CHANGED
|
@@ -9,7 +9,11 @@ dotenv.config();
|
|
|
9
9
|
*/
|
|
10
10
|
class AIClient {
|
|
11
11
|
constructor() {
|
|
12
|
-
this.
|
|
12
|
+
this.client = null;
|
|
13
|
+
this.provider = null;
|
|
14
|
+
this.apiKey = null;
|
|
15
|
+
this.model = null;
|
|
16
|
+
this.baseUrl = null;
|
|
13
17
|
}
|
|
14
18
|
|
|
15
19
|
updateConfig() {
|
|
@@ -19,8 +23,17 @@ class AIClient {
|
|
|
19
23
|
this.model = model || this.getDefaultModel(provider);
|
|
20
24
|
this.baseUrl = baseUrl;
|
|
21
25
|
|
|
26
|
+
if (!apiKey && provider !== 'ollama') {
|
|
27
|
+
this.client = null;
|
|
28
|
+
return;
|
|
29
|
+
}
|
|
30
|
+
|
|
22
31
|
if (provider === 'groq') {
|
|
23
|
-
|
|
32
|
+
try {
|
|
33
|
+
this.client = new Groq({ apiKey });
|
|
34
|
+
} catch (e) {
|
|
35
|
+
this.client = null;
|
|
36
|
+
}
|
|
24
37
|
} else if (provider === 'openai' || provider === 'deepseek' || provider === 'ollama') {
|
|
25
38
|
// OpenAI compatible APIs
|
|
26
39
|
const url = provider === 'ollama' ? (baseUrl || 'http://localhost:11434/v1') :
|
|
@@ -63,18 +76,14 @@ class AIClient {
|
|
|
63
76
|
async createChatCompletion(messages) {
|
|
64
77
|
if (!this.client) this.updateConfig();
|
|
65
78
|
|
|
66
|
-
if (this.
|
|
67
|
-
|
|
68
|
-
messages,
|
|
69
|
-
model: this.model,
|
|
70
|
-
});
|
|
71
|
-
} else {
|
|
72
|
-
// OpenAI compatible
|
|
73
|
-
return this.client.chat.completions.create({
|
|
74
|
-
messages,
|
|
75
|
-
model: this.model,
|
|
76
|
-
});
|
|
79
|
+
if (!this.client) {
|
|
80
|
+
throw new Error(`AI Client for ${this.provider} could not be initialized. Check your API Key.`);
|
|
77
81
|
}
|
|
82
|
+
|
|
83
|
+
return this.client.chat.completions.create({
|
|
84
|
+
messages,
|
|
85
|
+
model: this.model,
|
|
86
|
+
});
|
|
78
87
|
}
|
|
79
88
|
}
|
|
80
89
|
|