ak-gemini 1.0.55 → 1.0.57

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.57",
6
6
  "main": "index.js",
7
7
  "files": [
8
8
  "index.js",
@@ -35,18 +35,10 @@
35
35
  "prepublishOnly": "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
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"
51
43
  },
52
44
  "type": "module",
@@ -57,7 +49,6 @@
57
49
  ],
58
50
  "license": "ISC",
59
51
  "dependencies": {
60
- "@google-cloud/functions-framework": "^4.0.0",
61
52
  "@google/genai": "^1.4.0",
62
53
  "ak-tools": "^1.0.64",
63
54
  "dotenv": "^16.5.0",
package/types.d.ts CHANGED
@@ -58,8 +58,10 @@ export interface AITransformerOptions {
58
58
  chatConfig?: ChatConfig; // Configuration object for the chat session
59
59
  examplesFile?: string; // Path to JSON file containing transformation examples
60
60
  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
61
+ sourceKey?: string; // Key name for source data in examples (alias for promptKey)
62
+ targetKey?: string; // Key name for target data in examples (alias for answerKey)
63
+ promptKey?: string; // Key for the prompt in examples
64
+ answerKey?: string; // Key for the answer in examples
63
65
  contextKey?: string; // Key name for context data in examples
64
66
  explanationKey?: string; // Key name for explanation data in examples
65
67
  systemInstructionsKey?: string; // Key for system instructions in examples
@@ -70,14 +72,47 @@ export interface AITransformerOptions {
70
72
  apiKey?: string; // API key for Google GenAI
71
73
  onlyJSON?: boolean; // If true, only JSON responses are allowed
72
74
  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
75
  }
78
76
 
79
77
  // Async validator function type
80
78
  export type AsyncValidatorFunction = (payload: Record<string, unknown>) => Promise<unknown>;
81
79
 
82
80
 
83
- export declare class AITransformer implements AITransformerContext {}
81
+ export declare class AITransformer {
82
+ // Constructor
83
+ constructor(options?: AITransformerOptions);
84
+
85
+ // Properties
86
+ modelName: string;
87
+ promptKey: string;
88
+ answerKey: string;
89
+ contextKey: string;
90
+ explanationKey: string;
91
+ systemInstructionKey: string;
92
+ maxRetries: number;
93
+ retryDelay: number;
94
+ systemInstructions: string;
95
+ chatConfig: ChatConfig;
96
+ apiKey: string;
97
+ onlyJSON: boolean;
98
+ asyncValidator: AsyncValidatorFunction | null;
99
+ genAIClient: any;
100
+ chat: any;
101
+
102
+ // Methods
103
+ init(force?: boolean): Promise<void>;
104
+ seed(examples?: TransformationExample[]): Promise<any>;
105
+ message(payload: Record<string, unknown>, opts?: object, validatorFn?: AsyncValidatorFunction | null): Promise<Record<string, unknown>>;
106
+ rawMessage(sourcePayload: Record<string, unknown> | string): Promise<Record<string, unknown>>;
107
+ transformWithValidation(sourcePayload: Record<string, unknown>, validatorFn: AsyncValidatorFunction, options?: object): Promise<Record<string, unknown>>;
108
+ messageAndValidate(sourcePayload: Record<string, unknown>, validatorFn: AsyncValidatorFunction, options?: object): Promise<Record<string, unknown>>;
109
+ rebuild(lastPayload: Record<string, unknown>, serverError: string): Promise<Record<string, unknown>>;
110
+ reset(): Promise<void>;
111
+ getHistory(): Array<any>;
112
+ estimateTokenUsage(nextPayload: Record<string, unknown> | string): Promise<{ totalTokens: number; breakdown?: any }>;
113
+ estimate(nextPayload: Record<string, unknown> | string): Promise<{ totalTokens: number; breakdown?: any }>;
114
+ }
115
+
116
+ // Default export
117
+ declare const _default: typeof AITransformer;
118
+ export default _default;