@memberjunction/ai-vertex 2.43.0 → 2.44.0

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.
Files changed (2) hide show
  1. package/package.json +3 -3
  2. package/readme.md +96 -9
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@memberjunction/ai-vertex",
3
- "version": "2.43.0",
3
+ "version": "2.44.0",
4
4
  "description": "MemberJunction Wrapper for Google Vertex AI Models",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -20,7 +20,7 @@
20
20
  },
21
21
  "dependencies": {
22
22
  "@google-cloud/vertexai": "^1.8.1",
23
- "@memberjunction/ai": "2.43.0",
24
- "@memberjunction/global": "2.43.0"
23
+ "@memberjunction/ai": "2.44.0",
24
+ "@memberjunction/global": "2.44.0"
25
25
  }
26
26
  }
package/readme.md CHANGED
@@ -11,7 +11,7 @@ A comprehensive wrapper for Google Vertex AI services, enabling seamless integra
11
11
  - **Response Format Control**: Support for various response formats including text and structured data
12
12
  - **Error Handling**: Robust error handling with detailed reporting
13
13
  - **Chat Completion**: Full support for chat-based interactions with supported models
14
- - **Embedding Generation**: Generate text embeddings for semantic search and other applications
14
+ - **Embedding Generation**: Generate text embeddings for semantic search and other applications (currently simulated, pending full Vertex AI embedding API support)
15
15
  - **Streaming Support**: Stream responses for real-time UI experiences
16
16
 
17
17
  ## Installation
@@ -36,10 +36,11 @@ import { VertexLLM, VertexEmbedding } from '@memberjunction/ai-vertex';
36
36
  // Path to Google Cloud service account key file
37
37
  const keyFilePath = '/path/to/service-account-key.json';
38
38
  const projectId = 'your-google-cloud-project-id';
39
+ const location = 'us-central1'; // Optional, defaults to 'us-central1'
39
40
 
40
41
  // Initialize with your Google Cloud credentials
41
- const vertexLLM = new VertexLLM(keyFilePath, projectId, 'us-central1');
42
- const vertexEmbedding = new VertexEmbedding(keyFilePath, projectId, 'us-central1');
42
+ const vertexLLM = new VertexLLM(keyFilePath, projectId, location);
43
+ const vertexEmbedding = new VertexEmbedding(keyFilePath, projectId, location);
43
44
  ```
44
45
 
45
46
  ### Chat Completion with PaLM Models
@@ -125,6 +126,8 @@ await vertexLLM.ChatCompletion(streamingParams);
125
126
 
126
127
  ### Text Embedding
127
128
 
129
+ **Note**: The embedding functionality is currently simulated as the Google Vertex AI SDK for Node.js does not yet provide direct access to embedding endpoints. This will be updated once the SDK supports native embedding generation.
130
+
128
131
  ```typescript
129
132
  import { EmbedTextParams, EmbedTextsParams } from '@memberjunction/ai';
130
133
 
@@ -160,10 +163,11 @@ Google Vertex AI offers a variety of foundation models. Here are some of the key
160
163
  - **PaLM 2 Family**: text-bison, chat-bison, text-unicorn
161
164
  - **Gemini Family**: gemini-pro, gemini-pro-vision, gemini-ultra
162
165
  - **Code Generation**: code-bison, codechat-bison
163
- - **Third-party Models**: claude-3-haiku, claude-3-sonnet, claude-3-opus (Anthropic Claude via Vertex)
166
+ - **Third-party Models**: Models from other providers may be available through Vertex AI
164
167
 
165
- ### Embedding Models
168
+ ### Embedding Models (Simulated)
166
169
  - **Text Embeddings**: textembedding-gecko, textembedding-gecko-multilingual
170
+ - *Note: Currently simulated pending SDK support*
167
171
 
168
172
  ### Multimodal Models
169
173
  - **Gemini Vision**: gemini-pro-vision
@@ -183,13 +187,18 @@ A class that extends BaseLLM to provide Google Vertex AI-specific functionality.
183
187
  new VertexLLM(apiKey: string, projectId: string, location: string = 'us-central1')
184
188
  ```
185
189
 
190
+ - `apiKey`: Path to the Google Cloud service account key file
191
+ - `projectId`: Your Google Cloud project ID
192
+ - `location`: The Google Cloud region for Vertex AI (defaults to 'us-central1')
193
+
186
194
  #### Properties
187
195
 
188
196
  - `Client`: (read-only) Returns the underlying Vertex AI client instance
197
+ - `SupportsStreaming`: (read-only) Returns `true` - Google Vertex AI supports streaming
189
198
 
190
199
  #### Methods
191
200
 
192
- - `ChatCompletion(params: ChatParams): Promise<ChatResult>` - Perform a chat completion
201
+ - `ChatCompletion(params: ChatParams): Promise<ChatResult>` - Perform a chat completion with optional streaming support
193
202
  - `SummarizeText(params: SummarizeParams): Promise<SummarizeResult>` - Not implemented yet
194
203
  - `ClassifyText(params: ClassifyParams): Promise<ClassifyResult>` - Not implemented yet
195
204
 
@@ -203,16 +212,34 @@ A class that extends BaseEmbeddings to provide Google Vertex AI embedding functi
203
212
  new VertexEmbedding(apiKey: string, projectId: string, location: string = 'us-central1')
204
213
  ```
