mm_llm 1.1.0 → 1.3.1

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.
@@ -0,0 +1,285 @@
1
+ {
2
+ "name": "llm",
3
+ "handler": "executor",
4
+ "title": "LLM 调用器",
5
+ "description": "LLM 网关:不传 action(或 action=chat)时单次调用 OpenAI 兼容接口并支持 function calling;传入 action 时操作 mm_llm 管理器实例,支持按会话发送、重置会话、查询会话消息/调用选项/用户配额,以及注册、删除、清空与列举已注册工具。适用场景:文本生成或 JSON、多轮会话维护、LLM 工具注册与配额核查。",
6
+ "type": "data",
7
+ "params": {
8
+ "type": "object",
9
+ "properties": {
10
+ "action": {
11
+ "type": "string",
12
+ "description": "操作类型: chat(单次直连对话,缺省)/send(按会话发送)/reset_session(重置会话)/history(查询会话消息)/options(查询调用选项)/quota(查询配额)/list_tools(列举已注册工具)/set_tool(注册工具)/del_tool(删除工具)/clear_tools(清空工具)",
13
+ "enum": [
14
+ "chat",
15
+ "send",
16
+ "reset_session",
17
+ "history",
18
+ "options",
19
+ "quota",
20
+ "list_tools",
21
+ "set_tool",
22
+ "del_tool",
23
+ "clear_tools"
24
+ ]
25
+ },
26
+ "scope": {
27
+ "type": "string",
28
+ "description": "llm 管理器实例作用域,缺省 os",
29
+ "default": "os"
30
+ },
31
+ "user_id": {
32
+ "type": "integer",
33
+ "description": "用户ID(send/reset_session/history/options/quota 必填)"
34
+ },
35
+ "agent_id": {
36
+ "type": "integer",
37
+ "description": "智能体ID(send/reset_session/history/options 必填;quota 可选;list_tools 可选)"
38
+ },
39
+ "session_id": {
40
+ "type": "integer",
41
+ "description": "会话ID(send/reset_session/history 必填)"
42
+ },
43
+ "name": {
44
+ "type": "string",
45
+ "description": "LLM 工具名称(set_tool/del_tool 必填)"
46
+ },
47
+ "tool": {
48
+ "type": "string",
49
+ "description": "内核工具名称(set_tool 可选,缺省与 name 相同;注册的执行函数转调该内核工具)"
50
+ },
51
+ "description": {
52
+ "type": "string",
53
+ "description": "工具描述(set_tool 可选,用于生成工具定义)"
54
+ },
55
+ "parameters": {
56
+ "type": "object",
57
+ "description": "工具参数 JSON Schema(set_tool 可选)"
58
+ },
59
+ "schema": {
60
+ "type": "object",
61
+ "description": "完整工具定义(set_tool 可选,优先于 description/parameters)"
62
+ },
63
+ "system_prompt": {
64
+ "type": "string",
65
+ "description": "系统提示词,定义 AI 的角色和行为规则"
66
+ },
67
+ "user_prompt": {
68
+ "type": "string",
69
+ "description": "用户提示词,包含具体问题和上下文"
70
+ },
71
+ "messages": {
72
+ "type": "array",
73
+ "description": "消息数组 [{role:'system'|'user'|'assistant', content:'...'}],优先级高于 system_prompt/user_prompt"
74
+ },
75
+ "llm": {
76
+ "type": "string",
77
+ "description": "LLM 模块名称,默认 default",
78
+ "default": "default"
79
+ },
80
+ "api_key": {
81
+ "type": "string",
82
+ "description": "API 密钥,优先使用此值,否则从 options 读取"
83
+ },
84
+ "base_url": {
85
+ "type": "string",
86
+ "description": "API 基础地址,如 https://api.openai.com/v1"
87
+ },
88
+ "model": {
89
+ "type": "string",
90
+ "description": "模型名称,如 gpt-4o"
91
+ },
92
+ "temperature": {
93
+ "type": "number",
94
+ "description": "生成温度 (0-2),值越低越确定",
95
+ "min": 0,
96
+ "max": 2
97
+ },
98
+ "max_tokens": {
99
+ "type": "integer",
100
+ "description": "最大生成 token 数"
101
+ },
102
+ "response_format": {
103
+ "type": "object",
104
+ "description": "响应格式,如 {type:'json_object'} 强制 JSON 输出"
105
+ },
106
+ "tools": {
107
+ "type": "array",
108
+ "description": "OpenAI 工具定义数组,格式 [{type:'function', function:{name, description, parameters}}]"
109
+ },
110
+ "tool_names": {
111
+ "type": "array",
112
+ "description": "工具名称数组,通过 kernel.getTools 自动获取工具定义并转换为 OpenAI 格式"
113
+ },
114
+ "tool_choice": {
115
+ "description": "工具选择策略: 'auto' | 'none' | 'required' | {type:'function', function:{name}}"
116
+ }
117
+ },
118
+ "required": []
119
+ },
120
+ "returns": {
121
+ "type": "object",
122
+ "description": "对话模式返回响应内容、模型和用量;管理动作模式返回 code/msg 及动作结果,失败时包含 error",
123
+ "properties": {
124
+ "code": {
125
+ "type": "number",
126
+ "description": "0 表示成功,1xxxx 表示业务/执行异常(管理动作模式)"
127
+ },
128
+ "msg": {
129
+ "type": "string",
130
+ "description": "LLM 调用成功/失败或动作结果描述"
131
+ },
132
+ "user_id": {
133
+ "type": "integer",
134
+ "description": "用户ID"
135
+ },
136
+ "agent_id": {
137
+ "type": "integer",
138
+ "description": "智能体ID"
139
+ },
140
+ "session_id": {
141
+ "type": "integer",
142
+ "description": "会话ID"
143
+ },
144
+ "result": {
145
+ "description": "send 动作的助手消息或流对象"
146
+ },
147
+ "reset": {
148
+ "type": "boolean",
149
+ "description": "是否重置了已存在的会话"
150
+ },
151
+ "count": {
152
+ "type": "number",
153
+ "description": "消息或已注册工具数量"
154
+ },
155
+ "messages": {
156
+ "type": "array",
157
+ "description": "会话消息上下文(history)"
158
+ },
159
+ "options": {
160
+ "type": "object",
161
+ "description": "调用选项(options)"
162
+ },
163
+ "quota": {
164
+ "type": "number",
165
+ "description": "剩余配额,未设置时为 null(quota)"
166
+ },
167
+ "allowed": {
168
+ "type": "boolean",
169
+ "description": "是否通过配额准入(quota)"
170
+ },
171
+ "tools": {
172
+ "type": "array",
173
+ "description": "已注册工具实现名称(list_tools)"
174
+ },
175
+ "schemas": {
176
+ "type": "array",
177
+ "description": "已定义工具名(list_tools)"
178
+ },
179
+ "agent_tools": {
180
+ "type": "array",
181
+ "description": "指定智能体引用的工具定义(list_tools)"
182
+ },
183
+ "tool": {
184
+ "type": "string",
185
+ "description": "工具名称(set_tool/del_tool)"
186
+ },
187
+ "kernel_tool": {
188
+ "type": "string",
189
+ "description": "绑定的内核工具名称(set_tool)"
190
+ },
191
+ "schema_saved": {
192
+ "type": "boolean",
193
+ "description": "是否写入工具定义(set_tool)"
194
+ },
195
+ "removed": {
196
+ "type": "boolean",
197
+ "description": "是否删除工具实现(del_tool)"
198
+ },
199
+ "removed_schema": {
200
+ "type": "boolean",
201
+ "description": "是否删除工具定义(del_tool)"
202
+ },
203
+ "cleared_schema": {
204
+ "type": "boolean",
205
+ "description": "是否清空工具定义(clear_tools)"
206
+ },
207
+ "content": {
208
+ "type": "string",
209
+ "description": "LLM 响应文本内容"
210
+ },
211
+ "tool_calls": {
212
+ "type": "array",
213
+ "description": "LLM 返回的工具调用列表,每个元素含 id、type、function(name, arguments)"
214
+ },
215
+ "usage": {
216
+ "type": "object",
217
+ "description": "Token 用量统计",
218
+ "properties": {
219
+ "prompt_tokens": {
220
+ "type": "integer",
221
+ "description": "输入 token 数"
222
+ },
223
+ "completion_tokens": {
224
+ "type": "integer",
225
+ "description": "输出 token 数"
226
+ },
227
+ "total_tokens": {
228
+ "type": "integer",
229
+ "description": "总 token 数"
230
+ }
231
+ }
232
+ },
233
+ "error": {
234
+ "type": "object",
235
+ "description": "错误信息,仅调用出错时返回",
236
+ "properties": {
237
+ "code": {
238
+ "type": "string",
239
+ "description": "错误码 (EXEC_ 前缀)"
240
+ },
241
+ "message": {
242
+ "type": "string",
243
+ "description": "错误描述"
244
+ }
245
+ }
246
+ }
247
+ }
248
+ },
249
+ "options": {
250
+ "api_key": {
251
+ "type": "string",
252
+ "description": "API 密钥"
253
+ },
254
+ "base_url": {
255
+ "type": "string",
256
+ "description": "API 基础地址",
257
+ "default": "https://api.openai.com/v1"
258
+ },
259
+ "model": {
260
+ "type": "string",
261
+ "description": "模型名称",
262
+ "default": "gpt-4o"
263
+ },
264
+ "temperature": {
265
+ "type": "number",
266
+ "description": "生成温度 (0-2)",
267
+ "default": 0.2,
268
+ "min": 0,
269
+ "max": 2
270
+ },
271
+ "max_tokens": {
272
+ "type": "integer",
273
+ "description": "最大生成 token 数",
274
+ "default": 4096
275
+ },
276
+ "timeout": {
277
+ "type": "integer",
278
+ "description": "请求超时(毫秒)",
279
+ "default": 60000,
280
+ "min": 1000,
281
+ "max": 300000
282
+ }
283
+ },
284
+ "group": "ai"
285
+ }
@@ -0,0 +1,36 @@
1
+ 'use strict';
2
+ const { admin } = require('../../index.js');
3
+
4
+ /**
5
+ * 管理 LLM 实例池
6
+ * @param {object} params 参数:action/scope
7
+ * @param {object} ctx 执行上下文
8
+ * @returns {Promise<object>} 执行结果
9
+ */
10
+ async function main(params, ctx) {
11
+ const p = params || {};
12
+ const action = p.action || 'list';
13
+ const scope = p.scope || 'os';
14
+ const done = (data) => {
15
+ if (ctx) ctx.output = data;
16
+ return data;
17
+ };
18
+ try {
19
+ if (action === 'list') {
20
+ const scopes = [...admin.keys()];
21
+ return done({ code: 0, msg: '获取成功', action, count: scopes.length, scopes });
22
+ }
23
+ if (action === 'inspect') {
24
+ const exists = admin.has(scope);
25
+ const instance = exists ? admin.get(scope) : null;
26
+ return done({ code: 0, msg: exists ? '获取成功' : '实例不存在', action, scope, exists, config: instance && instance.config ? instance.config : null });
27
+ }
28
+ if (action === 'del') return done({ code: 0, msg: '删除成功', action, scope, ok: admin.del(scope) });
29
+ if (action === 'clear') { admin.clear(); return done({ code: 0, msg: '实例池已清空', action }); }
30
+ return done({ code: 10001, msg: '不支持的操作: ' + action });
31
+ } catch (error) {
32
+ return done({ code: 10000, msg: '执行失败:' + error.message, error: { name: error.name, message: error.message } });
33
+ }
34
+ }
35
+
36
+ module.exports = { main };
@@ -0,0 +1,11 @@
1
+ {
2
+ "name": "llm_admin",
3
+ "title": "LLM 实例管理",
4
+ "description": "管理 mm_llm 的实例池:list 列出实例、inspect 查看配置、del 删除实例、clear 清空实例池。",
5
+ "category": "AI 能力",
6
+ "group": "ai",
7
+ "type": "function",
8
+ "main": "./index.js",
9
+ "params": { "type": "object", "properties": { "action": { "type": "string", "description": "操作类型: list/inspect/del/clear", "default": "list" }, "scope": { "type": "string", "description": "实例作用域,缺省 os", "default": "os" } }, "required": ["action"] },
10
+ "handler": "manager"
11
+ }