ak-gemini 1.0.55 → 1.0.58

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 CHANGED
@@ -119,7 +119,9 @@ var AITransformer = class {
119
119
  this.reset = resetChat.bind(this);
120
120
  this.getHistory = getChatHistory.bind(this);
121
121
  this.messageAndValidate = prepareAndValidateMessage.bind(this);
122
+ this.transformWithValidation = prepareAndValidateMessage.bind(this);
122
123
  this.estimate = estimateTokenUsage.bind(this);
124
+ this.estimateTokenUsage = estimateTokenUsage.bind(this);
123
125
  }
124
126
  };
125
127
  var index_default = AITransformer;
@@ -138,8 +140,8 @@ function AITransformFactory(options = {}) {
138
140
  }
139
141
  this.examplesFile = options.examplesFile || null;
140
142
  this.exampleData = options.exampleData || null;
141
- this.promptKey = options.promptKey || "PROMPT";
142
- this.answerKey = options.answerKey || "ANSWER";
143
+ this.promptKey = options.promptKey || options.sourceKey || "PROMPT";
144
+ this.answerKey = options.answerKey || options.targetKey || "ANSWER";
143
145
  this.contextKey = options.contextKey || "CONTEXT";
144
146
  this.explanationKey = options.explanationKey || "EXPLANATION";
145
147
  this.systemInstructionsKey = options.systemInstructionsKey || "SYSTEM";
package/index.js CHANGED
@@ -120,7 +120,9 @@ class AITransformer {
120
120
  this.reset = resetChat.bind(this);
121
121
  this.getHistory = getChatHistory.bind(this);
122
122
  this.messageAndValidate = prepareAndValidateMessage.bind(this);
123
+ this.transformWithValidation = prepareAndValidateMessage.bind(this);
123
124
  this.estimate = estimateTokenUsage.bind(this);
125
+ this.estimateTokenUsage = estimateTokenUsage.bind(this);
124
126
  }
125
127
  }
126
128
 
@@ -155,8 +157,8 @@ function AITransformFactory(options = {}) {
155
157
  this.exampleData = options.exampleData || null; // can be used instead of examplesFile
156
158
 
157
159
  // Use configurable keys with fallbacks
158
- this.promptKey = options.promptKey || 'PROMPT';
159
- this.answerKey = options.answerKey || 'ANSWER';
160
+ this.promptKey = options.promptKey || options.sourceKey || 'PROMPT';
161
+ this.answerKey = options.answerKey || options.targetKey || 'ANSWER';
160
162
  this.contextKey = options.contextKey || 'CONTEXT'; // Optional key for context
161
163
  this.explanationKey = options.explanationKey || 'EXPLANATION'; // Optional key for explanations
162
164
  this.systemInstructionsKey = options.systemInstructionsKey || 'SYSTEM'; // Optional key for system instructions
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.55",
5
+ "version": "1.0.58",
6
6
  "main": "index.js",
7
7
  "files": [
8
8
  "index.js",
@@ -32,22 +32,16 @@
32
32
  },
33
33
  "homepage": "https://github.com/ak--47/ak-gemini#readme",
34
34
  "scripts": {
35
- "prepublishOnly": "npm run build:cjs",
35
+ "prepublishOnly": "npm run typecheck && npm run build:cjs",
36
36
  "post": "npm publish --access public",
37
37
  "release": "npm version patch && npm publish --access public",
38
- "local": "./scripts/local.sh",
39
- "fire": "./scripts/fire.sh",
40
- "deploy": "./scripts/deploy.sh",
41
- "perms": "chmod +x ./scripts/*.sh",
42
38
  "update-deps": "npx npm-check-updates -u && npm install",
43
39
  "prune": "rm -rf tmp/*",
44
40
  "test": "node --no-warnings --experimental-vm-modules node_modules/jest/bin/jest.js",
45
- "test:all": "./scripts/test-all.sh",
46
- "test:integration": "./scripts/test-local.sh",
47
41
  "test:unit": "npm test -- tests/module.test.js",
48
- "test:function": "npm test -- tests/function.integration.test.js",
49
- "test:http": "npm test -- tests/function.http.test.js",
50
- "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"
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
+ "coverage": "node --no-warnings --experimental-vm-modules node_modules/jest/bin/jest.js --coverage",
44
+ "typecheck": "tsc --noEmit"
51
45
  },
52
46
  "type": "module",
53
47
  "keywords": [
@@ -57,7 +51,6 @@
57
51
  ],
58
52
  "license": "ISC",
59
53
  "dependencies": {
60
- "@google-cloud/functions-framework": "^4.0.0",
61
54
  "@google/genai": "^1.4.0",
62
55
  "ak-tools": "^1.0.64",
63
56
  "dotenv": "^16.5.0",
@@ -68,6 +61,7 @@
68
61
  "@types/jest": "^29.5.14",
69
62
  "esbuild": "^0.25.5",
70
63
  "jest": "^29.7.0",
71
- "nodemon": "^3.1.10"
64
+ "nodemon": "^3.1.10",
65
+ "typescript": "^5.9.2"
72
66
  }
73
- }
67
+ }
package/types.d.ts CHANGED
@@ -31,20 +31,25 @@ export interface AITransformerContext {
31
31
  systemInstructionsKey?: string;
32
32
  maxRetries?: number;
33
33
  retryDelay?: number;
34
- init?: () => Promise<void>; // Initialization function
34
+ init?: (force?: boolean) => Promise<void>; // Initialization function
35
35
  seed?: () => Promise<void>; // Function to seed the transformer with examples
36
36
  message?: (payload: Record<string, unknown>) => Promise<Record<string, unknown>>; // Function to send messages to the model
37
- rebuild?: () => Promise<Record<string, unknown>; // Function to rebuild the transformer
38
- rawMessage?: (payload: Record<string, unknown>) => Promise<Record<string, unknown>>; // Function to send raw messages to the model
37
+ rebuild?: (lastPayload: Record<string, unknown>, serverError: string) => Promise<Record<string, unknown>>; // Function to rebuild the transformer
38
+ rawMessage?: (payload: Record<string, unknown> | string) => Promise<Record<string, unknown>>; // Function to send raw messages to the model
39
39
  genAIClient?: GoogleGenAI; // Google GenAI client instance
40
40
  onlyJSON?: boolean; // If true, only JSON responses are allowed
41
41
 
42
42
  }