205
214
 
215
+ - `apiKey`: Path to the Google Cloud service account key file
216
+ - `projectId`: Your Google Cloud project ID
217
+ - `location`: The Google Cloud region for Vertex AI (defaults to 'us-central1')
218
+
206
219
  #### Properties
207
220
 
208
221
  - `Client`: (read-only) Returns the underlying Vertex AI client instance
209
222
 
210
223
  #### Methods
211
224
 
212
- - `EmbedText(params: EmbedTextParams): Promise<EmbedTextResult>` - Generate embeddings for a single text
213
- - `EmbedTexts(params: EmbedTextsParams): Promise<EmbedTextsResult>` - Generate embeddings for multiple texts
225
+ - `EmbedText(params: EmbedTextParams): Promise<EmbedTextResult>` - Generate embeddings for a single text (currently simulated)
226
+ - `EmbedTexts(params: EmbedTextsParams): Promise<EmbedTextsResult>` - Generate embeddings for multiple texts (currently simulated)
214
227
  - `GetEmbeddingModels(): Promise<any>` - Get available embedding models
215
228
 
229
+ ### Loader Functions
230
+
231
+ The package exports loader functions to prevent tree-shaking of the registered classes:
232
+
233
+ ```typescript
234
+ import { LoadVertexLLM, LoadVertexEmbedding } from '@memberjunction/ai-vertex';
235
+
236
+ // Call these functions if you need to ensure the classes are registered
237
+ LoadVertexLLM();
238
+ LoadVertexEmbedding();
239
+ ```
240
+
241
+ These functions are typically not needed in normal usage as importing the classes will automatically register them.
242
+
216
243
  ## Error Handling
217
244
 
218
245
  The wrapper provides detailed error information:
@@ -247,13 +274,15 @@ if (response.success) {
247
274
 
248
275
  Currently, the wrapper implements:
249
276
  - Chat completion functionality with token usage tracking
250
- - Embedding functionality
251
277
  - Streaming response support
278
+ - Simulated embedding functionality (pending native SDK support)
252
279
 
253
280
  Future implementations may include:
281
+ - Native embedding functionality (once supported by the Google Cloud Vertex AI SDK)
254
282
  - `SummarizeText` functionality
255
283
  - `ClassifyText` functionality
256
284
  - Support for image generation models
285
+ - Support for multimodal inputs
257
286
 
258
287
  ## Dependencies
259
288
 
@@ -261,4 +290,62 @@ Future implementations may include:
261
290
  - `@memberjunction/ai`: MemberJunction AI core framework
262
291
  - `@memberjunction/global`: MemberJunction global utilities
263
292
 
293
+ ## Integration with MemberJunction
294
+
295
+ This package integrates seamlessly with the MemberJunction AI framework:
296
+
297
+ 1. **Standardized Interface**: Implements the same interface as other AI providers in the MemberJunction ecosystem
298
+ 2. **Provider Registration**: Classes are automatically registered using the `@RegisterClass` decorator
299
+ 3. **Model Management**: Compatible with MemberJunction's AI model management system
300
+ 4. **Token Tracking**: Integrates with MemberJunction's usage tracking and billing systems
301
+
302
+ ### Using with MemberJunction AI Core
303
+
304
+ ```typescript
305
+ import { GetAIAPIKey } from '@memberjunction/ai';
306
+ import { VertexLLM } from '@memberjunction/ai-vertex';
307
+
308
+ // Get API key from MemberJunction configuration
309
+ const apiKey = GetAIAPIKey('vertex');
310
+ const projectId = 'your-project-id';
311
+
312
+ // Create provider instance
313
+ const vertex = new VertexLLM(apiKey, projectId);
314
+
315
+ // Use with MemberJunction AI services
316
+ // The provider will be automatically available through the AI factory system
317
+ ```
318
+
319
+ ## Implementation Notes
320
+
321
+ ### Authentication
322
+ The package expects the `apiKey` parameter to be a path to a Google Cloud service account key file, not an API key string. This file should contain the credentials for accessing Vertex AI services.
323
+
324
+ ### Model Name Mapping
325
+ The package automatically handles different model types based on their name prefix:
326
+ - Models starting with `gemini-` are handled as Gemini models
327
+ - Models starting with `text-` are handled as text generation models
328
+ - Models starting with `code-` are handled as code generation models
329
+
330
+ ### Message Role Mapping
331
+ The package maps MemberJunction message roles to Vertex AI format:
332
+ - `system` → `system`
333
+ - `assistant` → `model`
334
+ - `user` → `user`
335
+
336
+ ## Building and Development
337
+
338
+ ```bash
339
+ # Build the package
340
+ npm run build
341
+
342
+ # Watch mode for development
343
+ npm run watch
344
+
345
+ # Run type checking
346
+ tsc --noEmit
347
+ ```
348
+
349
+ ## License
350
+
264
351
  See the [repository root](../../../LICENSE) for license information.