@push.rocks/smartai 0.12.0 → 0.12.1
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/dist_ts/00_commitinfo_data.js +1 -1
- package/package.json +1 -1
- package/readme.hints.md +23 -193
- package/readme.md +136 -146
- package/ts/00_commitinfo_data.ts +1 -1
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
*/
|
|
4
4
|
export const commitinfo = {
|
|
5
5
|
name: '@push.rocks/smartai',
|
|
6
|
-
version: '0.12.
|
|
6
|
+
version: '0.12.1',
|
|
7
7
|
description: 'SmartAi is a versatile TypeScript library designed to facilitate integration and interaction with various AI models, offering functionalities for chat, audio generation, document processing, and vision tasks.'
|
|
8
8
|
};
|
|
9
9
|
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiMDBfY29tbWl0aW5mb19kYXRhLmpzIiwic291cmNlUm9vdCI6IiIsInNvdXJjZXMiOlsiLi4vdHMvMDBfY29tbWl0aW5mb19kYXRhLnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiJBQUFBOztHQUVHO0FBQ0gsTUFBTSxDQUFDLE1BQU0sVUFBVSxHQUFHO0lBQ3hCLElBQUksRUFBRSxxQkFBcUI7SUFDM0IsT0FBTyxFQUFFLFFBQVE7SUFDakIsV0FBVyxFQUFFLGtOQUFrTjtDQUNoTyxDQUFBIn0=
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@push.rocks/smartai",
|
|
3
|
-
"version": "0.12.
|
|
3
|
+
"version": "0.12.1",
|
|
4
4
|
"private": false,
|
|
5
5
|
"description": "SmartAi is a versatile TypeScript library designed to facilitate integration and interaction with various AI models, offering functionalities for chat, audio generation, document processing, and vision tasks.",
|
|
6
6
|
"main": "dist_ts/index.js",
|
package/readme.hints.md
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
## Dependencies
|
|
4
4
|
|
|
5
5
|
- Uses `@git.zone/tstest` v3.x for testing (import from `@git.zone/tstest/tapbundle`)
|
|
6
|
-
- `@push.rocks/smartfs` v1.x for file system operations
|
|
6
|
+
- `@push.rocks/smartfs` v1.x for file system operations
|
|
7
7
|
- `@anthropic-ai/sdk` v0.71.x with extended thinking support
|
|
8
8
|
- `@mistralai/mistralai` v1.x for Mistral OCR and chat capabilities
|
|
9
9
|
- `openai` v6.x for OpenAI API integration
|
|
@@ -14,12 +14,26 @@
|
|
|
14
14
|
- When extended thinking is enabled, temperature parameter must NOT be set (or set to 1)
|
|
15
15
|
- The `streamNode()` method was removed in smartrequest v5, use `response.stream()` with `Readable.fromWeb()` instead
|
|
16
16
|
|
|
17
|
+
## Provider Capabilities Summary
|
|
18
|
+
|
|
19
|
+
| Provider | Chat | Stream | TTS | Vision | Documents | Research | Images |
|
|
20
|
+
|--------------|------|--------|-----|--------|-----------|----------|--------|
|
|
21
|
+
| OpenAI | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ |
|
|
22
|
+
| Anthropic | ✅ | ✅ | ❌ | ✅ | ✅ | ✅ | ❌ |
|
|
23
|
+
| Mistral | ✅ | ✅ | ❌ | ✅ | ✅ | ❌ | ❌ |
|
|
24
|
+
| ElevenLabs | ❌ | ❌ | ✅ | ❌ | ❌ | ❌ | ❌ |
|
|
25
|
+
| Ollama | ✅ | ✅ | ❌ | ✅ | ✅ | ❌ | ❌ |
|
|
26
|
+
| XAI | ✅ | ✅ | ❌ | ❌ | ✅ | ❌ | ❌ |
|
|
27
|
+
| Perplexity | ✅ | ✅ | ❌ | ❌ | ❌ | ✅ | ❌ |
|
|
28
|
+
| Groq | ✅ | ✅ | ❌ | ❌ | ❌ | ❌ | ❌ |
|
|
29
|
+
| Exo | ✅ | ✅ | ❌ | ❌ | ❌ | ❌ | ❌ |
|
|
30
|
+
|
|
17
31
|
## Mistral Provider Integration
|
|
18
32
|
|
|
19
33
|
### Overview
|
|
20
34
|
|
|
21
35
|
The Mistral provider supports:
|
|
22
|
-
- **Document AI** via Mistral OCR
|
|
36
|
+
- **Document AI** via Mistral OCR (December 2025) - native PDF processing without image conversion
|
|
23
37
|
- **Chat capabilities** using Mistral's chat models (`mistral-large-latest`, etc.)
|
|
24
38
|
|
|
25
39
|
### Key Advantage: Native PDF Support
|
|
@@ -41,47 +55,12 @@ const provider = new smartai.MistralProvider({
|
|
|
41
55
|
await provider.start();
|
|
42
56
|
```
|
|
43
57
|
|
|
44
|
-
### Supported Methods
|
|
45
|
-
|
|
46
|
-
| Method | Support | Notes |
|
|
47
|
-
|--------|---------|-------|
|
|
48
|
-
| `chat()` | ✅ | Standard chat completion |
|
|
49
|
-
| `chatStream()` | ✅ | Streaming chat responses |
|
|
50
|
-
| `document()` | ✅ | Native PDF OCR - no image conversion needed |
|
|
51
|
-
| `vision()` | ✅ | Image OCR with optional chat analysis |
|
|
52
|
-
| `audio()` | ❌ | Not supported - use ElevenLabs |
|
|
53
|
-
| `research()` | ❌ | Not supported - use Perplexity |
|
|
54
|
-
| `imageGenerate()` | ❌ | Not supported - use OpenAI |
|
|
55
|
-
| `imageEdit()` | ❌ | Not supported - use OpenAI |
|
|
56
|
-
|
|
57
|
-
### Document Processing
|
|
58
|
-
|
|
59
|
-
The `document()` method uses Mistral OCR to extract text from PDFs, then uses Mistral chat to process the user's query with the extracted content.
|
|
60
|
-
|
|
61
|
-
```typescript
|
|
62
|
-
const result = await provider.document({
|
|
63
|
-
systemMessage: 'You are a document analyst.',
|
|
64
|
-
userMessage: 'Summarize this document.',
|
|
65
|
-
pdfDocuments: [pdfBuffer],
|
|
66
|
-
messageHistory: [],
|
|
67
|
-
});
|
|
68
|
-
```
|
|
69
|
-
|
|
70
58
|
### API Key
|
|
71
59
|
|
|
72
60
|
Tests require `MISTRAL_API_KEY` in `.nogit/env.json`.
|
|
73
61
|
|
|
74
|
-
### Pricing (as of December 2025)
|
|
75
|
-
|
|
76
|
-
- OCR: $2 per 1,000 pages ($1 with Batch API)
|
|
77
|
-
- Chat: Varies by model (see Mistral pricing page)
|
|
78
|
-
|
|
79
62
|
## Anthropic Extended Thinking Feature
|
|
80
63
|
|
|
81
|
-
### Overview
|
|
82
|
-
|
|
83
|
-
The Anthropic provider now supports extended thinking by default across all methods. Extended thinking enables Claude to spend more time reasoning about complex problems before generating responses, leading to higher quality answers for difficult questions.
|
|
84
|
-
|
|
85
64
|
### Configuration
|
|
86
65
|
|
|
87
66
|
Extended thinking is configured at the provider level during instantiation:
|
|
@@ -97,8 +76,6 @@ const provider = new smartai.AnthropicProvider({
|
|
|
97
76
|
|
|
98
77
|
### Thinking Modes
|
|
99
78
|
|
|
100
|
-
The `extendedThinking` parameter accepts four modes:
|
|
101
|
-
|
|
102
79
|
| Mode | Budget Tokens | Use Case |
|
|
103
80
|
| ---------- | ------------- | ----------------------------------------------- |
|
|
104
81
|
| `'quick'` | 2,048 | Lightweight reasoning for simple queries |
|
|
@@ -106,141 +83,13 @@ The `extendedThinking` parameter accepts four modes:
|
|
|
106
83
|
| `'deep'` | 16,000 | Complex reasoning for difficult problems |
|
|
107
84
|
| `'off'` | 0 | Disable extended thinking |
|
|
108
85
|
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
### Supported Methods
|
|
112
|
-
|
|
113
|
-
Extended thinking is automatically applied to all Anthropic provider methods:
|
|
114
|
-
|
|
115
|
-
- `chat()` - Synchronous chat
|
|
116
|
-
- `chatStream()` - Streaming chat
|
|
117
|
-
- `vision()` - Image analysis
|
|
118
|
-
- `document()` - PDF document processing
|
|
119
|
-
- `research()` - Web research with citations
|
|
120
|
-
|
|
121
|
-
### Token Budget Constraints
|
|
122
|
-
|
|
123
|
-
**Important**: The thinking budget must be less than `max_tokens` for the API call. The current `max_tokens` values are:
|
|
124
|
-
|
|
125
|
-
- `chatStream()`: 20,000 tokens (sufficient for all modes ✓)
|
|
126
|
-
- `chat()`: 20,000 tokens (sufficient for all modes ✓)
|
|
127
|
-
- `vision()`: 10,000 tokens (sufficient for all modes ✓)
|
|
128
|
-
- `document()`: 20,000 tokens (sufficient for all modes ✓)
|
|
129
|
-
- `research()`: 20,000 tokens for all searchDepth levels (sufficient ✓)
|
|
130
|
-
|
|
131
|
-
### Performance and Cost Implications
|
|
132
|
-
|
|
133
|
-
**Token Usage**:
|
|
134
|
-
|
|
135
|
-
- You are charged for the **full thinking tokens** generated, not just the summary
|
|
136
|
-
- Higher thinking budgets may result in more thorough reasoning but increased costs
|
|
137
|
-
- The budget is a **target**, not a strict limit - actual usage may vary
|
|
138
|
-
|
|
139
|
-
**Response Quality**:
|
|
140
|
-
|
|
141
|
-
- `'quick'`: Fast responses, basic reasoning
|
|
142
|
-
- `'normal'`: Good balance between quality and speed (recommended for most use cases)
|
|
143
|
-
- `'deep'`: Highest quality reasoning for complex problems, slower responses
|
|
144
|
-
|
|
145
|
-
**Recommendations**:
|
|
146
|
-
|
|
147
|
-
- Start with `'normal'` (default) for general usage
|
|
148
|
-
- Use `'deep'` for complex analytical tasks, philosophy, mathematics, or research
|
|
149
|
-
- Use `'quick'` for simple factual queries where deep reasoning isn't needed
|
|
150
|
-
- Use `'off'` only if you want traditional Claude behavior without extended thinking
|
|
151
|
-
|
|
152
|
-
### Usage Examples
|
|
153
|
-
|
|
154
|
-
#### Example 1: Default (Normal Mode)
|
|
155
|
-
|
|
156
|
-
```typescript
|
|
157
|
-
const provider = new smartai.AnthropicProvider({
|
|
158
|
-
anthropicToken: process.env.ANTHROPIC_TOKEN,
|
|
159
|
-
// extendedThinking defaults to 'normal'
|
|
160
|
-
});
|
|
161
|
-
|
|
162
|
-
await provider.start();
|
|
163
|
-
|
|
164
|
-
const response = await provider.chat({
|
|
165
|
-
systemMessage: 'You are a helpful assistant.',
|
|
166
|
-
userMessage: 'Explain the implications of quantum computing.',
|
|
167
|
-
messageHistory: [],
|
|
168
|
-
});
|
|
169
|
-
```
|
|
170
|
-
|
|
171
|
-
#### Example 2: Deep Thinking for Complex Analysis
|
|
172
|
-
|
|
173
|
-
```typescript
|
|
174
|
-
const provider = new smartai.AnthropicProvider({
|
|
175
|
-
anthropicToken: process.env.ANTHROPIC_TOKEN,
|
|
176
|
-
extendedThinking: 'deep', // 16,000 token budget
|
|
177
|
-
});
|
|
178
|
-
|
|
179
|
-
await provider.start();
|
|
180
|
-
|
|
181
|
-
const response = await provider.chat({
|
|
182
|
-
systemMessage: 'You are a philosopher and ethicist.',
|
|
183
|
-
userMessage: 'Analyze the trolley problem from multiple ethical frameworks.',
|
|
184
|
-
messageHistory: [],
|
|
185
|
-
});
|
|
186
|
-
```
|
|
187
|
-
|
|
188
|
-
#### Example 3: Quick Mode for Simple Queries
|
|
189
|
-
|
|
190
|
-
```typescript
|
|
191
|
-
const provider = new smartai.AnthropicProvider({
|
|
192
|
-
anthropicToken: process.env.ANTHROPIC_TOKEN,
|
|
193
|
-
extendedThinking: 'quick', // 2,048 token budget
|
|
194
|
-
});
|
|
195
|
-
|
|
196
|
-
await provider.start();
|
|
197
|
-
|
|
198
|
-
const response = await provider.chat({
|
|
199
|
-
systemMessage: 'You are a helpful assistant.',
|
|
200
|
-
userMessage: 'What is the capital of France?',
|
|
201
|
-
messageHistory: [],
|
|
202
|
-
});
|
|
203
|
-
```
|
|
204
|
-
|
|
205
|
-
#### Example 4: Disable Thinking
|
|
206
|
-
|
|
207
|
-
```typescript
|
|
208
|
-
const provider = new smartai.AnthropicProvider({
|
|
209
|
-
anthropicToken: process.env.ANTHROPIC_TOKEN,
|
|
210
|
-
extendedThinking: 'off', // No extended thinking
|
|
211
|
-
});
|
|
212
|
-
|
|
213
|
-
await provider.start();
|
|
214
|
-
|
|
215
|
-
const response = await provider.chat({
|
|
216
|
-
systemMessage: 'You are a helpful assistant.',
|
|
217
|
-
userMessage: 'Tell me a joke.',
|
|
218
|
-
messageHistory: [],
|
|
219
|
-
});
|
|
220
|
-
```
|
|
221
|
-
|
|
222
|
-
#### Example 5: Extended Thinking with Vision
|
|
223
|
-
|
|
224
|
-
```typescript
|
|
225
|
-
const provider = new smartai.AnthropicProvider({
|
|
226
|
-
anthropicToken: process.env.ANTHROPIC_TOKEN,
|
|
227
|
-
extendedThinking: 'normal',
|
|
228
|
-
});
|
|
229
|
-
|
|
230
|
-
await provider.start();
|
|
231
|
-
|
|
232
|
-
const imageBuffer = await fs.promises.readFile('./image.jpg');
|
|
233
|
-
const analysis = await provider.vision({
|
|
234
|
-
image: imageBuffer,
|
|
235
|
-
prompt: 'Analyze this image in detail and explain what you see.',
|
|
236
|
-
});
|
|
237
|
-
```
|
|
238
|
-
|
|
239
|
-
### Testing
|
|
86
|
+
### Implementation Details
|
|
240
87
|
|
|
241
|
-
|
|
88
|
+
- Extended thinking is implemented via `getThinkingConfig()` private method
|
|
89
|
+
- When thinking is enabled, temperature must NOT be set
|
|
90
|
+
- Uses `claude-sonnet-4-5-20250929` model
|
|
242
91
|
|
|
243
|
-
|
|
92
|
+
## Testing
|
|
244
93
|
|
|
245
94
|
Run tests with:
|
|
246
95
|
|
|
@@ -248,27 +97,8 @@ Run tests with:
|
|
|
248
97
|
pnpm test
|
|
249
98
|
```
|
|
250
99
|
|
|
251
|
-
Run specific
|
|
100
|
+
Run specific tests:
|
|
252
101
|
|
|
253
102
|
```bash
|
|
254
|
-
npx tstest test/test.
|
|
103
|
+
npx tstest test/test.something.ts --verbose
|
|
255
104
|
```
|
|
256
|
-
|
|
257
|
-
### API Reference
|
|
258
|
-
|
|
259
|
-
According to Anthropic's documentation:
|
|
260
|
-
|
|
261
|
-
- Extended thinking is supported on Claude Sonnet 4.5, 4, 3.7, Haiku 4.5, and Opus 4.1, 4
|
|
262
|
-
- The current model used is `claude-sonnet-4-5-20250929`
|
|
263
|
-
- Minimum thinking budget is 1,024 tokens
|
|
264
|
-
- Thinking budget must be less than `max_tokens`
|
|
265
|
-
|
|
266
|
-
### Implementation Details
|
|
267
|
-
|
|
268
|
-
The extended thinking feature is implemented via:
|
|
269
|
-
|
|
270
|
-
1. **Interface**: `IAnthropicProviderOptions.extendedThinking` property
|
|
271
|
-
2. **Helper Method**: `getThinkingConfig()` private method that maps modes to token budgets
|
|
272
|
-
3. **API Parameter**: Adds `thinking: { type: 'enabled', budget_tokens: number }` to all API calls
|
|
273
|
-
|
|
274
|
-
The thinking configuration is applied automatically to all API calls when the provider is instantiated.
|
package/readme.md
CHANGED
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
[](https://www.typescriptlang.org/)
|
|
7
7
|
[](https://opensource.org/licenses/MIT)
|
|
8
8
|
|
|
9
|
-
SmartAI unifies the world's leading AI providers
|
|
9
|
+
SmartAI unifies the world's leading AI providers — OpenAI, Anthropic, Mistral, Perplexity, Ollama, Groq, XAI, Exo, and ElevenLabs — under a single, elegant TypeScript interface. Build AI applications at lightning speed without vendor lock-in.
|
|
10
10
|
|
|
11
11
|
## Issue Reporting and Security
|
|
12
12
|
|
|
@@ -14,19 +14,23 @@ For reporting bugs, issues, or security vulnerabilities, please visit [community
|
|
|
14
14
|
|
|
15
15
|
## 🎯 Why SmartAI?
|
|
16
16
|
|
|
17
|
-
- **🔌 Universal Interface**: Write once, run with any AI provider. Switch between GPT-
|
|
18
|
-
- **🛡️ Type-Safe**: Full TypeScript support with comprehensive type definitions for all operations
|
|
19
|
-
- **🌊 Streaming First**: Built for real-time applications with native streaming support
|
|
20
|
-
- **🎨 Multi-Modal**: Seamlessly work with text, images, audio, and documents
|
|
21
|
-
- **🏠 Local & Cloud**: Support for both cloud providers and local models via Ollama
|
|
22
|
-
- **⚡ Zero Lock-In**: Your code remains portable across all AI providers
|
|
17
|
+
- **🔌 Universal Interface**: Write once, run with any AI provider. Switch between GPT-5, Claude, Llama, or Grok with a single line change.
|
|
18
|
+
- **🛡️ Type-Safe**: Full TypeScript support with comprehensive type definitions for all operations.
|
|
19
|
+
- **🌊 Streaming First**: Built for real-time applications with native streaming support.
|
|
20
|
+
- **🎨 Multi-Modal**: Seamlessly work with text, images, audio, and documents.
|
|
21
|
+
- **🏠 Local & Cloud**: Support for both cloud providers and local models via Ollama/Exo.
|
|
22
|
+
- **⚡ Zero Lock-In**: Your code remains portable across all AI providers.
|
|
23
23
|
|
|
24
|
-
##
|
|
24
|
+
## 📦 Installation
|
|
25
25
|
|
|
26
26
|
```bash
|
|
27
27
|
npm install @push.rocks/smartai
|
|
28
|
+
# or
|
|
29
|
+
pnpm install @push.rocks/smartai
|
|
28
30
|
```
|
|
29
31
|
|
|
32
|
+
## 🚀 Quick Start
|
|
33
|
+
|
|
30
34
|
```typescript
|
|
31
35
|
import { SmartAi } from '@push.rocks/smartai';
|
|
32
36
|
|
|
@@ -48,6 +52,8 @@ const response = await ai.openaiProvider.chat({
|
|
|
48
52
|
userMessage: 'Explain quantum computing in simple terms',
|
|
49
53
|
messageHistory: [],
|
|
50
54
|
});
|
|
55
|
+
|
|
56
|
+
console.log(response.message);
|
|
51
57
|
```
|
|
52
58
|
|
|
53
59
|
## 📊 Provider Capabilities Matrix
|
|
@@ -56,15 +62,15 @@ Choose the right provider for your use case:
|
|
|
56
62
|
|
|
57
63
|
| Provider | Chat | Streaming | TTS | Vision | Documents | Research | Images | Highlights |
|
|
58
64
|
| -------------- | :--: | :-------: | :-: | :----: | :-------: | :------: | :----: | --------------------------------------------------------------- |
|
|
59
|
-
| **OpenAI** | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ |
|
|
60
|
-
| **Anthropic** | ✅ | ✅ | ❌ | ✅ | ✅ | ✅ | ❌ |
|
|
61
|
-
| **Mistral** | ✅ | ✅ | ❌ | ✅ | ✅ | ❌ | ❌ |
|
|
62
|
-
| **ElevenLabs** | ❌ | ❌ | ✅ | ❌ | ❌ | ❌ | ❌ |
|
|
63
|
-
| **Ollama** | ✅ | ✅ | ❌ | ✅ | ✅ | ❌ | ❌ |
|
|
64
|
-
| **XAI** | ✅ | ✅ | ❌ | ❌ | ✅ | ❌ | ❌ |
|
|
65
|
-
| **Perplexity** | ✅ | ✅ | ❌ | ❌ | ❌ | ✅ | ❌ |
|
|
66
|
-
| **Groq** | ✅ | ✅ | ❌ | ❌ | ❌ | ❌ | ❌ |
|
|
67
|
-
| **Exo** | ✅ | ✅ | ❌ | ❌ | ❌ | ❌ | ❌ | •
|
|
65
|
+
| **OpenAI** | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | gpt-image-1 • DALL-E 3 • Deep Research API |
|
|
66
|
+
| **Anthropic** | ✅ | ✅ | ❌ | ✅ | ✅ | ✅ | ❌ | Claude Sonnet 4.5 • Extended Thinking • Web Search API |
|
|
67
|
+
| **Mistral** | ✅ | ✅ | ❌ | ✅ | ✅ | ❌ | ❌ | Native PDF OCR • mistral-large • Fast inference |
|
|
68
|
+
| **ElevenLabs** | ❌ | ❌ | ✅ | ❌ | ❌ | ❌ | ❌ | Premium TTS • 70+ languages • v3 model |
|
|
69
|
+
| **Ollama** | ✅ | ✅ | ❌ | ✅ | ✅ | ❌ | ❌ | 100% local • Privacy-first • No API costs |
|
|
70
|
+
| **XAI** | ✅ | ✅ | ❌ | ❌ | ✅ | ❌ | ❌ | Grok 2 • Real-time data |
|
|
71
|
+
| **Perplexity** | ✅ | ✅ | ❌ | ❌ | ❌ | ✅ | ❌ | Web-aware • Research-focused • Sonar Pro |
|
|
72
|
+
| **Groq** | ✅ | ✅ | ❌ | ❌ | ❌ | ❌ | ❌ | 10x faster • LPU inference • Llama 3.3 |
|
|
73
|
+
| **Exo** | ✅ | ✅ | ❌ | ❌ | ❌ | ❌ | ❌ | Distributed • P2P compute • Decentralized |
|
|
68
74
|
|
|
69
75
|
## 🎮 Core Features
|
|
70
76
|
|
|
@@ -73,9 +79,9 @@ Choose the right provider for your use case:
|
|
|
73
79
|
Works identically across all providers:
|
|
74
80
|
|
|
75
81
|
```typescript
|
|
76
|
-
// Use GPT-
|
|
82
|
+
// Use GPT-5 for complex reasoning
|
|
77
83
|
const gptResponse = await ai.openaiProvider.chat({
|
|
78
|
-
systemMessage: 'You are
|
|
84
|
+
systemMessage: 'You are an expert physicist.',
|
|
79
85
|
userMessage: 'Explain the implications of quantum entanglement',
|
|
80
86
|
messageHistory: [],
|
|
81
87
|
});
|
|
@@ -128,20 +134,17 @@ const audioStream = await ai.openaiProvider.audio({
|
|
|
128
134
|
const elevenLabsAudio = await ai.elevenlabsProvider.audio({
|
|
129
135
|
message: 'Experience the most lifelike text to speech technology.',
|
|
130
136
|
voiceId: '19STyYD15bswVz51nqLf', // Optional: Samara voice
|
|
131
|
-
modelId: 'eleven_v3', // Optional: defaults to eleven_v3 (70+ languages
|
|
137
|
+
modelId: 'eleven_v3', // Optional: defaults to eleven_v3 (70+ languages)
|
|
132
138
|
voiceSettings: {
|
|
133
139
|
// Optional: fine-tune voice characteristics
|
|
134
140
|
stability: 0.5, // 0-1: Speech consistency
|
|
135
141
|
similarity_boost: 0.8, // 0-1: Voice similarity to original
|
|
136
|
-
style: 0.0, // 0-1: Expressiveness
|
|
142
|
+
style: 0.0, // 0-1: Expressiveness
|
|
137
143
|
use_speaker_boost: true, // Enhanced clarity
|
|
138
144
|
},
|
|
139
145
|
});
|
|
140
146
|
|
|
141
|
-
// Stream directly to speakers
|
|
142
|
-
audioStream.pipe(speakerOutput);
|
|
143
|
-
|
|
144
|
-
// Or save to file
|
|
147
|
+
// Stream directly to speakers or save to file
|
|
145
148
|
audioStream.pipe(fs.createWriteStream('welcome.mp3'));
|
|
146
149
|
```
|
|
147
150
|
|
|
@@ -158,7 +161,7 @@ const gptVision = await ai.openaiProvider.vision({
|
|
|
158
161
|
prompt: 'Describe this product and suggest marketing angles',
|
|
159
162
|
});
|
|
160
163
|
|
|
161
|
-
// Anthropic: Detailed analysis
|
|
164
|
+
// Anthropic: Detailed analysis with extended thinking
|
|
162
165
|
const claudeVision = await ai.anthropicProvider.vision({
|
|
163
166
|
image,
|
|
164
167
|
prompt: 'Identify any safety concerns or defects',
|
|
@@ -179,7 +182,7 @@ Extract insights from PDFs with AI:
|
|
|
179
182
|
const contract = fs.readFileSync('contract.pdf');
|
|
180
183
|
const invoice = fs.readFileSync('invoice.pdf');
|
|
181
184
|
|
|
182
|
-
// Analyze documents
|
|
185
|
+
// Analyze documents with OpenAI
|
|
183
186
|
const analysis = await ai.openaiProvider.document({
|
|
184
187
|
systemMessage: 'You are a legal expert.',
|
|
185
188
|
userMessage: 'Compare these documents and highlight key differences',
|
|
@@ -187,7 +190,7 @@ const analysis = await ai.openaiProvider.document({
|
|
|
187
190
|
pdfDocuments: [contract, invoice],
|
|
188
191
|
});
|
|
189
192
|
|
|
190
|
-
// Multi-document analysis
|
|
193
|
+
// Multi-document analysis with Anthropic
|
|
191
194
|
const taxDocs = [form1099, w2, receipts];
|
|
192
195
|
const taxAnalysis = await ai.anthropicProvider.document({
|
|
193
196
|
systemMessage: 'You are a tax advisor.',
|
|
@@ -213,6 +216,8 @@ console.log(deepResearch.answer);
|
|
|
213
216
|
console.log('Sources:', deepResearch.sources);
|
|
214
217
|
|
|
215
218
|
// Anthropic Web Search - Domain-filtered research
|
|
219
|
+
import { AnthropicProvider } from '@push.rocks/smartai';
|
|
220
|
+
|
|
216
221
|
const anthropic = new AnthropicProvider({
|
|
217
222
|
anthropicToken: 'sk-ant-...',
|
|
218
223
|
enableWebSearch: true,
|
|
@@ -233,14 +238,14 @@ const perplexityResearch = await ai.perplexityProvider.research({
|
|
|
233
238
|
|
|
234
239
|
**Research Options:**
|
|
235
240
|
|
|
236
|
-
- `searchDepth`: 'basic' | 'advanced' | 'deep'
|
|
241
|
+
- `searchDepth`: `'basic'` | `'advanced'` | `'deep'`
|
|
237
242
|
- `maxSources`: Number of sources to include
|
|
238
243
|
- `includeWebSearch`: Enable web search (OpenAI)
|
|
239
244
|
- `background`: Run as background task (OpenAI)
|
|
240
245
|
|
|
241
246
|
**Supported Providers:**
|
|
242
247
|
|
|
243
|
-
- **OpenAI**: Deep Research API with specialized models (`o3-deep-research
|
|
248
|
+
- **OpenAI**: Deep Research API with specialized models (`o3-deep-research-*`, `o4-mini-deep-research-*`)
|
|
244
249
|
- **Anthropic**: Web Search API with domain filtering
|
|
245
250
|
- **Perplexity**: Sonar and Sonar Pro models with built-in citations
|
|
246
251
|
|
|
@@ -269,12 +274,12 @@ const response = await anthropic.chat({
|
|
|
269
274
|
|
|
270
275
|
**Thinking Modes:**
|
|
271
276
|
|
|
272
|
-
| Mode
|
|
273
|
-
|
|
274
|
-
| `'quick'`
|
|
275
|
-
| `'normal'` | 8,000
|
|
276
|
-
| `'deep'`
|
|
277
|
-
| `'off'`
|
|
277
|
+
| Mode | Budget Tokens | Use Case |
|
|
278
|
+
| ---------- | ------------- | ------------------------------------------------ |
|
|
279
|
+
| `'quick'` | 2,048 | Lightweight reasoning for simple queries |
|
|
280
|
+
| `'normal'` | 8,000 | **Default** — Balanced reasoning for most tasks |
|
|
281
|
+
| `'deep'` | 16,000 | Complex reasoning for difficult problems |
|
|
282
|
+
| `'off'` | 0 | Disable extended thinking |
|
|
278
283
|
|
|
279
284
|
**Best Practices:**
|
|
280
285
|
|
|
@@ -285,16 +290,16 @@ const response = await anthropic.chat({
|
|
|
285
290
|
|
|
286
291
|
### 📑 Native PDF OCR (Mistral)
|
|
287
292
|
|
|
288
|
-
Mistral provides native PDF document processing via their OCR API
|
|
293
|
+
Mistral provides native PDF document processing via their OCR API — no image conversion required:
|
|
289
294
|
|
|
290
295
|
```typescript
|
|
291
296
|
import { MistralProvider } from '@push.rocks/smartai';
|
|
292
297
|
|
|
293
298
|
const mistral = new MistralProvider({
|
|
294
299
|
mistralToken: 'your-api-key',
|
|
295
|
-
chatModel: 'mistral-large-latest',
|
|
296
|
-
ocrModel: 'mistral-ocr-latest',
|
|
297
|
-
tableFormat: 'markdown',
|
|
300
|
+
chatModel: 'mistral-large-latest', // Default
|
|
301
|
+
ocrModel: 'mistral-ocr-latest', // Default
|
|
302
|
+
tableFormat: 'markdown', // 'markdown' | 'html'
|
|
298
303
|
});
|
|
299
304
|
|
|
300
305
|
await mistral.start();
|
|
@@ -311,6 +316,7 @@ const result = await mistral.document({
|
|
|
311
316
|
**Key Advantage**: Unlike other providers that convert PDFs to images first, Mistral's OCR API processes PDFs natively, potentially offering faster and more accurate text extraction for document-heavy workloads.
|
|
312
317
|
|
|
313
318
|
**Supported Formats:**
|
|
319
|
+
|
|
314
320
|
- Native PDF processing via Files API
|
|
315
321
|
- Image OCR (JPEG, PNG, GIF, WebP) for vision tasks
|
|
316
322
|
- Table extraction with markdown or HTML output
|
|
@@ -381,14 +387,14 @@ const editedImage = await ai.openaiProvider.imageEdit({
|
|
|
381
387
|
|
|
382
388
|
**Image Generation Options:**
|
|
383
389
|
|
|
384
|
-
- `model`: 'gpt-image-1' | 'dall-e-3' | 'dall-e-2'
|
|
385
|
-
- `quality`: 'low' | 'medium' | 'high' | 'auto'
|
|
390
|
+
- `model`: `'gpt-image-1'` | `'dall-e-3'` | `'dall-e-2'`
|
|
391
|
+
- `quality`: `'low'` | `'medium'` | `'high'` | `'auto'`
|
|
386
392
|
- `size`: Multiple aspect ratios up to 4096×4096
|
|
387
|
-
- `background`: 'transparent' | 'opaque' | 'auto'
|
|
388
|
-
- `outputFormat`: 'png' | 'jpeg' | 'webp'
|
|
389
|
-
- `outputCompression`: 0
|
|
390
|
-
- `moderation`: 'low' | 'auto'
|
|
391
|
-
- `n`: Number of images (1
|
|
393
|
+
- `background`: `'transparent'` | `'opaque'` | `'auto'`
|
|
394
|
+
- `outputFormat`: `'png'` | `'jpeg'` | `'webp'`
|
|
395
|
+
- `outputCompression`: 0–100 for webp/jpeg
|
|
396
|
+
- `moderation`: `'low'` | `'auto'`
|
|
397
|
+
- `n`: Number of images (1–10)
|
|
392
398
|
|
|
393
399
|
**gpt-image-1 Advantages:**
|
|
394
400
|
|
|
@@ -424,7 +430,7 @@ await inputWriter.write('Now show me how to make it thread-safe');
|
|
|
424
430
|
|
|
425
431
|
```typescript
|
|
426
432
|
const supportBot = new SmartAi({
|
|
427
|
-
anthropicToken: process.env.ANTHROPIC_KEY // Claude for empathetic responses
|
|
433
|
+
anthropicToken: process.env.ANTHROPIC_KEY, // Claude for empathetic responses
|
|
428
434
|
});
|
|
429
435
|
|
|
430
436
|
async function handleCustomerQuery(query: string, history: ChatMessage[]) {
|
|
@@ -433,13 +439,13 @@ async function handleCustomerQuery(query: string, history: ChatMessage[]) {
|
|
|
433
439
|
systemMessage: `You are a helpful customer support agent.
|
|
434
440
|
Be empathetic, professional, and solution-oriented.`,
|
|
435
441
|
userMessage: query,
|
|
436
|
-
messageHistory: history
|
|
442
|
+
messageHistory: history,
|
|
437
443
|
});
|
|
438
444
|
|
|
439
445
|
return response.message;
|
|
440
446
|
} catch (error) {
|
|
441
447
|
// Fallback to another provider if needed
|
|
442
|
-
return await supportBot.openaiProvider.chat({...});
|
|
448
|
+
return await supportBot.openaiProvider.chat({ /* ... */ });
|
|
443
449
|
}
|
|
444
450
|
}
|
|
445
451
|
```
|
|
@@ -452,19 +458,16 @@ const codeReviewer = new SmartAi({
|
|
|
452
458
|
});
|
|
453
459
|
|
|
454
460
|
async function reviewCode(code: string, language: string) {
|
|
455
|
-
const startTime = Date.now();
|
|
456
|
-
|
|
457
461
|
const review = await codeReviewer.groqProvider.chat({
|
|
458
462
|
systemMessage: `You are a ${language} expert. Review code for:
|
|
459
463
|
- Security vulnerabilities
|
|
460
|
-
- Performance issues
|
|
464
|
+
- Performance issues
|
|
461
465
|
- Best practices
|
|
462
466
|
- Potential bugs`,
|
|
463
467
|
userMessage: `Review this code:\n\n${code}`,
|
|
464
468
|
messageHistory: [],
|
|
465
469
|
});
|
|
466
470
|
|
|
467
|
-
console.log(`Review completed in ${Date.now() - startTime}ms`);
|
|
468
471
|
return review.message;
|
|
469
472
|
}
|
|
470
473
|
```
|
|
@@ -478,14 +481,15 @@ const researcher = new SmartAi({
|
|
|
478
481
|
|
|
479
482
|
async function research(topic: string) {
|
|
480
483
|
// Perplexity excels at web-aware research
|
|
481
|
-
const findings = await researcher.perplexityProvider.
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
userMessage: `Research the latest developments in ${topic}`,
|
|
485
|
-
messageHistory: [],
|
|
484
|
+
const findings = await researcher.perplexityProvider.research({
|
|
485
|
+
query: `Research the latest developments in ${topic}`,
|
|
486
|
+
searchDepth: 'deep',
|
|
486
487
|
});
|
|
487
488
|
|
|
488
|
-
return
|
|
489
|
+
return {
|
|
490
|
+
answer: findings.answer,
|
|
491
|
+
sources: findings.sources,
|
|
492
|
+
};
|
|
489
493
|
}
|
|
490
494
|
```
|
|
491
495
|
|
|
@@ -522,23 +526,26 @@ async function analyzeSensitiveDoc(pdfBuffer: Buffer) {
|
|
|
522
526
|
class SmartAIRouter {
|
|
523
527
|
constructor(private ai: SmartAi) {}
|
|
524
528
|
|
|
525
|
-
async query(
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
529
|
+
async query(
|
|
530
|
+
message: string,
|
|
531
|
+
requirements: {
|
|
532
|
+
speed?: boolean;
|
|
533
|
+
accuracy?: boolean;
|
|
534
|
+
cost?: boolean;
|
|
535
|
+
privacy?: boolean;
|
|
536
|
+
}
|
|
537
|
+
) {
|
|
531
538
|
if (requirements.privacy) {
|
|
532
|
-
return this.ai.ollamaProvider.chat({...}); // Local only
|
|
539
|
+
return this.ai.ollamaProvider.chat({ /* ... */ }); // Local only
|
|
533
540
|
}
|
|
534
541
|
if (requirements.speed) {
|
|
535
|
-
return this.ai.groqProvider.chat({...}); // 10x faster
|
|
542
|
+
return this.ai.groqProvider.chat({ /* ... */ }); // 10x faster
|
|
536
543
|
}
|
|
537
544
|
if (requirements.accuracy) {
|
|
538
|
-
return this.ai.anthropicProvider.chat({...}); // Best reasoning
|
|
545
|
+
return this.ai.anthropicProvider.chat({ /* ... */ }); // Best reasoning
|
|
539
546
|
}
|
|
540
547
|
// Default fallback
|
|
541
|
-
return this.ai.openaiProvider.chat({...});
|
|
548
|
+
return this.ai.openaiProvider.chat({ /* ... */ });
|
|
542
549
|
}
|
|
543
550
|
}
|
|
544
551
|
```
|
|
@@ -549,7 +556,7 @@ class SmartAIRouter {
|
|
|
549
556
|
// Don't wait for the entire response
|
|
550
557
|
async function streamResponse(userQuery: string) {
|
|
551
558
|
const stream = await ai.openaiProvider.chatStream(
|
|
552
|
-
createInputStream(userQuery)
|
|
559
|
+
createInputStream(userQuery)
|
|
553
560
|
);
|
|
554
561
|
|
|
555
562
|
// Process tokens as they arrive
|
|
@@ -566,9 +573,9 @@ async function streamResponse(userQuery: string) {
|
|
|
566
573
|
// Get the best answer from multiple AIs
|
|
567
574
|
async function consensusQuery(question: string) {
|
|
568
575
|
const providers = [
|
|
569
|
-
ai.openaiProvider.chat({...}),
|
|
570
|
-
ai.anthropicProvider.chat({...}),
|
|
571
|
-
ai.perplexityProvider.chat({...})
|
|
576
|
+
ai.openaiProvider.chat({ /* ... */ }),
|
|
577
|
+
ai.anthropicProvider.chat({ /* ... */ }),
|
|
578
|
+
ai.perplexityProvider.chat({ /* ... */ }),
|
|
572
579
|
];
|
|
573
580
|
|
|
574
581
|
const responses = await Promise.all(providers);
|
|
@@ -576,21 +583,61 @@ async function consensusQuery(question: string) {
|
|
|
576
583
|
}
|
|
577
584
|
```
|
|
578
585
|
|
|
579
|
-
## 🛠️ Advanced
|
|
586
|
+
## 🛠️ Advanced Configuration
|
|
580
587
|
|
|
581
|
-
###
|
|
588
|
+
### Provider-Specific Options
|
|
582
589
|
|
|
583
590
|
```typescript
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
591
|
+
const ai = new SmartAi({
|
|
592
|
+
// OpenAI
|
|
593
|
+
openaiToken: 'sk-...',
|
|
594
|
+
|
|
595
|
+
// Anthropic with extended thinking
|
|
596
|
+
anthropicToken: 'sk-ant-...',
|
|
597
|
+
|
|
598
|
+
// Perplexity for research
|
|
599
|
+
perplexityToken: 'pplx-...',
|
|
600
|
+
|
|
601
|
+
// Groq for speed
|
|
602
|
+
groqToken: 'gsk_...',
|
|
603
|
+
|
|
604
|
+
// Mistral with OCR settings
|
|
605
|
+
mistralToken: 'your-key',
|
|
606
|
+
mistral: {
|
|
607
|
+
chatModel: 'mistral-large-latest',
|
|
608
|
+
ocrModel: 'mistral-ocr-latest',
|
|
609
|
+
tableFormat: 'markdown',
|
|
589
610
|
},
|
|
590
|
-
});
|
|
591
611
|
|
|
592
|
-
|
|
593
|
-
|
|
612
|
+
// XAI (Grok)
|
|
613
|
+
xaiToken: 'xai-...',
|
|
614
|
+
|
|
615
|
+
// ElevenLabs TTS
|
|
616
|
+
elevenlabsToken: 'sk-...',
|
|
617
|
+
elevenlabs: {
|
|
618
|
+
defaultVoiceId: '19STyYD15bswVz51nqLf',
|
|
619
|
+
defaultModelId: 'eleven_v3',
|
|
620
|
+
},
|
|
621
|
+
|
|
622
|
+
// Ollama (local)
|
|
623
|
+
ollama: {
|
|
624
|
+
baseUrl: 'http://localhost:11434',
|
|
625
|
+
model: 'llama2',
|
|
626
|
+
visionModel: 'llava',
|
|
627
|
+
defaultOptions: {
|
|
628
|
+
num_ctx: 4096,
|
|
629
|
+
temperature: 0.7,
|
|
630
|
+
top_p: 0.9,
|
|
631
|
+
},
|
|
632
|
+
defaultTimeout: 120000,
|
|
633
|
+
},
|
|
634
|
+
|
|
635
|
+
// Exo (distributed)
|
|
636
|
+
exo: {
|
|
637
|
+
baseUrl: 'http://localhost:8080/v1',
|
|
638
|
+
apiKey: 'optional-key',
|
|
639
|
+
},
|
|
640
|
+
});
|
|
594
641
|
```
|
|
595
642
|
|
|
596
643
|
### Error Handling & Fallbacks
|
|
@@ -613,84 +660,27 @@ class ResilientAI {
|
|
|
613
660
|
}
|
|
614
661
|
```
|
|
615
662
|
|
|
616
|
-
### Token Counting & Cost Management
|
|
617
|
-
|
|
618
|
-
```typescript
|
|
619
|
-
// Track usage across providers
|
|
620
|
-
class UsageTracker {
|
|
621
|
-
async trackedChat(provider: string, options: ChatOptions) {
|
|
622
|
-
const start = Date.now();
|
|
623
|
-
const response = await ai[`${provider}Provider`].chat(options);
|
|
624
|
-
|
|
625
|
-
const usage = {
|
|
626
|
-
provider,
|
|
627
|
-
duration: Date.now() - start,
|
|
628
|
-
inputTokens: estimateTokens(options),
|
|
629
|
-
outputTokens: estimateTokens(response.message),
|
|
630
|
-
};
|
|
631
|
-
|
|
632
|
-
await this.logUsage(usage);
|
|
633
|
-
return response;
|
|
634
|
-
}
|
|
635
|
-
}
|
|
636
|
-
```
|
|
637
|
-
|
|
638
|
-
## 📦 Installation & Setup
|
|
639
|
-
|
|
640
|
-
### Prerequisites
|
|
641
|
-
|
|
642
|
-
- Node.js 16+
|
|
643
|
-
- TypeScript 4.5+
|
|
644
|
-
- API keys for your chosen providers
|
|
645
|
-
|
|
646
|
-
### Environment Setup
|
|
647
|
-
|
|
648
|
-
```bash
|
|
649
|
-
# Install
|
|
650
|
-
npm install @push.rocks/smartai
|
|
651
|
-
|
|
652
|
-
# Set up environment variables
|
|
653
|
-
export OPENAI_API_KEY=sk-...
|
|
654
|
-
export ANTHROPIC_API_KEY=sk-ant-...
|
|
655
|
-
export PERPLEXITY_API_KEY=pplx-...
|
|
656
|
-
export ELEVENLABS_API_KEY=sk-...
|
|
657
|
-
# ... etc
|
|
658
|
-
```
|
|
659
|
-
|
|
660
|
-
### TypeScript Configuration
|
|
661
|
-
|
|
662
|
-
```json
|
|
663
|
-
{
|
|
664
|
-
"compilerOptions": {
|
|
665
|
-
"target": "ES2022",
|
|
666
|
-
"module": "NodeNext",
|
|
667
|
-
"lib": ["ES2022"],
|
|
668
|
-
"strict": true,
|
|
669
|
-
"esModuleInterop": true,
|
|
670
|
-
"skipLibCheck": true
|
|
671
|
-
}
|
|
672
|
-
}
|
|
673
|
-
```
|
|
674
|
-
|
|
675
663
|
## 🎯 Choosing the Right Provider
|
|
676
664
|
|
|
677
665
|
| Use Case | Recommended Provider | Why |
|
|
678
666
|
| --------------------- | -------------------- | --------------------------------------------------------- |
|
|
679
667
|
| **General Purpose** | OpenAI | Most features, stable, well-documented |
|
|
680
|
-
| **Complex Reasoning** | Anthropic | Superior logical thinking, safer
|
|
668
|
+
| **Complex Reasoning** | Anthropic | Superior logical thinking, extended thinking, safer |
|
|
681
669
|
| **Document OCR** | Mistral | Native PDF processing, no image conversion overhead |
|
|
682
670
|
| **Research & Facts** | Perplexity | Web-aware, provides citations |
|
|
683
671
|
| **Deep Research** | OpenAI | Deep Research API with comprehensive analysis |
|
|
684
|
-
| **Premium TTS** | ElevenLabs | Most natural voices, 70+ languages,
|
|
672
|
+
| **Premium TTS** | ElevenLabs | Most natural voices, 70+ languages, v3 model |
|
|
685
673
|
| **Speed Critical** | Groq | 10x faster inference, sub-second responses |
|
|
686
674
|
| **Privacy Critical** | Ollama | 100% local, no data leaves your servers |
|
|
687
|
-
| **Real-time Data** | XAI |
|
|
675
|
+
| **Real-time Data** | XAI | Grok with access to current information |
|
|
688
676
|
| **Cost Sensitive** | Ollama/Exo | Free (local) or distributed compute |
|
|
689
677
|
|
|
690
678
|
## 📈 Roadmap
|
|
691
679
|
|
|
692
680
|
- [x] Research & Web Search API
|
|
693
681
|
- [x] Image generation support (gpt-image-1, DALL-E 3, DALL-E 2)
|
|
682
|
+
- [x] Extended thinking (Anthropic)
|
|
683
|
+
- [x] Native PDF OCR (Mistral)
|
|
694
684
|
- [ ] Streaming function calls
|
|
695
685
|
- [ ] Voice input processing
|
|
696
686
|
- [ ] Fine-tuning integration
|
package/ts/00_commitinfo_data.ts
CHANGED
|
@@ -3,6 +3,6 @@
|
|
|
3
3
|
*/
|
|
4
4
|
export const commitinfo = {
|
|
5
5
|
name: '@push.rocks/smartai',
|
|
6
|
-
version: '0.12.
|
|
6
|
+
version: '0.12.1',
|
|
7
7
|
description: 'SmartAi is a versatile TypeScript library designed to facilitate integration and interaction with various AI models, offering functionalities for chat, audio generation, document processing, and vision tasks.'
|
|
8
8
|
}
|