@memberjunction/graphql-dataprovider 2.92.0 → 2.94.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.
package/README.md CHANGED
@@ -29,6 +29,8 @@ npm install @memberjunction/graphql-dataprovider
29
29
  - **Session Management**: Persistent session IDs with automatic storage
30
30
  - **System User Client**: Specialized client for server-to-server communication
31
31
  - **Duplicate Detection**: Built-in support for finding and merging duplicate records
32
+ - **AI Operations**: Execute AI prompts and generate embeddings through GraphQL
33
+ - **Simple Prompts**: Run ad-hoc AI prompts without stored configurations
32
34
 
33
35
  ## Usage
34
36
 
@@ -352,6 +354,108 @@ function subscribeToRecordChanges() {
352
354
  }
353
355
  ```
354
356
 
357
+ ### AI Operations
358
+
359
+ The GraphQL provider includes a comprehensive AI client for executing prompts and generating embeddings.
360
+
361
+ ```typescript
362
+ import { GraphQLDataProvider } from '@memberjunction/graphql-dataprovider';
363
+
364
+ const dataProvider = new GraphQLDataProvider();
365
+ const aiClient = dataProvider.AI; // Access the AI client
366
+
367
+ // Execute a stored AI prompt
368
+ async function runAIPrompt() {
369
+ const result = await aiClient.RunAIPrompt({
370
+ promptId: 'prompt-123',
371
+ data: { context: 'user specific data' },
372
+ temperature: 0.7,
373
+ topP: 0.9,
374
+ responseFormat: 'json'
375
+ });
376
+
377
+ if (result.success) {
378
+ console.log('AI Response:', result.output);
379
+ console.log('Parsed Result:', result.parsedResult);
380
+ console.log('Tokens Used:', result.tokensUsed);
381
+ }
382
+ return result;
383
+ }
384
+
385
+ // Execute a simple prompt without stored configuration
386
+ async function runSimplePrompt() {
387
+ const result = await aiClient.ExecuteSimplePrompt({
388
+ systemPrompt: 'You are a helpful data analyst',
389
+ messages: [
390
+ { message: 'What are the key trends?', role: 'user' },
391
+ { message: 'Based on the data...', role: 'assistant' },
392
+ { message: 'Can you elaborate?', role: 'user' }
393
+ ],
394
+ preferredModels: ['gpt-4', 'claude-3'],
395
+ modelPower: 'medium', // 'lowest', 'medium', or 'highest'
396
+ responseFormat: 'json'
397
+ });
398
+
399
+ if (result.success) {
400
+ console.log('Response:', result.result);
401
+ console.log('Model Used:', result.modelName);
402
+
403
+ // If response contains JSON
404
+ if (result.resultObject) {
405
+ console.log('Parsed JSON:', result.resultObject);
406
+ }
407
+ }
408
+ return result;
409
+ }
410
+
411
+ // Generate text embeddings
412
+ async function generateEmbeddings() {
413
+ // Single text embedding
414
+ const single = await aiClient.EmbedText({
415
+ textToEmbed: 'This is a sample text',
416
+ modelSize: 'small' // 'small' or 'medium'
417
+ });
418
+
419
+ console.log('Embedding:', single.embeddings); // number[]
420
+ console.log('Dimensions:', single.vectorDimensions);
421
+
422
+ // Multiple text embeddings (batch)
423
+ const batch = await aiClient.EmbedText({
424
+ textToEmbed: [
425
+ 'First text to embed',
426
+ 'Second text to embed',
427
+ 'Third text to embed'
428
+ ],
429
+ modelSize: 'medium'
430
+ });
431
+
432
+ console.log('Embeddings:', batch.embeddings); // number[][]
433
+ console.log('Model:', batch.modelName);
434
+
435
+ return batch;
436
+ }
437
+
438
+ // Run an AI agent for conversational interactions
439
+ async function runAIAgent() {
440
+ const result = await aiClient.RunAIAgent({
441
+ agentId: 'agent-456',
442
+ messages: [
443
+ { role: 'user', content: 'Hello, I need help with data analysis' },
444
+ { role: 'assistant', content: 'I can help you analyze your data' },
445
+ { role: 'user', content: 'What patterns do you see?' }
446
+ ],
447
+ sessionId: 'session-789',
448
+ data: { contextData: 'relevant information' }
449
+ });
450
+
451
+ if (result.success) {
452
+ console.log('Agent Response:', result.payload);
453
+ console.log('Execution Time:', result.executionTimeMs, 'ms');
454
+ }
455
+ return result;
456
+ }
457
+ ```
458
+
355
459
  ### System User Client
356
460
 
357
461
  ```typescript
