@revenium/perplexity 2.0.5 → 2.0.6
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/CHANGELOG.md +113 -97
- package/LICENSE +21 -21
- package/README.md +292 -290
- package/SECURITY.md +34 -34
- package/dist/cjs/core/client/manager.js +6 -3
- package/dist/cjs/core/client/manager.js.map +1 -1
- package/dist/cjs/core/config/validator.js +18 -16
- package/dist/cjs/core/config/validator.js.map +1 -1
- package/dist/cjs/core/middleware/interfaces.js +4 -4
- package/dist/cjs/core/middleware/interfaces.js.map +1 -1
- package/dist/cjs/core/middleware/streaming-wrapper.js +4 -4
- package/dist/cjs/core/middleware/streaming-wrapper.js.map +1 -1
- package/dist/cjs/core/tracking/api-client.js +3 -3
- package/dist/cjs/core/tracking/api-client.js.map +1 -1
- package/dist/cjs/index.js +1 -6
- package/dist/cjs/index.js.map +1 -1
- package/dist/esm/core/client/manager.js +6 -3
- package/dist/esm/core/client/manager.js.map +1 -1
- package/dist/esm/core/config/validator.js +18 -16
- package/dist/esm/core/config/validator.js.map +1 -1
- package/dist/esm/core/middleware/interfaces.js +1 -1
- package/dist/esm/core/middleware/interfaces.js.map +1 -1
- package/dist/esm/core/middleware/streaming-wrapper.js +2 -2
- package/dist/esm/core/middleware/streaming-wrapper.js.map +1 -1
- package/dist/esm/core/tracking/api-client.js +1 -1
- package/dist/esm/core/tracking/api-client.js.map +1 -1
- package/dist/esm/index.js +0 -4
- package/dist/esm/index.js.map +1 -1
- package/dist/types/core/client/manager.d.ts.map +1 -1
- package/dist/types/core/config/validator.d.ts.map +1 -1
- package/dist/types/index.d.ts +0 -5
- package/dist/types/index.d.ts.map +1 -1
- package/examples/README.md +226 -226
- package/examples/advanced.ts +123 -123
- package/examples/basic.ts +45 -45
- package/examples/getting_started.ts +41 -41
- package/examples/metadata.ts +68 -68
- package/examples/stream.ts +53 -53
- package/package.json +72 -71
- package/dist/cjs/constants/models.js +0 -38
- package/dist/cjs/constants/models.js.map +0 -1
- package/dist/esm/constants/models.js +0 -35
- package/dist/esm/constants/models.js.map +0 -1
- package/dist/types/constants/models.d.ts +0 -39
- package/dist/types/constants/models.d.ts.map +0 -1
package/examples/README.md
CHANGED
|
@@ -1,226 +1,226 @@
|
|
|
1
|
-
# Revenium Perplexity Middleware - Examples
|
|
2
|
-
|
|
3
|
-
This directory contains examples demonstrating how to use the Revenium Perplexity middleware.
|
|
4
|
-
|
|
5
|
-
## Prerequisites
|
|
6
|
-
|
|
7
|
-
Before running the examples, make sure you have:
|
|
8
|
-
|
|
9
|
-
1. **Node.js
|
|
10
|
-
2. **Revenium API Key** - Get one from [Revenium Dashboard](https://app.revenium.io)
|
|
11
|
-
3. **Perplexity API Key** - Get one from [Perplexity Platform](https://www.perplexity.ai)
|
|
12
|
-
|
|
13
|
-
## Setup
|
|
14
|
-
|
|
15
|
-
1. **Clone the repository** (if you haven't already):
|
|
16
|
-
|
|
17
|
-
```bash
|
|
18
|
-
git clone https://github.com/revenium/revenium-middleware-perplexity-node.git
|
|
19
|
-
cd revenium-middleware-perplexity-node
|
|
20
|
-
```
|
|
21
|
-
|
|
22
|
-
2. **Install dependencies**:
|
|
23
|
-
|
|
24
|
-
```bash
|
|
25
|
-
npm install
|
|
26
|
-
```
|
|
27
|
-
|
|
28
|
-
3. **Configure environment variables**:
|
|
29
|
-
|
|
30
|
-
Copy the `.env.example` file to `.env` and edit it with your API keys:
|
|
31
|
-
|
|
32
|
-
```bash
|
|
33
|
-
cp .env.example .env
|
|
34
|
-
```
|
|
35
|
-
|
|
36
|
-
See [.env.example](https://github.com/revenium/revenium-middleware-perplexity-node/blob/HEAD/.env.example) for all available configuration options.
|
|
37
|
-
|
|
38
|
-
## Examples
|
|
39
|
-
|
|
40
|
-
### 1. Getting Started
|
|
41
|
-
|
|
42
|
-
**File:** `getting_started.ts`
|
|
43
|
-
|
|
44
|
-
The simplest example to get you started with Revenium tracking:
|
|
45
|
-
|
|
46
|
-
- Initialize the middleware
|
|
47
|
-
- Create a basic chat completion
|
|
48
|
-
- Display response and usage metrics
|
|
49
|
-
|
|
50
|
-
**Run:**
|
|
51
|
-
|
|
52
|
-
```bash
|
|
53
|
-
npm run example:getting-started
|
|
54
|
-
# or
|
|
55
|
-
npx tsx examples/getting_started.ts
|
|
56
|
-
```
|
|
57
|
-
|
|
58
|
-
**What it does:**
|
|
59
|
-
|
|
60
|
-
- Loads configuration from environment variables
|
|
61
|
-
- Creates a simple chat completion request
|
|
62
|
-
- Automatically sends metering data to Revenium API
|
|
63
|
-
- Displays the response
|
|
64
|
-
|
|
65
|
-
---
|
|
66
|
-
|
|
67
|
-
### 2. Basic Usage
|
|
68
|
-
|
|
69
|
-
**File:** `basic.ts`
|
|
70
|
-
|
|
71
|
-
Demonstrates standard Perplexity API usage:
|
|
72
|
-
|
|
73
|
-
- Chat completions with metadata
|
|
74
|
-
- Simple metadata tracking
|
|
75
|
-
|
|
76
|
-
**Run:**
|
|
77
|
-
|
|
78
|
-
```bash
|
|
79
|
-
npm run example:basic
|
|
80
|
-
# or
|
|
81
|
-
npx tsx examples/basic.ts
|
|
82
|
-
```
|
|
83
|
-
|
|
84
|
-
**What it does:**
|
|
85
|
-
|
|
86
|
-
- Creates chat completions with metadata tracking
|
|
87
|
-
- Demonstrates basic metadata usage
|
|
88
|
-
|
|
89
|
-
---
|
|
90
|
-
|
|
91
|
-
### 3. Metadata
|
|
92
|
-
|
|
93
|
-
**File:** `metadata.ts`
|
|
94
|
-
|
|
95
|
-
Demonstrates all available metadata fields:
|
|
96
|
-
|
|
97
|
-
- Complete metadata structure
|
|
98
|
-
- All optional fields documented
|
|
99
|
-
- Subscriber information
|
|
100
|
-
|
|
101
|
-
**Run:**
|
|
102
|
-
|
|
103
|
-
```bash
|
|
104
|
-
npm run example:metadata
|
|
105
|
-
# or
|
|
106
|
-
npx tsx examples/metadata.ts
|
|
107
|
-
```
|
|
108
|
-
|
|
109
|
-
**What it does:**
|
|
110
|
-
|
|
111
|
-
- Shows all available metadata fields
|
|
112
|
-
- Demonstrates subscriber tracking
|
|
113
|
-
- Includes organization and product tracking
|
|
114
|
-
|
|
115
|
-
**Metadata fields supported:**
|
|
116
|
-
|
|
117
|
-
- `traceId` - Session or conversation tracking identifier
|
|
118
|
-
- `taskType` - Type of AI task being performed
|
|
119
|
-
- `agent` - AI agent or bot identifier
|
|
120
|
-
- `organizationId` - Organization identifier
|
|
121
|
-
- `productId` - Product or service identifier
|
|
122
|
-
- `subscriptionId` - Subscription tier identifier
|
|
123
|
-
- `responseQualityScore` - Quality rating (0.0-1.0)
|
|
124
|
-
- `subscriber` - Nested subscriber object with `id`, `email`, `credential` (with `name` and `value`)
|
|
125
|
-
|
|
126
|
-
---
|
|
127
|
-
|
|
128
|
-
### 4. Streaming
|
|
129
|
-
|
|
130
|
-
**File:** `stream.ts`
|
|
131
|
-
|
|
132
|
-
Demonstrates streaming responses:
|
|
133
|
-
|
|
134
|
-
- Real-time token streaming
|
|
135
|
-
- Accumulating responses
|
|
136
|
-
- Streaming metrics
|
|
137
|
-
|
|
138
|
-
**Run:**
|
|
139
|
-
|
|
140
|
-
```bash
|
|
141
|
-
npm run example:stream
|
|
142
|
-
# or
|
|
143
|
-
npx tsx examples/stream.ts
|
|
144
|
-
```
|
|
145
|
-
|
|
146
|
-
**What it does:**
|
|
147
|
-
|
|
148
|
-
- Creates a streaming chat completion
|
|
149
|
-
- Displays tokens as they arrive in real-time
|
|
150
|
-
- Tracks streaming metrics
|
|
151
|
-
- Sends metering data after stream completes
|
|
152
|
-
|
|
153
|
-
---
|
|
154
|
-
|
|
155
|
-
### 5. Advanced Features
|
|
156
|
-
|
|
157
|
-
**File:** `advanced.ts`
|
|
158
|
-
|
|
159
|
-
Demonstrates advanced Perplexity features:
|
|
160
|
-
|
|
161
|
-
- Multi-turn conversations
|
|
162
|
-
- Different temperature settings
|
|
163
|
-
- Multiple Perplexity models
|
|
164
|
-
|
|
165
|
-
**Run:**
|
|
166
|
-
|
|
167
|
-
```bash
|
|
168
|
-
npm run example:advanced
|
|
169
|
-
# or
|
|
170
|
-
npx tsx examples/advanced.ts
|
|
171
|
-
```
|
|
172
|
-
|
|
173
|
-
**What it does:**
|
|
174
|
-
|
|
175
|
-
- Demonstrates multi-turn conversation with system prompt
|
|
176
|
-
- Shows creative responses with higher temperature
|
|
177
|
-
- Uses sonar-reasoning model for complex reasoning tasks
|
|
178
|
-
|
|
179
|
-
---
|
|
180
|
-
|
|
181
|
-
## Common Issues
|
|
182
|
-
|
|
183
|
-
### "Client not initialized" error
|
|
184
|
-
|
|
185
|
-
**Solution:** Make sure to call `Initialize()` before using `GetClient()`.
|
|
186
|
-
|
|
187
|
-
### "REVENIUM_METERING_API_KEY is required" error
|
|
188
|
-
|
|
189
|
-
**Solution:** Set the `REVENIUM_METERING_API_KEY` environment variable in your `.env` file.
|
|
190
|
-
|
|
191
|
-
### "invalid Revenium API key format" error
|
|
192
|
-
|
|
193
|
-
**Solution:** Revenium API keys should start with `hak_`. Check your API key format.
|
|
194
|
-
|
|
195
|
-
### Environment variables not loading
|
|
196
|
-
|
|
197
|
-
**Solution:** Make sure your `.env` file is in the project root directory and contains the required variables.
|
|
198
|
-
|
|
199
|
-
### Perplexity API errors
|
|
200
|
-
|
|
201
|
-
**Solution:** Make sure you have set `PERPLEXITY_API_KEY` in your `.env` file and that it starts with `pplx-`.
|
|
202
|
-
|
|
203
|
-
### Debug Mode
|
|
204
|
-
|
|
205
|
-
Enable detailed logging to troubleshoot issues:
|
|
206
|
-
|
|
207
|
-
```bash
|
|
208
|
-
# In .env file
|
|
209
|
-
REVENIUM_DEBUG=true
|
|
210
|
-
|
|
211
|
-
# Then run examples
|
|
212
|
-
npm run example:getting-started
|
|
213
|
-
```
|
|
214
|
-
|
|
215
|
-
## Next Steps
|
|
216
|
-
|
|
217
|
-
- Check the [main README](https://github.com/revenium/revenium-middleware-perplexity-node/blob/HEAD/README.md) for detailed documentation
|
|
218
|
-
- Visit the [Revenium Dashboard](https://app.revenium.io) to view your metering data
|
|
219
|
-
- See [.env.example](https://github.com/revenium/revenium-middleware-perplexity-node/blob/HEAD/.env.example) for all configuration options
|
|
220
|
-
|
|
221
|
-
## Support
|
|
222
|
-
|
|
223
|
-
For issues or questions:
|
|
224
|
-
|
|
225
|
-
- Documentation: https://docs.revenium.io
|
|
226
|
-
- Email: support@revenium.io
|
|
1
|
+
# Revenium Perplexity Middleware - Examples
|
|
2
|
+
|
|
3
|
+
This directory contains examples demonstrating how to use the Revenium Perplexity middleware.
|
|
4
|
+
|
|
5
|
+
## Prerequisites
|
|
6
|
+
|
|
7
|
+
Before running the examples, make sure you have:
|
|
8
|
+
|
|
9
|
+
1. **Node.js 16 or later** installed
|
|
10
|
+
2. **Revenium API Key** - Get one from [Revenium Dashboard](https://app.revenium.io)
|
|
11
|
+
3. **Perplexity API Key** - Get one from [Perplexity Platform](https://www.perplexity.ai)
|
|
12
|
+
|
|
13
|
+
## Setup
|
|
14
|
+
|
|
15
|
+
1. **Clone the repository** (if you haven't already):
|
|
16
|
+
|
|
17
|
+
```bash
|
|
18
|
+
git clone https://github.com/revenium/revenium-middleware-perplexity-node.git
|
|
19
|
+
cd revenium-middleware-perplexity-node
|
|
20
|
+
```
|
|
21
|
+
|
|
22
|
+
2. **Install dependencies**:
|
|
23
|
+
|
|
24
|
+
```bash
|
|
25
|
+
npm install
|
|
26
|
+
```
|
|
27
|
+
|
|
28
|
+
3. **Configure environment variables**:
|
|
29
|
+
|
|
30
|
+
Copy the `.env.example` file to `.env` and edit it with your API keys:
|
|
31
|
+
|
|
32
|
+
```bash
|
|
33
|
+
cp .env.example .env
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
See [.env.example](https://github.com/revenium/revenium-middleware-perplexity-node/blob/HEAD/.env.example) for all available configuration options.
|
|
37
|
+
|
|
38
|
+
## Examples
|
|
39
|
+
|
|
40
|
+
### 1. Getting Started
|
|
41
|
+
|
|
42
|
+
**File:** `getting_started.ts`
|
|
43
|
+
|
|
44
|
+
The simplest example to get you started with Revenium tracking:
|
|
45
|
+
|
|
46
|
+
- Initialize the middleware
|
|
47
|
+
- Create a basic chat completion
|
|
48
|
+
- Display response and usage metrics
|
|
49
|
+
|
|
50
|
+
**Run:**
|
|
51
|
+
|
|
52
|
+
```bash
|
|
53
|
+
npm run example:getting-started
|
|
54
|
+
# or
|
|
55
|
+
npx tsx examples/getting_started.ts
|
|
56
|
+
```
|
|
57
|
+
|
|
58
|
+
**What it does:**
|
|
59
|
+
|
|
60
|
+
- Loads configuration from environment variables
|
|
61
|
+
- Creates a simple chat completion request
|
|
62
|
+
- Automatically sends metering data to Revenium API
|
|
63
|
+
- Displays the response
|
|
64
|
+
|
|
65
|
+
---
|
|
66
|
+
|
|
67
|
+
### 2. Basic Usage
|
|
68
|
+
|
|
69
|
+
**File:** `basic.ts`
|
|
70
|
+
|
|
71
|
+
Demonstrates standard Perplexity API usage:
|
|
72
|
+
|
|
73
|
+
- Chat completions with metadata
|
|
74
|
+
- Simple metadata tracking
|
|
75
|
+
|
|
76
|
+
**Run:**
|
|
77
|
+
|
|
78
|
+
```bash
|
|
79
|
+
npm run example:basic
|
|
80
|
+
# or
|
|
81
|
+
npx tsx examples/basic.ts
|
|
82
|
+
```
|
|
83
|
+
|
|
84
|
+
**What it does:**
|
|
85
|
+
|
|
86
|
+
- Creates chat completions with metadata tracking
|
|
87
|
+
- Demonstrates basic metadata usage
|
|
88
|
+
|
|
89
|
+
---
|
|
90
|
+
|
|
91
|
+
### 3. Metadata
|
|
92
|
+
|
|
93
|
+
**File:** `metadata.ts`
|
|
94
|
+
|
|
95
|
+
Demonstrates all available metadata fields:
|
|
96
|
+
|
|
97
|
+
- Complete metadata structure
|
|
98
|
+
- All optional fields documented
|
|
99
|
+
- Subscriber information
|
|
100
|
+
|
|
101
|
+
**Run:**
|
|
102
|
+
|
|
103
|
+
```bash
|
|
104
|
+
npm run example:metadata
|
|
105
|
+
# or
|
|
106
|
+
npx tsx examples/metadata.ts
|
|
107
|
+
```
|
|
108
|
+
|
|
109
|
+
**What it does:**
|
|
110
|
+
|
|
111
|
+
- Shows all available metadata fields
|
|
112
|
+
- Demonstrates subscriber tracking
|
|
113
|
+
- Includes organization and product tracking
|
|
114
|
+
|
|
115
|
+
**Metadata fields supported:**
|
|
116
|
+
|
|
117
|
+
- `traceId` - Session or conversation tracking identifier
|
|
118
|
+
- `taskType` - Type of AI task being performed
|
|
119
|
+
- `agent` - AI agent or bot identifier
|
|
120
|
+
- `organizationId` - Organization identifier
|
|
121
|
+
- `productId` - Product or service identifier
|
|
122
|
+
- `subscriptionId` - Subscription tier identifier
|
|
123
|
+
- `responseQualityScore` - Quality rating (0.0-1.0)
|
|
124
|
+
- `subscriber` - Nested subscriber object with `id`, `email`, `credential` (with `name` and `value`)
|
|
125
|
+
|
|
126
|
+
---
|
|
127
|
+
|
|
128
|
+
### 4. Streaming
|
|
129
|
+
|
|
130
|
+
**File:** `stream.ts`
|
|
131
|
+
|
|
132
|
+
Demonstrates streaming responses:
|
|
133
|
+
|
|
134
|
+
- Real-time token streaming
|
|
135
|
+
- Accumulating responses
|
|
136
|
+
- Streaming metrics
|
|
137
|
+
|
|
138
|
+
**Run:**
|
|
139
|
+
|
|
140
|
+
```bash
|
|
141
|
+
npm run example:stream
|
|
142
|
+
# or
|
|
143
|
+
npx tsx examples/stream.ts
|
|
144
|
+
```
|
|
145
|
+
|
|
146
|
+
**What it does:**
|
|
147
|
+
|
|
148
|
+
- Creates a streaming chat completion
|
|
149
|
+
- Displays tokens as they arrive in real-time
|
|
150
|
+
- Tracks streaming metrics
|
|
151
|
+
- Sends metering data after stream completes
|
|
152
|
+
|
|
153
|
+
---
|
|
154
|
+
|
|
155
|
+
### 5. Advanced Features
|
|
156
|
+
|
|
157
|
+
**File:** `advanced.ts`
|
|
158
|
+
|
|
159
|
+
Demonstrates advanced Perplexity features:
|
|
160
|
+
|
|
161
|
+
- Multi-turn conversations
|
|
162
|
+
- Different temperature settings
|
|
163
|
+
- Multiple Perplexity models
|
|
164
|
+
|
|
165
|
+
**Run:**
|
|
166
|
+
|
|
167
|
+
```bash
|
|
168
|
+
npm run example:advanced
|
|
169
|
+
# or
|
|
170
|
+
npx tsx examples/advanced.ts
|
|
171
|
+
```
|
|
172
|
+
|
|
173
|
+
**What it does:**
|
|
174
|
+
|
|
175
|
+
- Demonstrates multi-turn conversation with system prompt
|
|
176
|
+
- Shows creative responses with higher temperature
|
|
177
|
+
- Uses sonar-reasoning model for complex reasoning tasks
|
|
178
|
+
|
|
179
|
+
---
|
|
180
|
+
|
|
181
|
+
## Common Issues
|
|
182
|
+
|
|
183
|
+
### "Client not initialized" error
|
|
184
|
+
|
|
185
|
+
**Solution:** Make sure to call `Initialize()` before using `GetClient()`.
|
|
186
|
+
|
|
187
|
+
### "REVENIUM_METERING_API_KEY is required" error
|
|
188
|
+
|
|
189
|
+
**Solution:** Set the `REVENIUM_METERING_API_KEY` environment variable in your `.env` file.
|
|
190
|
+
|
|
191
|
+
### "invalid Revenium API key format" error
|
|
192
|
+
|
|
193
|
+
**Solution:** Revenium API keys should start with `hak_`. Check your API key format.
|
|
194
|
+
|
|
195
|
+
### Environment variables not loading
|
|
196
|
+
|
|
197
|
+
**Solution:** Make sure your `.env` file is in the project root directory and contains the required variables.
|
|
198
|
+
|
|
199
|
+
### Perplexity API errors
|
|
200
|
+
|
|
201
|
+
**Solution:** Make sure you have set `PERPLEXITY_API_KEY` in your `.env` file and that it starts with `pplx-`.
|
|
202
|
+
|
|
203
|
+
### Debug Mode
|
|
204
|
+
|
|
205
|
+
Enable detailed logging to troubleshoot issues:
|
|
206
|
+
|
|
207
|
+
```bash
|
|
208
|
+
# In .env file
|
|
209
|
+
REVENIUM_DEBUG=true
|
|
210
|
+
|
|
211
|
+
# Then run examples
|
|
212
|
+
npm run example:getting-started
|
|
213
|
+
```
|
|
214
|
+
|
|
215
|
+
## Next Steps
|
|
216
|
+
|
|
217
|
+
- Check the [main README](https://github.com/revenium/revenium-middleware-perplexity-node/blob/HEAD/README.md) for detailed documentation
|
|
218
|
+
- Visit the [Revenium Dashboard](https://app.revenium.io) to view your metering data
|
|
219
|
+
- See [.env.example](https://github.com/revenium/revenium-middleware-perplexity-node/blob/HEAD/.env.example) for all configuration options
|
|
220
|
+
|
|
221
|
+
## Support
|
|
222
|
+
|
|
223
|
+
For issues or questions:
|
|
224
|
+
|
|
225
|
+
- Documentation: https://docs.revenium.io
|
|
226
|
+
- Email: support@revenium.io
|