llmist 0.4.0 → 0.4.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.
- package/dist/{chunk-VRTKJK2X.js → chunk-A4GRCCXF.js} +2 -2
- package/dist/{chunk-VYBRYR2S.js → chunk-LQE7TKKW.js} +43 -38
- package/dist/chunk-LQE7TKKW.js.map +1 -0
- package/dist/{chunk-I55AV3WV.js → chunk-QVDGTUQN.js} +2 -2
- package/dist/cli.cjs +43 -38
- package/dist/cli.cjs.map +1 -1
- package/dist/cli.js +3 -3
- package/dist/cli.js.map +1 -1
- package/dist/index.cjs +42 -37
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +17 -3
- package/dist/index.d.ts +17 -3
- package/dist/index.js +3 -3
- package/dist/testing/index.cjs +42 -37
- package/dist/testing/index.cjs.map +1 -1
- package/dist/testing/index.js +2 -2
- package/package.json +1 -1
- package/dist/chunk-VYBRYR2S.js.map +0 -1
- /package/dist/{chunk-VRTKJK2X.js.map → chunk-A4GRCCXF.js.map} +0 -0
- /package/dist/{chunk-I55AV3WV.js.map → chunk-QVDGTUQN.js.map} +0 -0
package/dist/index.d.cts
CHANGED
|
@@ -1562,7 +1562,21 @@ declare class GeminiGenerativeProvider extends BaseProviderAdapter {
|
|
|
1562
1562
|
}>;
|
|
1563
1563
|
config: Record<string, unknown>;
|
|
1564
1564
|
}): Promise<AsyncIterable<GeminiChunk>>;
|
|
1565
|
-
|
|
1565
|
+
/**
|
|
1566
|
+
* Convert LLM messages to Gemini contents format.
|
|
1567
|
+
*
|
|
1568
|
+
* For Gemini, we convert system messages to user+model exchanges instead of
|
|
1569
|
+
* using systemInstruction, because:
|
|
1570
|
+
* 1. systemInstruction doesn't work with countTokens() API
|
|
1571
|
+
* 2. This approach gives perfect token counting accuracy (0% error)
|
|
1572
|
+
* 3. The model receives and follows system instructions identically
|
|
1573
|
+
*
|
|
1574
|
+
* System message: "You are a helpful assistant"
|
|
1575
|
+
* Becomes:
|
|
1576
|
+
* - User: "You are a helpful assistant"
|
|
1577
|
+
* - Model: "Understood."
|
|
1578
|
+
*/
|
|
1579
|
+
private convertMessagesToContents;
|
|
1566
1580
|
private mergeConsecutiveMessages;
|
|
1567
1581
|
private convertContentsForNewSDK;
|
|
1568
1582
|
private buildGenerationConfig;
|
|
@@ -1575,8 +1589,8 @@ declare class GeminiGenerativeProvider extends BaseProviderAdapter {
|
|
|
1575
1589
|
*
|
|
1576
1590
|
* This method provides accurate token estimation for Gemini models by:
|
|
1577
1591
|
* - Using the SDK's countTokens() method
|
|
1578
|
-
* -
|
|
1579
|
-
* -
|
|
1592
|
+
* - Converting system messages to user+model exchanges (same as in generation)
|
|
1593
|
+
* - This gives perfect token counting accuracy (0% error vs actual usage)
|
|
1580
1594
|
*
|
|
1581
1595
|
* @param messages - The messages to count tokens for
|
|
1582
1596
|
* @param descriptor - Model descriptor containing the model name
|
package/dist/index.d.ts
CHANGED
|
@@ -1562,7 +1562,21 @@ declare class GeminiGenerativeProvider extends BaseProviderAdapter {
|
|
|
1562
1562
|
}>;
|
|
1563
1563
|
config: Record<string, unknown>;
|
|
1564
1564
|
}): Promise<AsyncIterable<GeminiChunk>>;
|
|
1565
|
-
|
|
1565
|
+
/**
|
|
1566
|
+
* Convert LLM messages to Gemini contents format.
|
|
1567
|
+
*
|
|
1568
|
+
* For Gemini, we convert system messages to user+model exchanges instead of
|
|
1569
|
+
* using systemInstruction, because:
|
|
1570
|
+
* 1. systemInstruction doesn't work with countTokens() API
|
|
1571
|
+
* 2. This approach gives perfect token counting accuracy (0% error)
|
|
1572
|
+
* 3. The model receives and follows system instructions identically
|
|
1573
|
+
*
|
|
1574
|
+
* System message: "You are a helpful assistant"
|
|
1575
|
+
* Becomes:
|
|
1576
|
+
* - User: "You are a helpful assistant"
|
|
1577
|
+
* - Model: "Understood."
|
|
1578
|
+
*/
|
|
1579
|
+
private convertMessagesToContents;
|
|
1566
1580
|
private mergeConsecutiveMessages;
|
|
1567
1581
|
private convertContentsForNewSDK;
|
|
1568
1582
|
private buildGenerationConfig;
|
|
@@ -1575,8 +1589,8 @@ declare class GeminiGenerativeProvider extends BaseProviderAdapter {
|
|
|
1575
1589
|
*
|
|
1576
1590
|
* This method provides accurate token estimation for Gemini models by:
|
|
1577
1591
|
* - Using the SDK's countTokens() method
|
|
1578
|
-
* -
|
|
1579
|
-
* -
|
|
1592
|
+
* - Converting system messages to user+model exchanges (same as in generation)
|
|
1593
|
+
* - This gives perfect token counting accuracy (0% error vs actual usage)
|
|
1580
1594
|
*
|
|
1581
1595
|
* @param messages - The messages to count tokens for
|
|
1582
1596
|
* @param descriptor - Model descriptor containing the model name
|
package/dist/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import {
|
|
2
2
|
createGadget
|
|
3
|
-
} from "./chunk-
|
|
3
|
+
} from "./chunk-QVDGTUQN.js";
|
|
4
4
|
import {
|
|
5
5
|
MockBuilder,
|
|
6
6
|
MockManager,
|
|
@@ -13,7 +13,7 @@ import {
|
|
|
13
13
|
mockLLM,
|
|
14
14
|
validateAndApplyDefaults,
|
|
15
15
|
validateGadgetParams
|
|
16
|
-
} from "./chunk-
|
|
16
|
+
} from "./chunk-A4GRCCXF.js";
|
|
17
17
|
import {
|
|
18
18
|
AgentBuilder,
|
|
19
19
|
AnthropicMessagesProvider,
|
|
@@ -70,7 +70,7 @@ import {
|
|
|
70
70
|
resolveRulesTemplate,
|
|
71
71
|
runWithHandlers,
|
|
72
72
|
stream
|
|
73
|
-
} from "./chunk-
|
|
73
|
+
} from "./chunk-LQE7TKKW.js";
|
|
74
74
|
|
|
75
75
|
// src/index.ts
|
|
76
76
|
init_builder();
|
package/dist/testing/index.cjs
CHANGED
|
@@ -3256,10 +3256,11 @@ var init_gemini = __esm({
|
|
|
3256
3256
|
return GEMINI_MODELS;
|
|
3257
3257
|
}
|
|
3258
3258
|
buildRequestPayload(options, descriptor, _spec, messages) {
|
|
3259
|
-
const
|
|
3259
|
+
const contents = this.convertMessagesToContents(messages);
|
|
3260
3260
|
const generationConfig = this.buildGenerationConfig(options);
|
|
3261
3261
|
const config = {
|
|
3262
|
-
|
|
3262
|
+
// Note: systemInstruction removed - it doesn't work with countTokens()
|
|
3263
|
+
// System messages are now included in contents as user+model exchanges
|
|
3263
3264
|
...generationConfig ? { ...generationConfig } : {},
|
|
3264
3265
|
// Explicitly disable function calling to prevent UNEXPECTED_TOOL_CALL errors
|
|
3265
3266
|
toolConfig: {
|
|
@@ -3280,31 +3281,37 @@ var init_gemini = __esm({
|
|
|
3280
3281
|
const streamResponse = await client.models.generateContentStream(payload);
|
|
3281
3282
|
return streamResponse;
|
|
3282
3283
|
}
|
|
3283
|
-
|
|
3284
|
-
|
|
3285
|
-
|
|
3286
|
-
|
|
3287
|
-
|
|
3288
|
-
|
|
3289
|
-
|
|
3290
|
-
|
|
3291
|
-
|
|
3292
|
-
|
|
3293
|
-
|
|
3284
|
+
/**
|
|
3285
|
+
* Convert LLM messages to Gemini contents format.
|
|
3286
|
+
*
|
|
3287
|
+
* For Gemini, we convert system messages to user+model exchanges instead of
|
|
3288
|
+
* using systemInstruction, because:
|
|
3289
|
+
* 1. systemInstruction doesn't work with countTokens() API
|
|
3290
|
+
* 2. This approach gives perfect token counting accuracy (0% error)
|
|
3291
|
+
* 3. The model receives and follows system instructions identically
|
|
3292
|
+
*
|
|
3293
|
+
* System message: "You are a helpful assistant"
|
|
3294
|
+
* Becomes:
|
|
3295
|
+
* - User: "You are a helpful assistant"
|
|
3296
|
+
* - Model: "Understood."
|
|
3297
|
+
*/
|
|
3298
|
+
convertMessagesToContents(messages) {
|
|
3299
|
+
const expandedMessages = [];
|
|
3300
|
+
for (const message of messages) {
|
|
3301
|
+
if (message.role === "system") {
|
|
3302
|
+
expandedMessages.push({
|
|
3303
|
+
role: "user",
|
|
3304
|
+
content: message.content
|
|
3305
|
+
});
|
|
3306
|
+
expandedMessages.push({
|
|
3307
|
+
role: "assistant",
|
|
3308
|
+
content: "Understood."
|
|
3309
|
+
});
|
|
3310
|
+
} else {
|
|
3311
|
+
expandedMessages.push(message);
|
|
3312
|
+
}
|
|
3294
3313
|
}
|
|
3295
|
-
|
|
3296
|
-
const nonSystemMessages = [
|
|
3297
|
-
...messages.slice(0, firstSystemIndex),
|
|
3298
|
-
...messages.slice(systemBlockEnd)
|
|
3299
|
-
];
|
|
3300
|
-
const systemInstruction = {
|
|
3301
|
-
role: "system",
|
|
3302
|
-
parts: systemMessages.map((message) => ({ text: message.content }))
|
|
3303
|
-
};
|
|
3304
|
-
return {
|
|
3305
|
-
systemInstruction,
|
|
3306
|
-
contents: this.mergeConsecutiveMessages(nonSystemMessages)
|
|
3307
|
-
};
|
|
3314
|
+
return this.mergeConsecutiveMessages(expandedMessages);
|
|
3308
3315
|
}
|
|
3309
3316
|
mergeConsecutiveMessages(messages) {
|
|
3310
3317
|
if (messages.length === 0) {
|
|
@@ -3393,8 +3400,8 @@ var init_gemini = __esm({
|
|
|
3393
3400
|
*
|
|
3394
3401
|
* This method provides accurate token estimation for Gemini models by:
|
|
3395
3402
|
* - Using the SDK's countTokens() method
|
|
3396
|
-
* -
|
|
3397
|
-
* -
|
|
3403
|
+
* - Converting system messages to user+model exchanges (same as in generation)
|
|
3404
|
+
* - This gives perfect token counting accuracy (0% error vs actual usage)
|
|
3398
3405
|
*
|
|
3399
3406
|
* @param messages - The messages to count tokens for
|
|
3400
3407
|
* @param descriptor - Model descriptor containing the model name
|
|
@@ -3413,16 +3420,14 @@ var init_gemini = __esm({
|
|
|
3413
3420
|
*/
|
|
3414
3421
|
async countTokens(messages, descriptor, _spec) {
|
|
3415
3422
|
const client = this.client;
|
|
3416
|
-
const
|
|
3417
|
-
const request = {
|
|
3418
|
-
model: descriptor.name,
|
|
3419
|
-
contents: this.convertContentsForNewSDK(contents)
|
|
3420
|
-
};
|
|
3421
|
-
if (systemInstruction) {
|
|
3422
|
-
request.systemInstruction = systemInstruction.parts.map((p) => p.text).join("\n");
|
|
3423
|
-
}
|
|
3423
|
+
const contents = this.convertMessagesToContents(messages);
|
|
3424
3424
|
try {
|
|
3425
|
-
const response = await client.models.countTokens(
|
|
3425
|
+
const response = await client.models.countTokens({
|
|
3426
|
+
model: descriptor.name,
|
|
3427
|
+
contents: this.convertContentsForNewSDK(contents)
|
|
3428
|
+
// Note: systemInstruction not used - it's not supported by countTokens()
|
|
3429
|
+
// and would cause a 2100% token counting error
|
|
3430
|
+
});
|
|
3426
3431
|
return response.totalTokens ?? 0;
|
|
3427
3432
|
} catch (error) {
|
|
3428
3433
|
console.warn(
|