ak-gemini 1.0.6 → 1.0.7
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/index.cjs +34 -2
- package/index.js +43 -3
- package/package.json +5 -4
- package/types.d.ts +14 -1
package/index.cjs
CHANGED
|
@@ -29,6 +29,7 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
|
|
|
29
29
|
// index.js
|
|
30
30
|
var index_exports = {};
|
|
31
31
|
__export(index_exports, {
|
|
32
|
+
ThinkingLevel: () => import_genai.ThinkingLevel,
|
|
32
33
|
default: () => index_default,
|
|
33
34
|
log: () => logger_default
|
|
34
35
|
});
|
|
@@ -64,7 +65,7 @@ var DEFAULT_SAFETY_SETTINGS = [
|
|
|
64
65
|
var DEFAULT_SYSTEM_INSTRUCTIONS = `
|
|
65
66
|
You are an expert JSON transformation engine. Your task is to accurately convert data payloads from one format to another.
|
|
66
67
|
|
|
67
|
-
You will be provided with example transformations (Source JSON -> Target JSON).
|
|
68
|
+
You will be provided with example transformations (Source JSON -> Target JSON).
|
|
68
69
|
|
|
69
70
|
Learn the mapping rules from these examples.
|
|
70
71
|
|
|
@@ -72,8 +73,21 @@ When presented with new Source JSON, apply the learned transformation rules to p
|
|
|
72
73
|
|
|
73
74
|
Always respond ONLY with a valid JSON object that strictly adheres to the expected output format.
|
|
74
75
|
|
|
75
|
-
Do not include any additional text, explanations, or formatting before or after the JSON object.
|
|
76
|
+
Do not include any additional text, explanations, or formatting before or after the JSON object.
|
|
76
77
|
`;
|
|
78
|
+
var DEFAULT_THINKING_CONFIG = {
|
|
79
|
+
thinkingBudget: 0,
|
|
80
|
+
thinkingLevel: import_genai.ThinkingLevel.MINIMAL
|
|
81
|
+
};
|
|
82
|
+
var THINKING_SUPPORTED_MODELS = [
|
|
83
|
+
/^gemini-3-flash(-preview)?$/,
|
|
84
|
+
/^gemini-3-pro(-preview|-image-preview)?$/,
|
|
85
|
+
/^gemini-2\.5-pro/,
|
|
86
|
+
/^gemini-2\.5-flash(-preview)?$/,
|
|
87
|
+
/^gemini-2\.5-flash-lite(-preview)?$/,
|
|
88
|
+
/^gemini-2\.0-flash$/
|
|
89
|
+
// Experimental support, exact match only
|
|
90
|
+
];
|
|
77
91
|
var DEFAULT_CHAT_CONFIG = {
|
|
78
92
|
responseMimeType: "application/json",
|
|
79
93
|
temperature: 0.2,
|
|
@@ -152,6 +166,23 @@ function AITransformFactory(options = {}) {
|
|
|
152
166
|
...options.chatConfig,
|
|
153
167
|
systemInstruction: this.systemInstructions
|
|
154
168
|
};
|
|
169
|
+
const modelSupportsThinking = THINKING_SUPPORTED_MODELS.some(
|
|
170
|
+
(pattern) => pattern.test(this.modelName)
|
|
171
|
+
);
|
|
172
|
+
if (modelSupportsThinking && options.thinkingConfig) {
|
|
173
|
+
const thinkingConfig = {
|
|
174
|
+
...DEFAULT_THINKING_CONFIG,
|
|
175
|
+
...options.thinkingConfig
|
|
176
|
+
};
|
|
177
|
+
this.chatConfig.thinkingConfig = thinkingConfig;
|
|
178
|
+
if (logger_default.level !== "silent") {
|
|
179
|
+
logger_default.debug(`Model ${this.modelName} supports thinking. Applied thinkingConfig:`, thinkingConfig);
|
|
180
|
+
}
|
|
181
|
+
} else if (options.thinkingConfig && !modelSupportsThinking) {
|
|
182
|
+
if (logger_default.level !== "silent") {
|
|
183
|
+
logger_default.warn(`Model ${this.modelName} does not support thinking features. Ignoring thinkingConfig.`);
|
|
184
|
+
}
|
|
185
|
+
}
|
|
155
186
|
if (options.responseSchema) {
|
|
156
187
|
this.chatConfig.responseSchema = options.responseSchema;
|
|
157
188
|
}
|
|
@@ -572,5 +603,6 @@ if (import_meta.url === new URL(`file://${process.argv[1]}`).href) {
|
|
|
572
603
|
}
|
|
573
604
|
// Annotate the CommonJS export names for ESM import in node:
|
|
574
605
|
0 && (module.exports = {
|
|
606
|
+
ThinkingLevel,
|
|
575
607
|
log
|
|
576
608
|
});
|
package/index.js
CHANGED
|
@@ -23,11 +23,12 @@ const { NODE_ENV = "unknown", GEMINI_API_KEY, LOG_LEVEL = "" } = process.env;
|
|
|
23
23
|
|
|
24
24
|
|
|
25
25
|
//deps
|
|
26
|
-
import { GoogleGenAI, HarmCategory, HarmBlockThreshold } from '@google/genai';
|
|
26
|
+
import { GoogleGenAI, HarmCategory, HarmBlockThreshold, ThinkingLevel } from '@google/genai';
|
|
27
27
|
import u from 'ak-tools';
|
|
28
28
|
import path from 'path';
|
|
29
29
|
import log from './logger.js';
|
|
30
30
|
export { log };
|
|
31
|
+
export { ThinkingLevel };
|
|
31
32
|
|
|
32
33
|
|
|
33
34
|
|
|
@@ -40,7 +41,7 @@ const DEFAULT_SAFETY_SETTINGS = [
|
|
|
40
41
|
const DEFAULT_SYSTEM_INSTRUCTIONS = `
|
|
41
42
|
You are an expert JSON transformation engine. Your task is to accurately convert data payloads from one format to another.
|
|
42
43
|
|
|
43
|
-
You will be provided with example transformations (Source JSON -> Target JSON).
|
|
44
|
+
You will be provided with example transformations (Source JSON -> Target JSON).
|
|
44
45
|
|
|
45
46
|
Learn the mapping rules from these examples.
|
|
46
47
|
|
|
@@ -48,9 +49,25 @@ When presented with new Source JSON, apply the learned transformation rules to p
|
|
|
48
49
|
|
|
49
50
|
Always respond ONLY with a valid JSON object that strictly adheres to the expected output format.
|
|
50
51
|
|
|
51
|
-
Do not include any additional text, explanations, or formatting before or after the JSON object.
|
|
52
|
+
Do not include any additional text, explanations, or formatting before or after the JSON object.
|
|
52
53
|
`;
|
|
53
54
|
|
|
55
|
+
const DEFAULT_THINKING_CONFIG = {
|
|
56
|
+
thinkingBudget: 0,
|
|
57
|
+
thinkingLevel: ThinkingLevel.MINIMAL
|
|
58
|
+
};
|
|
59
|
+
|
|
60
|
+
// Models that support thinking features (as of Dec 2024)
|
|
61
|
+
// Using regex patterns for more precise matching
|
|
62
|
+
const THINKING_SUPPORTED_MODELS = [
|
|
63
|
+
/^gemini-3-flash(-preview)?$/,
|
|
64
|
+
/^gemini-3-pro(-preview|-image-preview)?$/,
|
|
65
|
+
/^gemini-2\.5-pro/,
|
|
66
|
+
/^gemini-2\.5-flash(-preview)?$/,
|
|
67
|
+
/^gemini-2\.5-flash-lite(-preview)?$/,
|
|
68
|
+
/^gemini-2\.0-flash$/ // Experimental support, exact match only
|
|
69
|
+
];
|
|
70
|
+
|
|
54
71
|
const DEFAULT_CHAT_CONFIG = {
|
|
55
72
|
responseMimeType: 'application/json',
|
|
56
73
|
temperature: 0.2,
|
|
@@ -161,6 +178,7 @@ function AITransformFactory(options = {}) {
|
|
|
161
178
|
|
|
162
179
|
this.apiKey = options.apiKey !== undefined && options.apiKey !== null ? options.apiKey : GEMINI_API_KEY;
|
|
163
180
|
if (!this.apiKey) throw new Error("Missing Gemini API key. Provide via options.apiKey or GEMINI_API_KEY env var.");
|
|
181
|
+
|
|
164
182
|
// Build chat config, making sure systemInstruction uses the custom instructions
|
|
165
183
|
this.chatConfig = {
|
|
166
184
|
...DEFAULT_CHAT_CONFIG,
|
|
@@ -168,6 +186,28 @@ function AITransformFactory(options = {}) {
|
|
|
168
186
|
systemInstruction: this.systemInstructions
|
|
169
187
|
};
|
|
170
188
|
|
|
189
|
+
// Only add thinkingConfig if the model supports it
|
|
190
|
+
const modelSupportsThinking = THINKING_SUPPORTED_MODELS.some(pattern =>
|
|
191
|
+
pattern.test(this.modelName)
|
|
192
|
+
);
|
|
193
|
+
|
|
194
|
+
if (modelSupportsThinking && options.thinkingConfig) {
|
|
195
|
+
// Handle thinkingConfig - merge with defaults
|
|
196
|
+
const thinkingConfig = {
|
|
197
|
+
...DEFAULT_THINKING_CONFIG,
|
|
198
|
+
...options.thinkingConfig
|
|
199
|
+
};
|
|
200
|
+
this.chatConfig.thinkingConfig = thinkingConfig;
|
|
201
|
+
|
|
202
|
+
if (log.level !== 'silent') {
|
|
203
|
+
log.debug(`Model ${this.modelName} supports thinking. Applied thinkingConfig:`, thinkingConfig);
|
|
204
|
+
}
|
|
205
|
+
} else if (options.thinkingConfig && !modelSupportsThinking) {
|
|
206
|
+
if (log.level !== 'silent') {
|
|
207
|
+
log.warn(`Model ${this.modelName} does not support thinking features. Ignoring thinkingConfig.`);
|
|
208
|
+
}
|
|
209
|
+
}
|
|
210
|
+
|
|
171
211
|
// response schema is optional, but if provided, it should be a valid JSON schema
|
|
172
212
|
if (options.responseSchema) {
|
|
173
213
|
this.chatConfig.responseSchema = options.responseSchema;
|
package/package.json
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
"name": "ak-gemini",
|
|
3
3
|
"author": "ak@mixpanel.com",
|
|
4
4
|
"description": "AK's Generative AI Helper for doing... transforms",
|
|
5
|
-
"version": "1.0.
|
|
5
|
+
"version": "1.0.7",
|
|
6
6
|
"main": "index.js",
|
|
7
7
|
"files": [
|
|
8
8
|
"index.js",
|
|
@@ -33,7 +33,7 @@
|
|
|
33
33
|
"homepage": "https://github.com/ak--47/ak-gemini#readme",
|
|
34
34
|
"scripts": {
|
|
35
35
|
"prepublishOnly": "npm run typecheck && npm run build:cjs",
|
|
36
|
-
"post": "npm publish
|
|
36
|
+
"post": "npm publish",
|
|
37
37
|
"release": "npm version patch && npm publish --access public",
|
|
38
38
|
"update-deps": "npx npm-check-updates -u && npm install",
|
|
39
39
|
"prune": "rm -rf tmp/*",
|
|
@@ -41,7 +41,8 @@
|
|
|
41
41
|
"test:unit": "npm test -- tests/module.test.js",
|
|
42
42
|
"build:cjs": "esbuild index.js --bundle --platform=node --format=cjs --outfile=index.cjs --external:@google/genai --external:ak-tools --external:dotenv --external:pino-pretty --external:pino",
|
|
43
43
|
"coverage": "node --no-warnings --experimental-vm-modules node_modules/jest/bin/jest.js --coverage",
|
|
44
|
-
"typecheck": "tsc --noEmit"
|
|
44
|
+
"typecheck": "tsc --noEmit",
|
|
45
|
+
"update:gemini": "npm install @google/genai@latest"
|
|
45
46
|
},
|
|
46
47
|
"type": "module",
|
|
47
48
|
"keywords": [
|
|
@@ -51,7 +52,7 @@
|
|
|
51
52
|
],
|
|
52
53
|
"license": "ISC",
|
|
53
54
|
"dependencies": {
|
|
54
|
-
"@google/genai": "^1.
|
|
55
|
+
"@google/genai": "^1.34.0",
|
|
55
56
|
"ak-tools": "^1.1.12",
|
|
56
57
|
"dotenv": "^16.5.0",
|
|
57
58
|
"pino": "^9.7.0",
|
package/types.d.ts
CHANGED
|
@@ -1,4 +1,15 @@
|
|
|
1
|
-
import type { GoogleGenAI } from '@google/genai';
|
|
1
|
+
import type { GoogleGenAI, ThinkingLevel } from '@google/genai';
|
|
2
|
+
|
|
3
|
+
export { ThinkingLevel };
|
|
4
|
+
|
|
5
|
+
export interface ThinkingConfig {
|
|
6
|
+
/** Indicates whether to include thoughts in the response. If true, thoughts are returned only if the model supports thought and thoughts are available. */
|
|
7
|
+
includeThoughts?: boolean;
|
|
8
|
+
/** Indicates the thinking budget in tokens. 0 is DISABLED. -1 is AUTOMATIC. The default values and allowed ranges are model dependent. */
|
|
9
|
+
thinkingBudget?: number;
|
|
10
|
+
/** Optional. The number of thoughts tokens that the model should generate. */
|
|
11
|
+
thinkingLevel?: ThinkingLevel;
|
|
12
|
+
}
|
|
2
13
|
|
|
3
14
|
export interface SafetySetting {
|
|
4
15
|
category: string; // The harm category
|
|
@@ -13,6 +24,7 @@ export interface ChatConfig {
|
|
|
13
24
|
systemInstruction?: string; // System instruction for the model
|
|
14
25
|
safetySettings?: SafetySetting[]; // Safety settings array
|
|
15
26
|
responseSchema?: Object; // Schema for validating model responses
|
|
27
|
+
thinkingConfig?: ThinkingConfig; // Thinking features configuration
|
|
16
28
|
[key: string]: any; // Additional properties for flexibility
|
|
17
29
|
}
|
|
18
30
|
|
|
@@ -61,6 +73,7 @@ export interface AITransformerOptions {
|
|
|
61
73
|
modelName?: string; // The Gemini model to use
|
|
62
74
|
systemInstructions?: string; // Custom system instructions for the model
|
|
63
75
|
chatConfig?: ChatConfig; // Configuration object for the chat session
|
|
76
|
+
thinkingConfig?: ThinkingConfig; // Thinking features configuration (defaults to thinkingBudget: 0, thinkingLevel: "MINIMAL")
|
|
64
77
|
examplesFile?: string; // Path to JSON file containing transformation examples
|
|
65
78
|
exampleData?: TransformationExample[]; // Inline examples to seed the transformer
|
|
66
79
|
sourceKey?: string; // Key name for source data in examples (alias for promptKey)
|