miii-agent 0.1.21 → 0.1.22
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/dist/cli.js +46 -2
- package/package.json +1 -1
package/dist/cli.js
CHANGED
|
@@ -163,6 +163,30 @@ async function modelContext(entry, model) {
|
|
|
163
163
|
throw err;
|
|
164
164
|
}
|
|
165
165
|
}
|
|
166
|
+
async function paramCountB(entry, model) {
|
|
167
|
+
try {
|
|
168
|
+
const info = await makeClient(entry).show({ model });
|
|
169
|
+
const details = info.details;
|
|
170
|
+
if (details?.parameter_size) {
|
|
171
|
+
const m = details.parameter_size.match(/([\d.]+)\s*([BM])/i);
|
|
172
|
+
if (m) {
|
|
173
|
+
const n = parseFloat(m[1]);
|
|
174
|
+
if (!isNaN(n)) return m[2].toUpperCase() === "M" ? n / 1e3 : n;
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
const modelInfo = info.model_info;
|
|
178
|
+
if (modelInfo) {
|
|
179
|
+
const key = Object.keys(modelInfo).find((k) => k.endsWith("parameter_count"));
|
|
180
|
+
if (key) {
|
|
181
|
+
const val = Number(modelInfo[key]);
|
|
182
|
+
if (!isNaN(val) && val > 0) return val / 1e9;
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
return null;
|
|
186
|
+
} catch {
|
|
187
|
+
return null;
|
|
188
|
+
}
|
|
189
|
+
}
|
|
166
190
|
async function* chat(entry, model, messages, tools, opts) {
|
|
167
191
|
if (opts?.signal?.aborted) return;
|
|
168
192
|
const signal = opts?.signal;
|
|
@@ -484,6 +508,9 @@ var init_openai = __esm({
|
|
|
484
508
|
function active() {
|
|
485
509
|
return resolveProvider();
|
|
486
510
|
}
|
|
511
|
+
function providerName() {
|
|
512
|
+
return active().name;
|
|
513
|
+
}
|
|
487
514
|
function isAvailable3() {
|
|
488
515
|
const { entry } = active();
|
|
489
516
|
return entry.type === "ollama" ? isAvailable(entry) : isAvailable2(entry);
|
|
@@ -500,6 +527,16 @@ async function modelContext3(model) {
|
|
|
500
527
|
const { entry } = active();
|
|
501
528
|
return entry.type === "ollama" ? modelContext(entry, model) : modelContext2(entry, model);
|
|
502
529
|
}
|
|
530
|
+
async function modelParamCountB(model) {
|
|
531
|
+
const { entry } = active();
|
|
532
|
+
if (entry.type !== "ollama") return null;
|
|
533
|
+
const key = `${entry.baseUrl}:${model}`;
|
|
534
|
+
const cached = paramCountCache.get(key);
|
|
535
|
+
if (cached !== void 0) return cached;
|
|
536
|
+
const params = await paramCountB(entry, model);
|
|
537
|
+
paramCountCache.set(key, params);
|
|
538
|
+
return params;
|
|
539
|
+
}
|
|
503
540
|
async function* chat3(model, messages, tools, opts) {
|
|
504
541
|
const { entry } = active();
|
|
505
542
|
if (entry.type === "ollama") {
|
|
@@ -508,12 +545,14 @@ async function* chat3(model, messages, tools, opts) {
|
|
|
508
545
|
yield* chat2(entry, model, messages, tools, opts);
|
|
509
546
|
}
|
|
510
547
|
}
|
|
548
|
+
var paramCountCache;
|
|
511
549
|
var init_client = __esm({
|
|
512
550
|
"src/llm/client.ts"() {
|
|
513
551
|
"use strict";
|
|
514
552
|
init_config();
|
|
515
553
|
init_ollama();
|
|
516
554
|
init_openai();
|
|
555
|
+
paramCountCache = /* @__PURE__ */ new Map();
|
|
517
556
|
}
|
|
518
557
|
});
|
|
519
558
|
|
|
@@ -1752,7 +1791,11 @@ function markSeen(name, input, seen) {
|
|
|
1752
1791
|
async function* runAgent(opts) {
|
|
1753
1792
|
const { model, cwd, permissions, hooks, signal, num_ctx } = opts;
|
|
1754
1793
|
const startTime = Date.now();
|
|
1755
|
-
|
|
1794
|
+
let useGrammar = false;
|
|
1795
|
+
if (providerName() === "ollama") {
|
|
1796
|
+
const params = await modelParamCountB(model);
|
|
1797
|
+
useGrammar = params == null || params <= GRAMMAR_MAX_PARAMS_B;
|
|
1798
|
+
}
|
|
1756
1799
|
const system = buildSystemPrompt(TOOLS, cwd, loadProjectContext(cwd), useGrammar);
|
|
1757
1800
|
const grammar = useGrammar ? buildToolGrammar(TOOLS) : void 0;
|
|
1758
1801
|
const ollamaTools = toOllamaTools(TOOLS);
|
|
@@ -1983,7 +2026,7 @@ async function* runAgent(opts) {
|
|
|
1983
2026
|
yield { type: "done", prompt_tokens: promptTokens, eval_tokens: evalTokens };
|
|
1984
2027
|
return history;
|
|
1985
2028
|
}
|
|
1986
|
-
var MAX_TURNS, REPEAT_TAIL, REPEAT_KILL, BIG_WRITE_TOOLS;
|
|
2029
|
+
var MAX_TURNS, REPEAT_TAIL, REPEAT_KILL, GRAMMAR_MAX_PARAMS_B, BIG_WRITE_TOOLS;
|
|
1987
2030
|
var init_loop = __esm({
|
|
1988
2031
|
"src/agent/loop.ts"() {
|
|
1989
2032
|
"use strict";
|
|
@@ -2000,6 +2043,7 @@ var init_loop = __esm({
|
|
|
2000
2043
|
MAX_TURNS = 25;
|
|
2001
2044
|
REPEAT_TAIL = 120;
|
|
2002
2045
|
REPEAT_KILL = 4;
|
|
2046
|
+
GRAMMAR_MAX_PARAMS_B = 14;
|
|
2003
2047
|
BIG_WRITE_TOOLS = /* @__PURE__ */ new Set(["write_file", "edit_file"]);
|
|
2004
2048
|
}
|
|
2005
2049
|
});
|
package/package.json
CHANGED