@atlisp/agent 0.1.14 → 0.1.15
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/config.js +1 -1
- package/package.json +1 -1
- package/providers/index.js +2 -0
- package/providers/minimax.js +68 -0
package/config.js
CHANGED
package/package.json
CHANGED
package/providers/index.js
CHANGED
|
@@ -1,12 +1,14 @@
|
|
|
1
1
|
import { VllmProvider } from './vllm.js';
|
|
2
2
|
import { DeepseekProvider } from './deepseek.js';
|
|
3
3
|
import { OpenAIProvider } from './openai.js';
|
|
4
|
+
import { MinimaxProvider } from './minimax.js';
|
|
4
5
|
import { getLlmConfig } from '../config.js';
|
|
5
6
|
|
|
6
7
|
const PROVIDERS = {
|
|
7
8
|
vllm: VllmProvider,
|
|
8
9
|
deepseek: DeepseekProvider,
|
|
9
10
|
openai: OpenAIProvider,
|
|
11
|
+
minimax: MinimaxProvider,
|
|
10
12
|
};
|
|
11
13
|
|
|
12
14
|
export function createProvider(config = {}) {
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import { getLlmConfig } from '../config.js';
|
|
2
|
+
|
|
3
|
+
export class MinimaxProvider {
|
|
4
|
+
constructor(config = {}) {
|
|
5
|
+
this.config = { ...getLlmConfig(), ...config };
|
|
6
|
+
this.baseURL = this.config.baseURL || 'https://api.minimax.chat/v1';
|
|
7
|
+
this.model = this.config.model || 'abab6.5s-chat';
|
|
8
|
+
this.apiKey = this.config.apiKey;
|
|
9
|
+
this.temperature = this.config.temperature;
|
|
10
|
+
this.maxTokens = this.config.maxTokens;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
async chat(messages, options = {}) {
|
|
14
|
+
const url = `${this.baseURL}/text/chatcompletion`;
|
|
15
|
+
const body = {
|
|
16
|
+
model: this.model,
|
|
17
|
+
messages: messages,
|
|
18
|
+
temperature: options.temperature ?? this.temperature,
|
|
19
|
+
max_tokens: options.maxTokens ?? this.maxTokens,
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
const headers = {
|
|
23
|
+
'Content-Type': 'application/json',
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
if (this.apiKey) {
|
|
27
|
+
headers['Authorization'] = `Bearer ${this.apiKey}`;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
try {
|
|
31
|
+
const response = await fetch(url, {
|
|
32
|
+
method: 'POST',
|
|
33
|
+
headers: headers,
|
|
34
|
+
body: JSON.stringify(body),
|
|
35
|
+
});
|
|
36
|
+
|
|
37
|
+
if (!response.ok) {
|
|
38
|
+
const errorText = await response.text();
|
|
39
|
+
throw new Error(`Minimax API error: ${response.status} ${errorText}`);
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
const data = await response.json();
|
|
43
|
+
|
|
44
|
+
if (data.base_resp?.status_code !== 0 && data.base_resp?.status_code !== 200) {
|
|
45
|
+
const errMsg = data.base_resp?.status_msg || 'Unknown error';
|
|
46
|
+
throw new Error(`Minimax API error: ${errMsg}`);
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
if (data.reply) return data.reply;
|
|
50
|
+
if (data.choices && data.choices.length > 0) {
|
|
51
|
+
return data.choices[0].message.content;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
throw new Error('No response content from Minimax: ' + JSON.stringify(data));
|
|
55
|
+
} catch (error) {
|
|
56
|
+
if (error.message.includes('fetch')) {
|
|
57
|
+
throw new Error(`无法连接到 Minimax API: ${error.message}`);
|
|
58
|
+
}
|
|
59
|
+
throw error;
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
getName() {
|
|
64
|
+
return 'minimax';
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
export default MinimaxProvider;
|