@@ -380,6 +484,43 @@ if (result.Success) {
380
484
  console.log('Query results:', result.Results);
381
485
  }
382
486
 
487
+ // AI Operations with system privileges
488
+ async function systemAIOperations() {
489
+ // Run AI prompt as system user
490
+ const promptResult = await systemClient.RunAIPrompt({
491
+ promptId: 'system-prompt-123',
492
+ skipValidation: true,
493
+ data: { systemContext: 'internal data' }
494
+ });
495
+
496
+ // Execute simple prompt as system user
497
+ const simpleResult = await systemClient.ExecuteSimplePrompt({
498
+ systemPrompt: 'Analyze system performance',
499
+ modelPower: 'highest'
500
+ });
501
+
502
+ // Generate embeddings as system user
503
+ const embeddings = await systemClient.EmbedText({
504
+ textToEmbed: ['System log entry 1', 'System log entry 2'],
505
+ modelSize: 'medium'
506
+ });
507
+
508
+ return { promptResult, simpleResult, embeddings };
509
+ }
510
+
511
+ // Run AI agent as system user
512
+ async function systemAgentOperation() {
513
+ const result = await systemClient.RunAIAgent({
514
+ agentId: 'system-agent-123',
515
+ messages: [
516
+ { role: 'system', content: 'Process batch data' }
517
+ ],
518
+ sessionId: 'system-session-456'
519
+ });
520
+
521
+ return result;
522
+ }
523
+
383
524
  // Sync roles and users
384
525
  const syncResult = await systemClient.SyncRolesAndUsers({
385
526
  Roles: [
@@ -406,6 +547,7 @@ const syncResult = await systemClient.SyncRolesAndUsers({
406
547
  | `GraphQLDataProvider` | Main class implementing IEntityDataProvider, IMetadataProvider, IRunViewProvider, IRunReportProvider, and IRunQueryProvider interfaces |
407
548
  | `GraphQLProviderConfigData` | Configuration class for setting up the GraphQL provider with authentication and connection details |
408
549
  | `GraphQLActionClient` | Client for executing actions and entity actions through GraphQL |
550
+ | `GraphQLAIClient` | Client for AI operations including prompts, agents, and embeddings |
409
551
  | `GraphQLSystemUserClient` | Specialized client for server-to-server communication using API keys |
410
552
  | `GraphQLTransactionGroup` | Manages complex multi-entity transactions with variable support |
411
553
  | `FieldMapper` | Handles automatic field name mapping between client and server |
@@ -440,6 +582,12 @@ const syncResult = await systemClient.SyncRolesAndUsers({
440
582
  - `GetEntityRecordNames(info: EntityRecordNameInput[])` - Get display names for multiple records
441
583
  - `GetEntityDependencies(entityName: string, compositeKey: CompositeKey)` - Get record dependencies
442
584
 
585
+ #### AI Operations (via GraphQLAIClient)
586
+ - `RunAIPrompt(params: RunAIPromptParams)` - Execute a stored AI prompt with parameters
587
+ - `RunAIAgent(params: RunAIAgentParams)` - Run an AI agent for conversational interactions
588
+ - `ExecuteSimplePrompt(params: ExecuteSimplePromptParams)` - Execute ad-hoc prompts without stored configuration
589
+ - `EmbedText(params: EmbedTextParams)` - Generate text embeddings using local models
590
+
443
591
  ## Dependencies
444
592
 
445
593
  - `@memberjunction/core` - Core MemberJunction functionality