43
43
 
44
44
  export interface TransformationExample {
45
- CONTEXT?: Record<string, unknown>; // optional context for the transformation
45
+ CONTEXT?: Record<string, unknown> | string; // optional context for the transformation
46
46
  PROMPT?: Record<string, unknown>; // what the user provides as input
47
47
  ANSWER?: Record<string, unknown>; // what the model should return as output
48
+ INPUT?: Record<string, unknown>; // alias for PROMPT
49
+ OUTPUT?: Record<string, unknown>; // alias for ANSWER
50
+ SYSTEM?: string; // system instructions for this example
51
+ EXPLANATION?: string; // explanation for this example
52
+ [key: string]: any; // allow additional properties for flexible key mapping
48
53
  }
49
54
 
50
55
  export interface ExampleFileContent {
@@ -58,8 +63,10 @@ export interface AITransformerOptions {
58
63
  chatConfig?: ChatConfig; // Configuration object for the chat session
59
64
  examplesFile?: string; // Path to JSON file containing transformation examples
60
65
  exampleData?: TransformationExample[]; // Inline examples to seed the transformer
61
- sourceKey?: string; // Key name for source data in examples
62
- targetKey?: string; // Key name for target data in examples
66
+ sourceKey?: string; // Key name for source data in examples (alias for promptKey)
67
+ targetKey?: string; // Key name for target data in examples (alias for answerKey)
68
+ promptKey?: string; // Key for the prompt in examples
69
+ answerKey?: string; // Key for the answer in examples
63
70
  contextKey?: string; // Key name for context data in examples
64
71
  explanationKey?: string; // Key name for explanation data in examples
65
72
  systemInstructionsKey?: string; // Key for system instructions in examples
@@ -70,14 +77,47 @@ export interface AITransformerOptions {
70
77
  apiKey?: string; // API key for Google GenAI
71
78
  onlyJSON?: boolean; // If true, only JSON responses are allowed
72
79
  asyncValidator?: AsyncValidatorFunction; // Optional async validator function for response validation
73
- promptKey?: string; // Key for the prompt in examples
74
- answerKey?: string; // Key for the answer in examples
75
- contextKey?: string; // Key for the context in examples
76
- explanationKey?: string; // Key for the explanation in examples
77
80
  }
78
81
 
79
82
  // Async validator function type
80
83
  export type AsyncValidatorFunction = (payload: Record<string, unknown>) => Promise<unknown>;
81
84
 
82
85
 
83
- export declare class AITransformer implements AITransformerContext {}
86
+ export declare class AITransformer {
87
+ // Constructor
88
+ constructor(options?: AITransformerOptions);
89
+
90
+ // Properties
91
+ modelName: string;
92
+ promptKey: string;
93
+ answerKey: string;
94
+ contextKey: string;
95
+ explanationKey: string;
96
+ systemInstructionKey: string;
97
+ maxRetries: number;
98
+ retryDelay: number;
99
+ systemInstructions: string;
100
+ chatConfig: ChatConfig;
101
+ apiKey: string;
102
+ onlyJSON: boolean;
103
+ asyncValidator: AsyncValidatorFunction | null;
104
+ genAIClient: any;
105
+ chat: any;
106
+
107
+ // Methods
108
+ init(force?: boolean): Promise<void>;
109
+ seed(examples?: TransformationExample[]): Promise<any>;
110
+ message(payload: Record<string, unknown>, opts?: object, validatorFn?: AsyncValidatorFunction | null): Promise<Record<string, unknown>>;
111
+ rawMessage(sourcePayload: Record<string, unknown> | string): Promise<Record<string, unknown> | any>;
112
+ transformWithValidation(sourcePayload: Record<string, unknown>, validatorFn: AsyncValidatorFunction, options?: object): Promise<Record<string, unknown>>;
113
+ messageAndValidate(sourcePayload: Record<string, unknown>, validatorFn: AsyncValidatorFunction, options?: object): Promise<Record<string, unknown>>;
114
+ rebuild(lastPayload: Record<string, unknown>, serverError: string): Promise<Record<string, unknown>>;
115
+ reset(): Promise<void>;
116
+ getHistory(): Array<any>;
117
+ estimateTokenUsage(nextPayload: Record<string, unknown> | string): Promise<{ totalTokens: number; breakdown?: any }>;
118
+ estimate(nextPayload: Record<string, unknown> | string): Promise<{ totalTokens: number; breakdown?: any }>;
119
+ }
120
+
121
+ // Default export
122
+ declare const _default: typeof AITransformer;
123
+ export default _default;