@memberjunction/ai 2.40.0 → 2.42.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 +2 -2
  2. package/readme.md +61 -68
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@memberjunction/ai",
3
- "version": "2.40.0",
3
+ "version": "2.42.0",
4
4
  "description": "MemberJunction: AI Module - LLMs and other AI services wrapped and abstracted for use in MemberJunction",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -15,7 +15,7 @@
15
15
  "author": "MemberJunction.com",
16
16
  "license": "ISC",
17
17
  "dependencies": {
18
- "@memberjunction/global": "2.40.0",
18
+ "@memberjunction/global": "2.42.0",
19
19
  "dotenv": "^16.4.1",
20
20
  "rxjs": "^7.8.1",
21
21
  "typeorm": "^0.3.20"
package/readme.md CHANGED
@@ -1,6 +1,17 @@
1
1
  # @memberjunction/ai
2
2
 
3
- The MemberJunction AI Core package provides a comprehensive abstraction layer for working with various AI models (LLMs, embedding models, etc.) in a provider-agnostic way, allowing your application to easily switch between different AI providers without refactoring your code.
3
+ The MemberJunction AI Core package provides a comprehensive abstraction layer for working with various AI models (LLMs, Video and Audio Generation, Text-To-Speech (TTS), embedding models, etc.) in a provider-agnostic way, allowing your application to easily switch between different AI providers without refactoring your code.
4
+
5
+ ## Standalone Usage
6
+
7
+ **IMPORTANT**: This package can be used completely independently from the rest of the MemberJunction framework:
8
+
9
+ - **Zero** database setup required
10
+ - No environment variables or other settings expected (you are responsible for this and pass in API keys to the constructors)
11
+ - Works in any TypeScript environment that can safely make API calls (e.g. don't use in browsers)
12
+ - Perfect for server-side applications, backend services, and CLI tools
13
+
14
+ The `@memberjunction/ai` package and all provider packages in `@memberjunction/ai-*` are designed to be lightweight, standalone modules that can be used in any TypeScript project.
4
15
 
5
16
  ## Features
6
17
 
@@ -30,29 +41,7 @@ npm install @memberjunction/ai-mistral
30
41
 
31
42
  ## Usage
32
43
 
33
- ### Direct Provider Usage
34
-
35
- Directly use a specific AI provider when you know which one you need:
36
-
37
- ```typescript
38
- import { OpenAILLM } from '@memberjunction/ai-openai';
39
-
40
- // Create an instance with your API key
41
- const llm = new OpenAILLM('your-openai-api-key');
42
-
43
- // Use the provider-specific implementation
44
- const result = await llm.ChatCompletion({
45
- model: 'gpt-4',
46
- messages: [
47
- { role: 'system', content: 'You are a helpful assistant.' },
48
- { role: 'user', content: 'What is AI abstraction?' }
49
- ]
50
- });
51
-
52
- console.log(result.data.choices[0].message.content);
53
- ```
54
-
55
- ### Provider-Agnostic Usage
44
+ ### Provider-Agnostic Usage (Recommended)
56
45
 
57
46
  For maximum flexibility, use the class factory approach to select the provider at runtime:
58
47
 
@@ -60,7 +49,11 @@ For maximum flexibility, use the class factory approach to select the provider a
60
49
  import { BaseLLM, ChatParams } from '@memberjunction/ai';
61
50
  import { MJGlobal } from '@memberjunction/global';
62
51
 
63
- // Get the highest registered implementation of BaseLLM
52
+ // Required to stop tree-shaking of the MistralLLM - since there's no static code path to this class when using Class Factory pattern, you need this to prevent some bundlers from tree-shaking optimization on this class.
53
+ import { LoadMistralLLM } from '@memberjunction/ai-mistral';
54
+ LoadMistralLLM();
55
+
56
+ // Get an implementation of BaseLLM by provider name
64
57
  const llm = MJGlobal.Instance.ClassFactory.CreateInstance<BaseLLM>(
65
58
  BaseLLM,
66
59
  'MistralLLM', // Provider class name
@@ -88,6 +81,10 @@ import { BaseLLM } from '@memberjunction/ai';
88
81
  import { MJGlobal } from '@memberjunction/global';
89
82
  import dotenv from 'dotenv';
90
83
 
84
+ // Required to stop tree-shaking of the OpenAILLM - since there's no static code path to this class when using Class Factory pattern, you need this to prevent some bundlers from tree-shaking optimization on this class.
85
+ import { LoadOpenAILLM } from '@memberjunction/ai-openai';
86
+ LoadOpenAILLM();
87
+
91
88
  dotenv.config();
92
89
 
93
90
  const providerName = process.env.AI_PROVIDER || 'OpenAILLM';
@@ -100,6 +97,29 @@ const llm = MJGlobal.Instance.ClassFactory.CreateInstance<BaseLLM>(
100
97
  );
101
98
  ```
102
99
 
100
+ ### Direct Provider Usage
101
+
102
+ When necessary, you can directly use a specific AI provider:
103
+
104
+ ```typescript
105
+ import { OpenAILLM } from '@memberjunction/ai-openai';
106
+
107
+ // Note with direct use of the OpenAILLM class no need for the LoadOpenAILLM call to prevent tree shaking since there is a static code path to the class
108
+ // Create an instance with your API key
109
+ const llm = new OpenAILLM('your-openai-api-key');
110
+
111
+ // Use the provider-specific implementation
112
+ const result = await llm.ChatCompletion({
113
+ model: 'gpt-4',
114
+ messages: [
115
+ { role: 'system', content: 'You are a helpful assistant.' },
116
+ { role: 'user', content: 'What is AI abstraction?' }
117
+ ]
118
+ });
119
+
120
+ console.log(result.data.choices[0].message.content);
121
+ ```
122
+
103
123
  ## Core Abstractions
104
124
 
105
125
  ### Base Models
@@ -136,7 +156,7 @@ const result: ChatResult = await llm.ChatCompletion(params);
136
156
 
137
157
  ### Streaming Chat Completion
138
158
 
139
- For real-time streaming of responses (supported by most modern LLM providers):
159
+ For real-time streaming of responses:
140
160
 
141
161
  ```typescript
142
162
  import { ChatParams, ChatResult, ChatMessage, StreamingChatCallbacks } from '@memberjunction/ai';
@@ -180,26 +200,6 @@ const params: ChatParams = {
180
200
  await llm.ChatCompletion(params);
181
201
  ```
182
202
 
183
- ### Checking Streaming Support
184
-
185
- Check if a provider supports streaming before enabling it:
186
-
187
- ```typescript
188
- // Check if the provider supports streaming
189
- if (llm.SupportsStreaming) {
190
- console.log("Provider supports streaming!");
191
- params.streaming = true;
192
- params.streamingCallbacks = callbacks;
193
- } else {
194
- console.log("Provider doesn't support streaming, using standard request");
195
- params.streaming = false;
196
- }
197
-
198
- // The call automatically handles both streaming and non-streaming paths
199
- await llm.ChatCompletion(params);
200
- ```
201
-
202
-
203
203
  ### Text Summarization
204
204
 
205
205
  For summarizing longer text content:
@@ -282,29 +282,24 @@ console.log('Completion Tokens:', result.data.usage.completionTokens);
282
282
  console.log('Total Tokens:', result.data.usage.totalTokens);
283
283
  ```
284
284
 
285
- ## Provider Streaming Support
286
-
287
- The following providers support streaming in the current implementation:
288
-
289
- | Provider | Streaming Support |
290
- |----------|------------------|
291
- | OpenAI | ✅ Full support |
292
- | Anthropic | ✅ Full support |
293
- | Mistral | ✅ Full support |
294
- | Groq | ✅ Full support |
295
- | Gemini | ✅ Full support |
296
- | BettyBot | ❌ Not supported |
297
-
298
285
  ## Available Providers
299
286
 
300
287
  The following provider packages implement the MemberJunction AI abstractions:
301
288
 
302
- - `@memberjunction/ai-openai` - OpenAI (GPT models)
303
- - `@memberjunction/ai-anthropic` - Anthropic (Claude models)
304
- - `@memberjunction/ai-mistral` - Mistral AI
305
- - `@memberjunction/ai-gemini` - Google's Gemini models
306
- - `@memberjunction/ai-groq` - Groq's optimized inference
307
- - `@memberjunction/ai-bettybot` - BettyBot AI
289
+ - [`@memberjunction/ai-openai`](../Providers/OpenAI/readme.md) - OpenAI (GPT models)
290
+ - [`@memberjunction/ai-anthropic`](../Providers/Anthropic/readme.md) - Anthropic (Claude models)
291
+ - [`@memberjunction/ai-mistral`](../Providers/Mistral/readme.md) - Mistral AI
292
+ - [`@memberjunction/ai-gemini`](../Providers/Gemini/readme.md) - Google's Gemini models
293
+ - [`@memberjunction/ai-vertex`](../Providers/Vertex/readme.md) - Google Vertex AI (various models including Gemini, others)
294
+ - [`@memberjunction/ai-bedrock`](../Providers/Bedrock/readme.md) - Amazon Bedrock (Claude, Llama, Titan, etc.)
295
+ - [`@memberjunction/ai-groq`](../Providers/Groq/readme.md) - Groq's optimized inference (https://www.groq.com)
296
+ - [`@memberjunction/ai-bettybot`](../Providers/BettyBot/readme.md) - Betty AI (https://www.meetbetty.ai)
297
+ - [`@memberjunction/ai-azure`](../Providers/Azure/readme.md) - Azure AI Foundry with support for OpenAI, Mistral, Phi, more
298
+ - [`@memberjunction/ai-cerebras`](../Providers/Cerebras/readme.md) - Cerebras models
299
+ - [`@memberjunction/ai-elevenlabs`](../Providers/ElevenLabs/readme.md) - ElevenLabs audio models
300
+ - [`@memberjunction/ai-heygen`](../Providers/HeyGen/readme.md) - HeyGen video models
301
+
302
+ Note: Each provider implements the features they support. See individual provider documentation for specific capabilities.
308
303
 
309
304
  ## Implementation Details
310
305
 
@@ -325,8 +320,6 @@ This architecture allows for a clean separation between common streaming logic a
325
320
 
326
321
  - `@memberjunction/global` - MemberJunction global utilities including class factory
327
322
  - `rxjs` - Reactive extensions for JavaScript
328
- - `typeorm` - ORM for database operations
329
323
 
330
324
  ## License
331
-
332
- ISC
325
+ See the [repository root](../../../LICENSE) for license information.