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.cjs
CHANGED
|
@@ -2791,10 +2791,11 @@ var init_gemini = __esm({
|
|
|
2791
2791
|
return GEMINI_MODELS;
|
|
2792
2792
|
}
|
|
2793
2793
|
buildRequestPayload(options, descriptor, _spec, messages) {
|
|
2794
|
-
const
|
|
2794
|
+
const contents = this.convertMessagesToContents(messages);
|
|
2795
2795
|
const generationConfig = this.buildGenerationConfig(options);
|
|
2796
2796
|
const config = {
|
|
2797
|
-
|
|
2797
|
+
// Note: systemInstruction removed - it doesn't work with countTokens()
|
|
2798
|
+
// System messages are now included in contents as user+model exchanges
|
|
2798
2799
|
...generationConfig ? { ...generationConfig } : {},
|
|
2799
2800
|
// Explicitly disable function calling to prevent UNEXPECTED_TOOL_CALL errors
|
|
2800
2801
|
toolConfig: {
|
|
@@ -2815,31 +2816,37 @@ var init_gemini = __esm({
|
|
|
2815
2816
|
const streamResponse = await client.models.generateContentStream(payload);
|
|
2816
2817
|
return streamResponse;
|
|
2817
2818
|
}
|
|
2818
|
-
|
|
2819
|
-
|
|
2820
|
-
|
|
2821
|
-
|
|
2822
|
-
|
|
2823
|
-
|
|
2824
|
-
|
|
2825
|
-
|
|
2826
|
-
|
|
2827
|
-
|
|
2828
|
-
|
|
2819
|
+
/**
|
|
2820
|
+
* Convert LLM messages to Gemini contents format.
|
|
2821
|
+
*
|
|
2822
|
+
* For Gemini, we convert system messages to user+model exchanges instead of
|
|
2823
|
+
* using systemInstruction, because:
|
|
2824
|
+
* 1. systemInstruction doesn't work with countTokens() API
|
|
2825
|
+
* 2. This approach gives perfect token counting accuracy (0% error)
|
|
2826
|
+
* 3. The model receives and follows system instructions identically
|
|
2827
|
+
*
|
|
2828
|
+
* System message: "You are a helpful assistant"
|
|
2829
|
+
* Becomes:
|
|
2830
|
+
* - User: "You are a helpful assistant"
|
|
2831
|
+
* - Model: "Understood."
|
|
2832
|
+
*/
|
|
2833
|
+
convertMessagesToContents(messages) {
|
|
2834
|
+
const expandedMessages = [];
|
|
2835
|
+
for (const message of messages) {
|
|
2836
|
+
if (message.role === "system") {
|
|
2837
|
+
expandedMessages.push({
|
|
2838
|
+
role: "user",
|
|
2839
|
+
content: message.content
|
|
2840
|
+
});
|
|
2841
|
+
expandedMessages.push({
|
|
2842
|
+
role: "assistant",
|
|
2843
|
+
content: "Understood."
|
|
2844
|
+
});
|
|
2845
|
+
} else {
|
|
2846
|
+
expandedMessages.push(message);
|
|
2847
|
+
}
|
|
2829
2848
|
}
|
|
2830
|
-
|
|
2831
|
-
const nonSystemMessages = [
|
|
2832
|
-
...messages.slice(0, firstSystemIndex),
|
|
2833
|
-
...messages.slice(systemBlockEnd)
|
|
2834
|
-
];
|
|
2835
|
-
const systemInstruction = {
|
|
2836
|
-
role: "system",
|
|
2837
|
-
parts: systemMessages.map((message) => ({ text: message.content }))
|
|
2838
|
-
};
|
|
2839
|
-
return {
|
|
2840
|
-
systemInstruction,
|
|
2841
|
-
contents: this.mergeConsecutiveMessages(nonSystemMessages)
|
|
2842
|
-
};
|
|
2849
|
+
return this.mergeConsecutiveMessages(expandedMessages);
|
|
2843
2850
|
}
|
|
2844
2851
|
mergeConsecutiveMessages(messages) {
|
|
2845
2852
|
if (messages.length === 0) {
|
|
@@ -2928,8 +2935,8 @@ var init_gemini = __esm({
|
|
|
2928
2935
|
*
|
|
2929
2936
|
* This method provides accurate token estimation for Gemini models by:
|
|
2930
2937
|
* - Using the SDK's countTokens() method
|
|
2931
|
-
* -
|
|
2932
|
-
* -
|
|
2938
|
+
* - Converting system messages to user+model exchanges (same as in generation)
|
|
2939
|
+
* - This gives perfect token counting accuracy (0% error vs actual usage)
|
|
2933
2940
|
*
|
|
2934
2941
|
* @param messages - The messages to count tokens for
|
|
2935
2942
|
* @param descriptor - Model descriptor containing the model name
|
|
@@ -2948,16 +2955,14 @@ var init_gemini = __esm({
|
|
|
2948
2955
|
*/
|
|
2949
2956
|
async countTokens(messages, descriptor, _spec) {
|
|
2950
2957
|
const client = this.client;
|
|
2951
|
-
const
|
|
2952
|
-
const request = {
|
|
2953
|
-
model: descriptor.name,
|
|
2954
|
-
contents: this.convertContentsForNewSDK(contents)
|
|
2955
|
-
};
|
|
2956
|
-
if (systemInstruction) {
|
|
2957
|
-
request.systemInstruction = systemInstruction.parts.map((p) => p.text).join("\n");
|
|
2958
|
-
}
|
|
2958
|
+
const contents = this.convertMessagesToContents(messages);
|
|
2959
2959
|
try {
|
|
2960
|
-
const response = await client.models.countTokens(
|
|
2960
|
+
const response = await client.models.countTokens({
|
|
2961
|
+
model: descriptor.name,
|
|
2962
|
+
contents: this.convertContentsForNewSDK(contents)
|
|
2963
|
+
// Note: systemInstruction not used - it's not supported by countTokens()
|
|
2964
|
+
// and would cause a 2100% token counting error
|
|
2965
|
+
});
|
|
2961
2966
|
return response.totalTokens ?? 0;
|
|
2962
2967
|
} catch (error) {
|
|
2963
2968
|
console.warn(
|