@memberjunction/ai-openai 5.14.0 → 5.16.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/package.json +3 -3
- package/readme.md +35 -31
- package/README.md +0 -164
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@memberjunction/ai-openai",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "5.
|
|
4
|
+
"version": "5.16.0",
|
|
5
5
|
"description": "MemberJunction Wrapper for OpenAI AI Models",
|
|
6
6
|
"main": "dist/index.js",
|
|
7
7
|
"types": "dist/index.d.ts",
|
|
@@ -21,8 +21,8 @@
|
|
|
21
21
|
"typescript": "^5.9.3"
|
|
22
22
|
},
|
|
23
23
|
"dependencies": {
|
|
24
|
-
"@memberjunction/ai": "5.
|
|
25
|
-
"@memberjunction/global": "5.
|
|
24
|
+
"@memberjunction/ai": "5.16.0",
|
|
25
|
+
"@memberjunction/global": "5.16.0",
|
|
26
26
|
"openai": "6.18.0"
|
|
27
27
|
},
|
|
28
28
|
"repository": {
|
package/readme.md
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
|
+
[Back to AI Framework Overview](../../README.md) | [All Providers](../README.md)
|
|
2
|
+
|
|
1
3
|
# @memberjunction/ai-openai
|
|
2
4
|
|
|
3
|
-
MemberJunction AI provider for OpenAI.
|
|
5
|
+
MemberJunction AI provider for OpenAI. Implements `BaseLLM`, `BaseEmbeddings`, `BaseImageGenerator`, and `BaseAudio` from `@memberjunction/ai`. This is the foundational LLM provider in MemberJunction -- many other providers (Groq, Cerebras, Fireworks, OpenRouter, LMStudio, xAI) extend this package since they use OpenAI-compatible APIs.
|
|
4
6
|
|
|
5
7
|
## Architecture
|
|
6
8
|
|
|
@@ -44,15 +46,17 @@ graph TD
|
|
|
44
46
|
|
|
45
47
|
## Features
|
|
46
48
|
|
|
47
|
-
- **Chat Completions**: Full support for GPT-4, GPT-4o, o1, o3, and other OpenAI models
|
|
49
|
+
- **Chat Completions**: Full support for GPT-4.1, GPT-4o, o1, o3, o4-mini, and other OpenAI models
|
|
48
50
|
- **Streaming**: Real-time response streaming with chunk processing
|
|
49
|
-
- **Thinking/Reasoning**: Extraction of thinking content from
|
|
50
|
-
- **Embeddings**: Text embedding generation via
|
|
51
|
-
- **
|
|
52
|
-
- **
|
|
51
|
+
- **Thinking/Reasoning**: Extraction of thinking content from reasoning model responses
|
|
52
|
+
- **Embeddings**: Text embedding generation via text-embedding-3-small/large and other models
|
|
53
|
+
- **Image Generation**: DALL-E integration via `BaseImageGenerator`
|
|
54
|
+
- **Audio**: Text-to-speech and speech-to-text via `BaseAudio`
|
|
55
|
+
- **Multimodal Input**: Support for text, image, audio, and file content in messages
|
|
56
|
+
- **Response Formats**: JSON mode, text, and structured output controls
|
|
53
57
|
- **Effort Level**: Maps MJ effort levels to OpenAI reasoning effort parameters
|
|
54
58
|
- **Error Analysis**: Integrated error analysis via `ErrorAnalyzer`
|
|
55
|
-
- **Extensible Base**: Designed as the foundation for OpenAI-compatible
|
|
59
|
+
- **Extensible Base**: Designed as the foundation for any OpenAI-compatible provider
|
|
56
60
|
|
|
57
61
|
## Installation
|
|
58
62
|
|
|
@@ -65,18 +69,18 @@ npm install @memberjunction/ai-openai
|
|
|
65
69
|
### Chat Completion
|
|
66
70
|
|
|
67
71
|
```typescript
|
|
68
|
-
import { OpenAILLM } from
|
|
72
|
+
import { OpenAILLM } from "@memberjunction/ai-openai";
|
|
69
73
|
|
|
70
|
-
const llm = new OpenAILLM(
|
|
74
|
+
const llm = new OpenAILLM("your-openai-api-key");
|
|
71
75
|
|
|
72
76
|
const result = await llm.ChatCompletion({
|
|
73
|
-
model:
|
|
77
|
+
model: "gpt-4.1",
|
|
74
78
|
messages: [
|
|
75
|
-
{ role:
|
|
76
|
-
{ role:
|
|
79
|
+
{ role: "system", content: "You are a helpful assistant." },
|
|
80
|
+
{ role: "user", content: "Explain quantum computing." },
|
|
77
81
|
],
|
|
78
82
|
temperature: 0.7,
|
|
79
|
-
maxOutputTokens: 1000
|
|
83
|
+
maxOutputTokens: 1000,
|
|
80
84
|
});
|
|
81
85
|
|
|
82
86
|
if (result.success) {
|
|
@@ -88,26 +92,26 @@ if (result.success) {
|
|
|
88
92
|
|
|
89
93
|
```typescript
|
|
90
94
|
const result = await llm.ChatCompletion({
|
|
91
|
-
model:
|
|
92
|
-
messages: [{ role:
|
|
95
|
+
model: "gpt-4.1",
|
|
96
|
+
messages: [{ role: "user", content: "Write a detailed essay." }],
|
|
93
97
|
streaming: true,
|
|
94
98
|
streamingCallbacks: {
|
|
95
99
|
OnContent: (content) => process.stdout.write(content),
|
|
96
|
-
OnComplete: (result) => console.log(
|
|
97
|
-
}
|
|
100
|
+
OnComplete: (result) => console.log("\nDone!"),
|
|
101
|
+
},
|
|
98
102
|
});
|
|
99
103
|
```
|
|
100
104
|
|
|
101
105
|
### Embeddings
|
|
102
106
|
|
|
103
107
|
```typescript
|
|
104
|
-
import { OpenAIEmbedding } from
|
|
108
|
+
import { OpenAIEmbedding } from "@memberjunction/ai-openai";
|
|
105
109
|
|
|
106
|
-
const embedder = new OpenAIEmbedding(
|
|
110
|
+
const embedder = new OpenAIEmbedding("your-openai-api-key");
|
|
107
111
|
|
|
108
112
|
const result = await embedder.EmbedText({
|
|
109
|
-
text:
|
|
110
|
-
model:
|
|
113
|
+
text: "Sample text for embedding",
|
|
114
|
+
model: "text-embedding-3-small",
|
|
111
115
|
});
|
|
112
116
|
|
|
113
117
|
console.log(`Dimensions: ${result.vector.length}`);
|
|
@@ -132,21 +136,21 @@ console.log(`Dimensions: ${result.vector.length}`);
|
|
|
132
136
|
|
|
133
137
|
## Extending for Compatible APIs
|
|
134
138
|
|
|
135
|
-
This provider is designed as a base class for any OpenAI-compatible API.
|
|
139
|
+
This provider is designed as a base class for any OpenAI-compatible API. Override the base URL to point to a different service:
|
|
136
140
|
|
|
137
141
|
```typescript
|
|
138
|
-
import { OpenAILLM } from
|
|
139
|
-
import { RegisterClass } from
|
|
140
|
-
import { BaseLLM } from
|
|
142
|
+
import { OpenAILLM } from "@memberjunction/ai-openai";
|
|
143
|
+
import { RegisterClass } from "@memberjunction/global";
|
|
144
|
+
import { BaseLLM } from "@memberjunction/ai";
|
|
145
|
+
import OpenAI from "openai";
|
|
141
146
|
|
|
142
|
-
@RegisterClass(BaseLLM,
|
|
147
|
+
@RegisterClass(BaseLLM, "MyProviderLLM")
|
|
143
148
|
export class MyProviderLLM extends OpenAILLM {
|
|
144
149
|
constructor(apiKey: string) {
|
|
145
150
|
super(apiKey);
|
|
146
|
-
// Override the base URL
|
|
147
151
|
this._openai = new OpenAI({
|
|
148
|
-
apiKey
|
|
149
|
-
baseURL:
|
|
152
|
+
apiKey,
|
|
153
|
+
baseURL: "https://api.my-provider.com/v1",
|
|
150
154
|
});
|
|
151
155
|
}
|
|
152
156
|
}
|
|
@@ -154,8 +158,8 @@ export class MyProviderLLM extends OpenAILLM {
|
|
|
154
158
|
|
|
155
159
|
## Class Registration
|
|
156
160
|
|
|
157
|
-
- `OpenAILLM` -- Registered via `@RegisterClass(BaseLLM,
|
|
158
|
-
- `OpenAIEmbedding` -- Registered via `@RegisterClass(BaseEmbeddings,
|
|
161
|
+
- `OpenAILLM` -- Registered via `@RegisterClass(BaseLLM, OpenAILLM)`
|
|
162
|
+
- `OpenAIEmbedding` -- Registered via `@RegisterClass(BaseEmbeddings, OpenAIEmbedding)`
|
|
159
163
|
|
|
160
164
|
## Dependencies
|
|
161
165
|
|
package/README.md
DELETED
|
@@ -1,164 +0,0 @@
|
|
|
1
|
-
# @memberjunction/ai-openai
|
|
2
|
-
|
|
3
|
-
MemberJunction AI provider for OpenAI. This is the foundational LLM provider in MemberJunction, implementing `BaseLLM` and `BaseEmbeddings` from `@memberjunction/ai`. Many other providers (Groq, Cerebras, Fireworks, OpenRouter, LMStudio, xAI) extend this package since they use OpenAI-compatible APIs.
|
|
4
|
-
|
|
5
|
-
## Architecture
|
|
6
|
-
|
|
7
|
-
```mermaid
|
|
8
|
-
graph TD
|
|
9
|
-
A["OpenAILLM<br/>(Provider)"] -->|extends| B["BaseLLM<br/>(@memberjunction/ai)"]
|
|
10
|
-
C["OpenAIEmbedding<br/>(Provider)"] -->|extends| D["BaseEmbeddings<br/>(@memberjunction/ai)"]
|
|
11
|
-
A -->|wraps| E["OpenAI SDK<br/>(openai npm)"]
|
|
12
|
-
C -->|wraps| E
|
|
13
|
-
A -->|provides| F["Chat + Streaming"]
|
|
14
|
-
A -->|provides| G["Thinking Extraction"]
|
|
15
|
-
A -->|provides| H["JSON / Response<br/>Format Control"]
|
|
16
|
-
B -->|registered via| I["@RegisterClass"]
|
|
17
|
-
D -->|registered via| I
|
|
18
|
-
|
|
19
|
-
subgraph Subclasses["OpenAI-Compatible Subclasses"]
|
|
20
|
-
J["GroqLLM"]
|
|
21
|
-
K["CerebrasLLM"]
|
|
22
|
-
L["FireworksLLM"]
|
|
23
|
-
M["OpenRouterLLM"]
|
|
24
|
-
N["LMStudioLLM"]
|
|
25
|
-
O["xAILLM"]
|
|
26
|
-
end
|
|
27
|
-
J -->|extends| A
|
|
28
|
-
K -->|extends| A
|
|
29
|
-
L -->|extends| A
|
|
30
|
-
M -->|extends| A
|
|
31
|
-
N -->|extends| A
|
|
32
|
-
O -->|extends| A
|
|
33
|
-
|
|
34
|
-
style A fill:#7c5295,stroke:#563a6b,color:#fff
|
|
35
|
-
style C fill:#7c5295,stroke:#563a6b,color:#fff
|
|
36
|
-
style B fill:#2d6a9f,stroke:#1a4971,color:#fff
|
|
37
|
-
style D fill:#2d6a9f,stroke:#1a4971,color:#fff
|
|
38
|
-
style E fill:#2d8659,stroke:#1a5c3a,color:#fff
|
|
39
|
-
style F fill:#b8762f,stroke:#8a5722,color:#fff
|
|
40
|
-
style G fill:#b8762f,stroke:#8a5722,color:#fff
|
|
41
|
-
style H fill:#b8762f,stroke:#8a5722,color:#fff
|
|
42
|
-
style I fill:#b8762f,stroke:#8a5722,color:#fff
|
|
43
|
-
```
|
|
44
|
-
|
|
45
|
-
## Features
|
|
46
|
-
|
|
47
|
-
- **Chat Completions**: Full support for GPT-4, GPT-4o, o1, o3, and other OpenAI models
|
|
48
|
-
- **Streaming**: Real-time response streaming with chunk processing
|
|
49
|
-
- **Thinking/Reasoning**: Extraction of thinking content from `<think>` blocks in reasoning model responses
|
|
50
|
-
- **Embeddings**: Text embedding generation via OpenAI embedding models
|
|
51
|
-
- **Multimodal Input**: Support for text and image content in messages
|
|
52
|
-
- **Response Formats**: JSON mode, text, and other format controls
|
|
53
|
-
- **Effort Level**: Maps MJ effort levels to OpenAI reasoning effort parameters
|
|
54
|
-
- **Error Analysis**: Integrated error analysis via `ErrorAnalyzer`
|
|
55
|
-
- **Extensible Base**: Designed as the foundation for OpenAI-compatible providers
|
|
56
|
-
|
|
57
|
-
## Installation
|
|
58
|
-
|
|
59
|
-
```bash
|
|
60
|
-
npm install @memberjunction/ai-openai
|
|
61
|
-
```
|
|
62
|
-
|
|
63
|
-
## Usage
|
|
64
|
-
|
|
65
|
-
### Chat Completion
|
|
66
|
-
|
|
67
|
-
```typescript
|
|
68
|
-
import { OpenAILLM } from '@memberjunction/ai-openai';
|
|
69
|
-
|
|
70
|
-
const llm = new OpenAILLM('your-openai-api-key');
|
|
71
|
-
|
|
72
|
-
const result = await llm.ChatCompletion({
|
|
73
|
-
model: 'gpt-4o',
|
|
74
|
-
messages: [
|
|
75
|
-
{ role: 'system', content: 'You are a helpful assistant.' },
|
|
76
|
-
{ role: 'user', content: 'Explain quantum computing.' }
|
|
77
|
-
],
|
|
78
|
-
temperature: 0.7,
|
|
79
|
-
maxOutputTokens: 1000
|
|
80
|
-
});
|
|
81
|
-
|
|
82
|
-
if (result.success) {
|
|
83
|
-
console.log(result.data.choices[0].message.content);
|
|
84
|
-
}
|
|
85
|
-
```
|
|
86
|
-
|
|
87
|
-
### Streaming
|
|
88
|
-
|
|
89
|
-
```typescript
|
|
90
|
-
const result = await llm.ChatCompletion({
|
|
91
|
-
model: 'gpt-4o',
|
|
92
|
-
messages: [{ role: 'user', content: 'Write a detailed essay.' }],
|
|
93
|
-
streaming: true,
|
|
94
|
-
streamingCallbacks: {
|
|
95
|
-
OnContent: (content) => process.stdout.write(content),
|
|
96
|
-
OnComplete: (result) => console.log('\nDone!')
|
|
97
|
-
}
|
|
98
|
-
});
|
|
99
|
-
```
|
|
100
|
-
|
|
101
|
-
### Embeddings
|
|
102
|
-
|
|
103
|
-
```typescript
|
|
104
|
-
import { OpenAIEmbedding } from '@memberjunction/ai-openai';
|
|
105
|
-
|
|
106
|
-
const embedder = new OpenAIEmbedding('your-openai-api-key');
|
|
107
|
-
|
|
108
|
-
const result = await embedder.EmbedText({
|
|
109
|
-
text: 'Sample text for embedding',
|
|
110
|
-
model: 'text-embedding-3-small'
|
|
111
|
-
});
|
|
112
|
-
|
|
113
|
-
console.log(`Dimensions: ${result.vector.length}`);
|
|
114
|
-
```
|
|
115
|
-
|
|
116
|
-
## Supported Parameters
|
|
117
|
-
|
|
118
|
-
| Parameter | Supported | Notes |
|
|
119
|
-
|-----------|-----------|-------|
|
|
120
|
-
| temperature | Yes | 0.0 - 2.0 |
|
|
121
|
-
| maxOutputTokens | Yes | Maximum tokens to generate |
|
|
122
|
-
| topP | Yes | Nucleus sampling |
|
|
123
|
-
| frequencyPenalty | Yes | -2.0 to 2.0 |
|
|
124
|
-
| presencePenalty | Yes | -2.0 to 2.0 |
|
|
125
|
-
| seed | Yes | Deterministic outputs |
|
|
126
|
-
| stopSequences | Yes | Custom stop sequences |
|
|
127
|
-
| responseFormat | Yes | JSON, text modes |
|
|
128
|
-
| streaming | Yes | Real-time streaming |
|
|
129
|
-
| effortLevel | Yes | Maps to reasoning_effort |
|
|
130
|
-
| topK | No | Not supported by OpenAI |
|
|
131
|
-
| minP | No | Not supported by OpenAI |
|
|
132
|
-
|
|
133
|
-
## Extending for Compatible APIs
|
|
134
|
-
|
|
135
|
-
This provider is designed as a base class for any OpenAI-compatible API. To create a new provider, override the base URL:
|
|
136
|
-
|
|
137
|
-
```typescript
|
|
138
|
-
import { OpenAILLM } from '@memberjunction/ai-openai';
|
|
139
|
-
import { RegisterClass } from '@memberjunction/global';
|
|
140
|
-
import { BaseLLM } from '@memberjunction/ai';
|
|
141
|
-
|
|
142
|
-
@RegisterClass(BaseLLM, 'MyProviderLLM')
|
|
143
|
-
export class MyProviderLLM extends OpenAILLM {
|
|
144
|
-
constructor(apiKey: string) {
|
|
145
|
-
super(apiKey);
|
|
146
|
-
// Override the base URL
|
|
147
|
-
this._openai = new OpenAI({
|
|
148
|
-
apiKey: apiKey,
|
|
149
|
-
baseURL: 'https://api.my-provider.com/v1'
|
|
150
|
-
});
|
|
151
|
-
}
|
|
152
|
-
}
|
|
153
|
-
```
|
|
154
|
-
|
|
155
|
-
## Class Registration
|
|
156
|
-
|
|
157
|
-
- `OpenAILLM` -- Registered via `@RegisterClass(BaseLLM, 'OpenAILLM')`
|
|
158
|
-
- `OpenAIEmbedding` -- Registered via `@RegisterClass(BaseEmbeddings, 'OpenAIEmbedding')`
|
|
159
|
-
|
|
160
|
-
## Dependencies
|
|
161
|
-
|
|
162
|
-
- `@memberjunction/ai` - Core AI abstractions
|
|
163
|
-
- `@memberjunction/global` - Class registration
|
|
164
|
-
- `openai` - Official OpenAI SDK
|