@revenium/perplexity 1.0.20 → 1.0.22
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 +2 -0
- package/dist/index.js +19 -19
- package/dist/interfaces/chatCompletionRequest.d.ts +2 -1
- package/dist/interfaces/credential.d.ts +4 -4
- package/dist/interfaces/credential.js +2 -2
- package/dist/interfaces/meteringRequest.d.ts +13 -13
- package/dist/interfaces/meteringResponse.d.ts +27 -27
- package/dist/interfaces/meteringResponse.js +2 -2
- package/dist/interfaces/operation.d.ts +4 -4
- package/dist/interfaces/operation.js +8 -8
- package/dist/interfaces/subscriber.d.ts +8 -8
- package/dist/interfaces/subscriber.js +2 -2
- package/dist/interfaces/tokenCounts.d.ts +7 -7
- package/dist/interfaces/tokenCounts.js +2 -2
- package/dist/interfaces/usageMetadata.d.ts +14 -0
- package/dist/middleware.d.ts +22 -22
- package/dist/middleware.js +2 -2
- package/dist/models/Logger.js +35 -35
- package/dist/models/Metering.d.ts +1 -1
- package/dist/models/Metering.js +28 -20
- package/dist/utils/calculateDurationMs.d.ts +1 -1
- package/dist/utils/calculateDurationMs.js +6 -6
- package/dist/utils/constants/constants.d.ts +6 -6
- package/dist/utils/constants/constants.js +11 -11
- package/dist/utils/constants/logLevels.d.ts +1 -1
- package/dist/utils/constants/logLevels.js +4 -4
- package/dist/utils/constants/messages.d.ts +5 -5
- package/dist/utils/constants/messages.js +8 -8
- package/dist/utils/constants/models.d.ts +1 -1
- package/dist/utils/constants/models.js +21 -21
- package/dist/utils/extractTokenCount.d.ts +2 -2
- package/dist/utils/extractTokenCount.js +28 -28
- package/dist/utils/formatTimeStamp.d.ts +1 -1
- package/dist/utils/formatTimeStamp.js +6 -6
- package/dist/utils/generateTransactionId.d.ts +1 -1
- package/dist/utils/generateTransactionId.js +7 -7
- package/dist/utils/index.d.ts +6 -6
- package/dist/utils/index.js +23 -23
- package/dist/utils/loadEnv.d.ts +1 -1
- package/dist/utils/loadEnv.js +7 -7
- package/dist/utils/safeExtract.d.ts +29 -29
- package/dist/utils/safeExtract.js +67 -67
- package/package.json +3 -1
- package/playground/basic.js +7 -11
- package/playground/chat-completions.js +22 -0
- package/playground/enhanced.js +6 -9
- package/playground/streaming.js +2 -2
package/README.md
CHANGED
|
@@ -313,6 +313,8 @@ npm run e-metadata # Metadata request
|
|
|
313
313
|
# Playground examples
|
|
314
314
|
# Required build first
|
|
315
315
|
npm run build
|
|
316
|
+
## Change type to module in package.json
|
|
317
|
+
"type": "module",
|
|
316
318
|
# Then run any of the following
|
|
317
319
|
npm run p-basic
|
|
318
320
|
npm run p-streaming
|
package/dist/index.js
CHANGED
|
@@ -1,19 +1,19 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
-
if (k2 === undefined) k2 = k;
|
|
4
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
-
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
-
};
|
|
16
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
-
const dotenv_1 = require("dotenv");
|
|
18
|
-
(0, dotenv_1.config)();
|
|
19
|
-
__exportStar(require("./middleware"), exports);
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
const dotenv_1 = require("dotenv");
|
|
18
|
+
(0, dotenv_1.config)();
|
|
19
|
+
__exportStar(require("./middleware"), exports);
|
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import { ChatCompletionMessageParam } from "openai/resources/index";
|
|
2
|
+
import { IUsageMetadata } from "./usageMetadata";
|
|
2
3
|
export interface IChatCompletionRequest {
|
|
3
4
|
model?: string;
|
|
4
5
|
messages: ChatCompletionMessageParam[];
|
|
5
6
|
stream?: boolean;
|
|
6
|
-
usageMetadata?:
|
|
7
|
+
usageMetadata?: IUsageMetadata;
|
|
7
8
|
[key: string]: any;
|
|
8
9
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export interface ICredential {
|
|
2
|
-
name: string;
|
|
3
|
-
value: string;
|
|
4
|
-
}
|
|
1
|
+
export interface ICredential {
|
|
2
|
+
name: string;
|
|
3
|
+
value: string;
|
|
4
|
+
}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
@@ -1,13 +1,13 @@
|
|
|
1
|
-
import { IOperationType } from "./operation";
|
|
2
|
-
import { ITokenCounts } from "./tokenCounts";
|
|
3
|
-
import { IUsageMetadata } from "./usageMetadata";
|
|
4
|
-
export interface IMeteringRequest {
|
|
5
|
-
transactionId?: string;
|
|
6
|
-
startTime: Date;
|
|
7
|
-
endTime: Date;
|
|
8
|
-
modelName: string;
|
|
9
|
-
tokenCounts: ITokenCounts;
|
|
10
|
-
stopReason: string;
|
|
11
|
-
operationType: IOperationType;
|
|
12
|
-
usageMetadata?: IUsageMetadata;
|
|
13
|
-
}
|
|
1
|
+
import { IOperationType } from "./operation";
|
|
2
|
+
import { ITokenCounts } from "./tokenCounts";
|
|
3
|
+
import { IUsageMetadata } from "./usageMetadata";
|
|
4
|
+
export interface IMeteringRequest {
|
|
5
|
+
transactionId?: string;
|
|
6
|
+
startTime: Date;
|
|
7
|
+
endTime: Date;
|
|
8
|
+
modelName: string;
|
|
9
|
+
tokenCounts: ITokenCounts;
|
|
10
|
+
stopReason: string;
|
|
11
|
+
operationType: IOperationType;
|
|
12
|
+
usageMetadata?: IUsageMetadata;
|
|
13
|
+
}
|
|
@@ -1,27 +1,27 @@
|
|
|
1
|
-
import { ISubscriber } from "./subscriber";
|
|
2
|
-
export interface IMeteringResponse {
|
|
3
|
-
stopReason: string;
|
|
4
|
-
costType: string;
|
|
5
|
-
isStreamed: boolean;
|
|
6
|
-
taskType: string;
|
|
7
|
-
agent: string;
|
|
8
|
-
operationType: string;
|
|
9
|
-
inputTokenCount: number;
|
|
10
|
-
outputTokenCount: number;
|
|
11
|
-
reasoningTokenCount: number;
|
|
12
|
-
cacheCreationTokenCount: number;
|
|
13
|
-
cacheReadTokenCount: number;
|
|
14
|
-
totalTokenCount: number;
|
|
15
|
-
organizationId: string;
|
|
16
|
-
productId: string;
|
|
17
|
-
subscriber: ISubscriber;
|
|
18
|
-
model: string;
|
|
19
|
-
transactionId: string;
|
|
20
|
-
responseTime: string;
|
|
21
|
-
requestDuration: number;
|
|
22
|
-
provider: string;
|
|
23
|
-
requestTime: string;
|
|
24
|
-
completionStartTime: string;
|
|
25
|
-
timeToFirstToken: number;
|
|
26
|
-
middleware_source: string;
|
|
27
|
-
}
|
|
1
|
+
import { ISubscriber } from "./subscriber";
|
|
2
|
+
export interface IMeteringResponse {
|
|
3
|
+
stopReason: string;
|
|
4
|
+
costType: string;
|
|
5
|
+
isStreamed: boolean;
|
|
6
|
+
taskType: string;
|
|
7
|
+
agent: string;
|
|
8
|
+
operationType: string;
|
|
9
|
+
inputTokenCount: number;
|
|
10
|
+
outputTokenCount: number;
|
|
11
|
+
reasoningTokenCount: number;
|
|
12
|
+
cacheCreationTokenCount: number;
|
|
13
|
+
cacheReadTokenCount: number;
|
|
14
|
+
totalTokenCount: number;
|
|
15
|
+
organizationId: string;
|
|
16
|
+
productId: string;
|
|
17
|
+
subscriber: ISubscriber;
|
|
18
|
+
model: string;
|
|
19
|
+
transactionId: string;
|
|
20
|
+
responseTime: string;
|
|
21
|
+
requestDuration: number;
|
|
22
|
+
provider: string;
|
|
23
|
+
requestTime: string;
|
|
24
|
+
completionStartTime: string;
|
|
25
|
+
timeToFirstToken: number;
|
|
26
|
+
middleware_source: string;
|
|
27
|
+
}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export declare enum IOperationType {
|
|
2
|
-
CHAT = "CHAT",
|
|
3
|
-
EMBED = "EMBED"
|
|
4
|
-
}
|
|
1
|
+
export declare enum IOperationType {
|
|
2
|
+
CHAT = "CHAT",
|
|
3
|
+
EMBED = "EMBED"
|
|
4
|
+
}
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.IOperationType = void 0;
|
|
4
|
-
var IOperationType;
|
|
5
|
-
(function (IOperationType) {
|
|
6
|
-
IOperationType["CHAT"] = "CHAT";
|
|
7
|
-
IOperationType["EMBED"] = "EMBED";
|
|
8
|
-
})(IOperationType || (exports.IOperationType = IOperationType = {}));
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.IOperationType = void 0;
|
|
4
|
+
var IOperationType;
|
|
5
|
+
(function (IOperationType) {
|
|
6
|
+
IOperationType["CHAT"] = "CHAT";
|
|
7
|
+
IOperationType["EMBED"] = "EMBED";
|
|
8
|
+
})(IOperationType || (exports.IOperationType = IOperationType = {}));
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
export interface ISubscriber {
|
|
2
|
-
id: string;
|
|
3
|
-
email: string;
|
|
4
|
-
credential: {
|
|
5
|
-
name: string;
|
|
6
|
-
value: string;
|
|
7
|
-
};
|
|
8
|
-
}
|
|
1
|
+
export interface ISubscriber {
|
|
2
|
+
id: string;
|
|
3
|
+
email: string;
|
|
4
|
+
credential: {
|
|
5
|
+
name: string;
|
|
6
|
+
value: string;
|
|
7
|
+
};
|
|
8
|
+
}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
export interface ITokenCounts {
|
|
2
|
-
inputTokens: number;
|
|
3
|
-
outputTokens: number;
|
|
4
|
-
totalTokens: number;
|
|
5
|
-
cachedTokens?: number;
|
|
6
|
-
reasoningTokens?: number;
|
|
7
|
-
}
|
|
1
|
+
export interface ITokenCounts {
|
|
2
|
+
inputTokens: number;
|
|
3
|
+
outputTokens: number;
|
|
4
|
+
totalTokens: number;
|
|
5
|
+
cachedTokens?: number;
|
|
6
|
+
reasoningTokens?: number;
|
|
7
|
+
}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
@@ -10,4 +10,18 @@ export interface IUsageMetadata {
|
|
|
10
10
|
productId?: string;
|
|
11
11
|
agent?: string;
|
|
12
12
|
responseQualityScore?: number;
|
|
13
|
+
transactionId?: string;
|
|
14
|
+
timeToFirstToken?: number;
|
|
15
|
+
requestTime?: Date;
|
|
16
|
+
completionStartTime?: Date;
|
|
17
|
+
operationType?: string;
|
|
18
|
+
inputTokenCount?: number;
|
|
19
|
+
outputTokenCount?: number;
|
|
20
|
+
reasoningTokenCount?: number;
|
|
21
|
+
cacheCreationTokenCount?: number;
|
|
22
|
+
cacheReadTokenCount?: number;
|
|
23
|
+
totalTokenCount?: number;
|
|
24
|
+
responseTime?: Date;
|
|
25
|
+
requestDuration?: number;
|
|
26
|
+
stopReason?: string;
|
|
13
27
|
}
|
package/dist/middleware.d.ts
CHANGED
|
@@ -1,22 +1,22 @@
|
|
|
1
|
-
import OpenAI from "openai";
|
|
2
|
-
import { IChatCompletionRequest } from "./interfaces/chatCompletionRequest";
|
|
3
|
-
import { RequestOptions } from "openai/internal/request-options";
|
|
4
|
-
export declare class PerplexityReveniumMiddleware {
|
|
5
|
-
private client;
|
|
6
|
-
private working;
|
|
7
|
-
private modelName;
|
|
8
|
-
constructor();
|
|
9
|
-
getGenerativeModel(model: string): {
|
|
10
|
-
createChatCompletion: (params: IChatCompletionRequest) => Promise<OpenAI.Chat.Completions.ChatCompletion & {
|
|
11
|
-
_request_id?: string | null | undefined;
|
|
12
|
-
}>;
|
|
13
|
-
createChatCompletionStream: (params: IChatCompletionRequest) => Promise<import("openai/core/streaming").Stream<OpenAI.Chat.Completions.ChatCompletionChunk> & {
|
|
14
|
-
_request_id?: string | null;
|
|
15
|
-
}>;
|
|
16
|
-
createEmbeddings: (_body: Omit<OpenAI.Embeddings.EmbeddingCreateParams, "model">, _options?: RequestOptions) => Promise<void>;
|
|
17
|
-
};
|
|
18
|
-
private embeddings;
|
|
19
|
-
private streamingChatCompletion;
|
|
20
|
-
private chatCompletion;
|
|
21
|
-
private verifyEnv;
|
|
22
|
-
}
|
|
1
|
+
import OpenAI from "openai";
|
|
2
|
+
import { IChatCompletionRequest } from "./interfaces/chatCompletionRequest";
|
|
3
|
+
import { RequestOptions } from "openai/internal/request-options";
|
|
4
|
+
export declare class PerplexityReveniumMiddleware {
|
|
5
|
+
private client;
|
|
6
|
+
private working;
|
|
7
|
+
private modelName;
|
|
8
|
+
constructor();
|
|
9
|
+
getGenerativeModel(model: string): {
|
|
10
|
+
createChatCompletion: (params: IChatCompletionRequest) => Promise<OpenAI.Chat.Completions.ChatCompletion & {
|
|
11
|
+
_request_id?: string | null | undefined;
|
|
12
|
+
}>;
|
|
13
|
+
createChatCompletionStream: (params: IChatCompletionRequest) => Promise<import("openai/core/streaming").Stream<OpenAI.Chat.Completions.ChatCompletionChunk> & {
|
|
14
|
+
_request_id?: string | null;
|
|
15
|
+
}>;
|
|
16
|
+
createEmbeddings: (_body: Omit<OpenAI.Embeddings.EmbeddingCreateParams, "model">, _options?: RequestOptions) => Promise<void>;
|
|
17
|
+
};
|
|
18
|
+
private embeddings;
|
|
19
|
+
private streamingChatCompletion;
|
|
20
|
+
private chatCompletion;
|
|
21
|
+
private verifyEnv;
|
|
22
|
+
}
|
package/dist/middleware.js
CHANGED
|
@@ -44,7 +44,7 @@ class PerplexityReveniumMiddleware {
|
|
|
44
44
|
stopReason: "END",
|
|
45
45
|
tokenCounts,
|
|
46
46
|
usageMetadata,
|
|
47
|
-
});
|
|
47
|
+
}, true);
|
|
48
48
|
await metering.sendMeteringData(getMetering);
|
|
49
49
|
return result;
|
|
50
50
|
}
|
|
@@ -81,7 +81,7 @@ class PerplexityReveniumMiddleware {
|
|
|
81
81
|
stopReason: "END",
|
|
82
82
|
tokenCounts,
|
|
83
83
|
usageMetadata,
|
|
84
|
-
});
|
|
84
|
+
}, false);
|
|
85
85
|
await metering.sendMeteringData(getMetering);
|
|
86
86
|
return result;
|
|
87
87
|
}
|
package/dist/models/Logger.js
CHANGED
|
@@ -1,35 +1,35 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.logger = exports.Logger = void 0;
|
|
4
|
-
const utils_1 = require("../utils");
|
|
5
|
-
class Logger {
|
|
6
|
-
static debug(message, data) {
|
|
7
|
-
if (this.shouldLog(utils_1.LOG_LEVELS[0])) {
|
|
8
|
-
console.log(`[${utils_1.LOG_LEVELS[0]}] ${message}`, data || "");
|
|
9
|
-
}
|
|
10
|
-
}
|
|
11
|
-
static info(message, data) {
|
|
12
|
-
if (this.shouldLog(utils_1.LOG_LEVELS[1])) {
|
|
13
|
-
console.log(`[${utils_1.LOG_LEVELS[1]}] ${message}`, data || "");
|
|
14
|
-
}
|
|
15
|
-
}
|
|
16
|
-
static warning(message, data) {
|
|
17
|
-
if (this.shouldLog(utils_1.LOG_LEVELS[2])) {
|
|
18
|
-
console.warn(`[${utils_1.LOG_LEVELS[2]}] ${message}`, data || "");
|
|
19
|
-
}
|
|
20
|
-
}
|
|
21
|
-
static error(message, data) {
|
|
22
|
-
if (this.shouldLog(utils_1.LOG_LEVELS[3])) {
|
|
23
|
-
console.error(`[${utils_1.LOG_LEVELS[3]}] ${message}`, data || "");
|
|
24
|
-
}
|
|
25
|
-
}
|
|
26
|
-
static shouldLog(level) {
|
|
27
|
-
const levels = utils_1.LOG_LEVELS;
|
|
28
|
-
const currentLevel = levels.indexOf(this.logLevel.toUpperCase());
|
|
29
|
-
const messageLevel = levels.indexOf(level);
|
|
30
|
-
return messageLevel >= currentLevel;
|
|
31
|
-
}
|
|
32
|
-
}
|
|
33
|
-
exports.Logger = Logger;
|
|
34
|
-
Logger.logLevel = process.env.REVENIUM_LOG_LEVEL || "INFO";
|
|
35
|
-
exports.logger = Logger;
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.logger = exports.Logger = void 0;
|
|
4
|
+
const utils_1 = require("../utils");
|
|
5
|
+
class Logger {
|
|
6
|
+
static debug(message, data) {
|
|
7
|
+
if (this.shouldLog(utils_1.LOG_LEVELS[0])) {
|
|
8
|
+
console.log(`[${utils_1.LOG_LEVELS[0]}] ${message}`, data || "");
|
|
9
|
+
}
|
|
10
|
+
}
|
|
11
|
+
static info(message, data) {
|
|
12
|
+
if (this.shouldLog(utils_1.LOG_LEVELS[1])) {
|
|
13
|
+
console.log(`[${utils_1.LOG_LEVELS[1]}] ${message}`, data || "");
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
static warning(message, data) {
|
|
17
|
+
if (this.shouldLog(utils_1.LOG_LEVELS[2])) {
|
|
18
|
+
console.warn(`[${utils_1.LOG_LEVELS[2]}] ${message}`, data || "");
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
static error(message, data) {
|
|
22
|
+
if (this.shouldLog(utils_1.LOG_LEVELS[3])) {
|
|
23
|
+
console.error(`[${utils_1.LOG_LEVELS[3]}] ${message}`, data || "");
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
static shouldLog(level) {
|
|
27
|
+
const levels = utils_1.LOG_LEVELS;
|
|
28
|
+
const currentLevel = levels.indexOf(this.logLevel.toUpperCase());
|
|
29
|
+
const messageLevel = levels.indexOf(level);
|
|
30
|
+
return messageLevel >= currentLevel;
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
exports.Logger = Logger;
|
|
34
|
+
Logger.logLevel = process.env.REVENIUM_LOG_LEVEL || "INFO";
|
|
35
|
+
exports.logger = Logger;
|
|
@@ -4,6 +4,6 @@ export declare class Metering {
|
|
|
4
4
|
private endpoint;
|
|
5
5
|
private apiKey;
|
|
6
6
|
constructor(clientApiKey: string, clientEndpoint: string);
|
|
7
|
-
createMetering(metering: IMeteringRequest): IMeteringResponse;
|
|
7
|
+
createMetering(metering: IMeteringRequest, isStreamed: boolean): IMeteringResponse;
|
|
8
8
|
sendMeteringData: (metering: IMeteringResponse) => Promise<void>;
|
|
9
9
|
}
|
package/dist/models/Metering.js
CHANGED
|
@@ -35,36 +35,44 @@ class Metering {
|
|
|
35
35
|
this.apiKey = clientApiKey;
|
|
36
36
|
this.endpoint = clientEndpoint;
|
|
37
37
|
}
|
|
38
|
-
createMetering(metering) {
|
|
38
|
+
createMetering(metering, isStreamed) {
|
|
39
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t, _u, _v, _w;
|
|
40
|
+
const usageMetadata = metering.usageMetadata;
|
|
39
41
|
const agent = "perplexity";
|
|
40
42
|
return {
|
|
41
|
-
stopReason: metering.stopReason,
|
|
43
|
+
stopReason: (_a = usageMetadata === null || usageMetadata === void 0 ? void 0 : usageMetadata.stopReason) !== null && _a !== void 0 ? _a : metering.stopReason,
|
|
42
44
|
costType: utils_1.COST_TYPE,
|
|
43
|
-
isStreamed
|
|
45
|
+
isStreamed,
|
|
44
46
|
taskType: utils_1.COST_TYPE,
|
|
45
|
-
agent,
|
|
46
|
-
operationType: metering.operationType.toString(),
|
|
47
|
-
inputTokenCount: metering.tokenCounts.inputTokens,
|
|
48
|
-
outputTokenCount: metering.tokenCounts.outputTokens,
|
|
49
|
-
reasoningTokenCount: metering.tokenCounts.reasoningTokens
|
|
50
|
-
cacheCreationTokenCount: metering.tokenCounts.cachedTokens
|
|
51
|
-
cacheReadTokenCount: 0,
|
|
52
|
-
totalTokenCount: metering.tokenCounts.totalTokens,
|
|
53
|
-
organizationId: `my-customer-name-${(0, generateTransactionId_1.generateTransactionId)()}`,
|
|
54
|
-
productId: utils_1.PRODUCT_ID_FREE,
|
|
47
|
+
agent: (_b = usageMetadata === null || usageMetadata === void 0 ? void 0 : usageMetadata.agent) !== null && _b !== void 0 ? _b : agent,
|
|
48
|
+
operationType: (_c = usageMetadata === null || usageMetadata === void 0 ? void 0 : usageMetadata.operationType) !== null && _c !== void 0 ? _c : metering.operationType.toString(),
|
|
49
|
+
inputTokenCount: (_d = usageMetadata === null || usageMetadata === void 0 ? void 0 : usageMetadata.inputTokenCount) !== null && _d !== void 0 ? _d : metering.tokenCounts.inputTokens,
|
|
50
|
+
outputTokenCount: (_e = usageMetadata === null || usageMetadata === void 0 ? void 0 : usageMetadata.outputTokenCount) !== null && _e !== void 0 ? _e : metering.tokenCounts.outputTokens,
|
|
51
|
+
reasoningTokenCount: (_g = (_f = usageMetadata === null || usageMetadata === void 0 ? void 0 : usageMetadata.reasoningTokenCount) !== null && _f !== void 0 ? _f : metering.tokenCounts.reasoningTokens) !== null && _g !== void 0 ? _g : 0,
|
|
52
|
+
cacheCreationTokenCount: (_j = (_h = usageMetadata === null || usageMetadata === void 0 ? void 0 : usageMetadata.cacheCreationTokenCount) !== null && _h !== void 0 ? _h : metering.tokenCounts.cachedTokens) !== null && _j !== void 0 ? _j : 0,
|
|
53
|
+
cacheReadTokenCount: (_k = usageMetadata === null || usageMetadata === void 0 ? void 0 : usageMetadata.cacheReadTokenCount) !== null && _k !== void 0 ? _k : 0,
|
|
54
|
+
totalTokenCount: (_l = usageMetadata === null || usageMetadata === void 0 ? void 0 : usageMetadata.totalTokenCount) !== null && _l !== void 0 ? _l : metering.tokenCounts.totalTokens,
|
|
55
|
+
organizationId: (_m = usageMetadata === null || usageMetadata === void 0 ? void 0 : usageMetadata.organizationId) !== null && _m !== void 0 ? _m : `my-customer-name-${(0, generateTransactionId_1.generateTransactionId)()}`,
|
|
56
|
+
productId: (_o = usageMetadata === null || usageMetadata === void 0 ? void 0 : usageMetadata.productId) !== null && _o !== void 0 ? _o : utils_1.PRODUCT_ID_FREE,
|
|
55
57
|
subscriber: {
|
|
56
|
-
id: `user-${(0, generateTransactionId_1.generateTransactionId)()}`,
|
|
57
|
-
email: `user-@${agent.toLowerCase()}.ai`,
|
|
58
|
-
credential:
|
|
58
|
+
id: (_p = usageMetadata === null || usageMetadata === void 0 ? void 0 : usageMetadata.subscriberId) !== null && _p !== void 0 ? _p : `user-${(0, generateTransactionId_1.generateTransactionId)()}`,
|
|
59
|
+
email: (_q = usageMetadata === null || usageMetadata === void 0 ? void 0 : usageMetadata.subscriberEmail) !== null && _q !== void 0 ? _q : `user-@${agent.toLowerCase()}.ai`,
|
|
60
|
+
credential: (usageMetadata === null || usageMetadata === void 0 ? void 0 : usageMetadata.subscriberCredentialName) &&
|
|
61
|
+
(usageMetadata === null || usageMetadata === void 0 ? void 0 : usageMetadata.subscriberCredential)
|
|
62
|
+
? {
|
|
63
|
+
name: usageMetadata.subscriberCredentialName,
|
|
64
|
+
value: usageMetadata.subscriberCredential,
|
|
65
|
+
}
|
|
66
|
+
: utils_1.CURRENT_CREDENTIAL,
|
|
59
67
|
},
|
|
60
68
|
model: metering.modelName,
|
|
61
|
-
transactionId: (0, generateTransactionId_1.generateTransactionId)(),
|
|
69
|
+
transactionId: (_r = usageMetadata === null || usageMetadata === void 0 ? void 0 : usageMetadata.transactionId) !== null && _r !== void 0 ? _r : (0, generateTransactionId_1.generateTransactionId)(),
|
|
62
70
|
responseTime: (0, formatTimeStamp_1.formatTimestamp)(metering.endTime),
|
|
63
71
|
requestDuration: (0, calculateDurationMs_1.calculateDurationMs)(metering.startTime, metering.endTime),
|
|
64
72
|
provider: agent,
|
|
65
|
-
requestTime: (0, formatTimeStamp_1.formatTimestamp)(metering.startTime),
|
|
66
|
-
completionStartTime: (0, formatTimeStamp_1.formatTimestamp)(metering.endTime),
|
|
67
|
-
timeToFirstToken: 0,
|
|
73
|
+
requestTime: (_t = (_s = usageMetadata === null || usageMetadata === void 0 ? void 0 : usageMetadata.requestTime) === null || _s === void 0 ? void 0 : _s.toString()) !== null && _t !== void 0 ? _t : (0, formatTimeStamp_1.formatTimestamp)(metering.startTime),
|
|
74
|
+
completionStartTime: (_v = (_u = usageMetadata === null || usageMetadata === void 0 ? void 0 : usageMetadata.completionStartTime) === null || _u === void 0 ? void 0 : _u.toString()) !== null && _v !== void 0 ? _v : (0, formatTimeStamp_1.formatTimestamp)(metering.endTime),
|
|
75
|
+
timeToFirstToken: (_w = usageMetadata === null || usageMetadata === void 0 ? void 0 : usageMetadata.timeToFirstToken) !== null && _w !== void 0 ? _w : 0,
|
|
68
76
|
middleware_source: utils_1.MIDDLEWARE_SOURCE,
|
|
69
77
|
};
|
|
70
78
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare function calculateDurationMs(startTime: Date, endTime: Date): number;
|
|
1
|
+
export declare function calculateDurationMs(startTime: Date, endTime: Date): number;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.calculateDurationMs = calculateDurationMs;
|
|
4
|
-
function calculateDurationMs(startTime, endTime) {
|
|
5
|
-
return Math.round(endTime.getTime() - startTime.getTime());
|
|
6
|
-
}
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.calculateDurationMs = calculateDurationMs;
|
|
4
|
+
function calculateDurationMs(startTime, endTime) {
|
|
5
|
+
return Math.round(endTime.getTime() - startTime.getTime());
|
|
6
|
+
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { ICredential } from "../../interfaces/credential";
|
|
2
|
-
export declare const PERPLEXITY_API_BASE_URL: string;
|
|
3
|
-
export declare const COST_TYPE: string;
|
|
4
|
-
export declare const MIDDLEWARE_SOURCE: string;
|
|
5
|
-
export declare const PRODUCT_ID_FREE: string;
|
|
6
|
-
export declare const CURRENT_CREDENTIAL: ICredential;
|
|
1
|
+
import { ICredential } from "../../interfaces/credential";
|
|
2
|
+
export declare const PERPLEXITY_API_BASE_URL: string;
|
|
3
|
+
export declare const COST_TYPE: string;
|
|
4
|
+
export declare const MIDDLEWARE_SOURCE: string;
|
|
5
|
+
export declare const PRODUCT_ID_FREE: string;
|
|
6
|
+
export declare const CURRENT_CREDENTIAL: ICredential;
|
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.CURRENT_CREDENTIAL = exports.PRODUCT_ID_FREE = exports.MIDDLEWARE_SOURCE = exports.COST_TYPE = exports.PERPLEXITY_API_BASE_URL = void 0;
|
|
4
|
-
exports.PERPLEXITY_API_BASE_URL = "https://api.perplexity.ai";
|
|
5
|
-
exports.COST_TYPE = "AI";
|
|
6
|
-
exports.MIDDLEWARE_SOURCE = "node";
|
|
7
|
-
exports.PRODUCT_ID_FREE = "free-trial";
|
|
8
|
-
exports.CURRENT_CREDENTIAL = {
|
|
9
|
-
name: "apiKey",
|
|
10
|
-
value: "keyValue",
|
|
11
|
-
};
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.CURRENT_CREDENTIAL = exports.PRODUCT_ID_FREE = exports.MIDDLEWARE_SOURCE = exports.COST_TYPE = exports.PERPLEXITY_API_BASE_URL = void 0;
|
|
4
|
+
exports.PERPLEXITY_API_BASE_URL = "https://api.perplexity.ai";
|
|
5
|
+
exports.COST_TYPE = "AI";
|
|
6
|
+
exports.MIDDLEWARE_SOURCE = "node";
|
|
7
|
+
exports.PRODUCT_ID_FREE = "free-trial";
|
|
8
|
+
exports.CURRENT_CREDENTIAL = {
|
|
9
|
+
name: "apiKey",
|
|
10
|
+
value: "keyValue",
|
|
11
|
+
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare const LOG_LEVELS: string[];
|
|
1
|
+
export declare const LOG_LEVELS: string[];
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.LOG_LEVELS = void 0;
|
|
4
|
-
exports.LOG_LEVELS = ["DEBUG", "INFO", "WARNING", "ERROR"];
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.LOG_LEVELS = void 0;
|
|
4
|
+
exports.LOG_LEVELS = ["DEBUG", "INFO", "WARNING", "ERROR"];
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
export declare const PERPLEXITY_REQUIRED_API_KEY_MESSAGE: string;
|
|
2
|
-
export declare const PERPLEXITY_API_KEY_INVALID_MESSAGE: string;
|
|
3
|
-
export declare const PERPLEXITY_METERING_API_KEY_IS_NOT_SET_MESSAGE: string;
|
|
4
|
-
export declare const PERPLEXITY_METERING_BASE_URL_IS_NOT_SET_MESSAGE: string;
|
|
5
|
-
export declare const PERPLEXITY_CLIENT_INITIALIZED_MESSAGE = "Perplexity AI client initialized with middleware";
|
|
1
|
+
export declare const PERPLEXITY_REQUIRED_API_KEY_MESSAGE: string;
|
|
2
|
+
export declare const PERPLEXITY_API_KEY_INVALID_MESSAGE: string;
|
|
3
|
+
export declare const PERPLEXITY_METERING_API_KEY_IS_NOT_SET_MESSAGE: string;
|
|
4
|
+
export declare const PERPLEXITY_METERING_BASE_URL_IS_NOT_SET_MESSAGE: string;
|
|
5
|
+
export declare const PERPLEXITY_CLIENT_INITIALIZED_MESSAGE = "Perplexity AI client initialized with middleware";
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.PERPLEXITY_CLIENT_INITIALIZED_MESSAGE = exports.PERPLEXITY_METERING_BASE_URL_IS_NOT_SET_MESSAGE = exports.PERPLEXITY_METERING_API_KEY_IS_NOT_SET_MESSAGE = exports.PERPLEXITY_API_KEY_INVALID_MESSAGE = exports.PERPLEXITY_REQUIRED_API_KEY_MESSAGE = void 0;
|
|
4
|
-
exports.PERPLEXITY_REQUIRED_API_KEY_MESSAGE = "PERPLEXITY_API_KEY is required. Set it in environment variables or pass it to the constructor.";
|
|
5
|
-
exports.PERPLEXITY_API_KEY_INVALID_MESSAGE = "PERPLEXITY_API_KEY is invalid. Please check your API key.";
|
|
6
|
-
exports.PERPLEXITY_METERING_API_KEY_IS_NOT_SET_MESSAGE = "REVENIUM_METERING_API_KEY is not set. Metering will not work.";
|
|
7
|
-
exports.PERPLEXITY_METERING_BASE_URL_IS_NOT_SET_MESSAGE = "REVENIUM_METERING_BASE_URL is not set. Metering will not work.";
|
|
8
|
-
exports.PERPLEXITY_CLIENT_INITIALIZED_MESSAGE = "Perplexity AI client initialized with middleware";
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.PERPLEXITY_CLIENT_INITIALIZED_MESSAGE = exports.PERPLEXITY_METERING_BASE_URL_IS_NOT_SET_MESSAGE = exports.PERPLEXITY_METERING_API_KEY_IS_NOT_SET_MESSAGE = exports.PERPLEXITY_API_KEY_INVALID_MESSAGE = exports.PERPLEXITY_REQUIRED_API_KEY_MESSAGE = void 0;
|
|
4
|
+
exports.PERPLEXITY_REQUIRED_API_KEY_MESSAGE = "PERPLEXITY_API_KEY is required. Set it in environment variables or pass it to the constructor.";
|
|
5
|
+
exports.PERPLEXITY_API_KEY_INVALID_MESSAGE = "PERPLEXITY_API_KEY is invalid. Please check your API key.";
|
|
6
|
+
exports.PERPLEXITY_METERING_API_KEY_IS_NOT_SET_MESSAGE = "REVENIUM_METERING_API_KEY is not set. Metering will not work.";
|
|
7
|
+
exports.PERPLEXITY_METERING_BASE_URL_IS_NOT_SET_MESSAGE = "REVENIUM_METERING_BASE_URL is not set. Metering will not work.";
|
|
8
|
+
exports.PERPLEXITY_CLIENT_INITIALIZED_MESSAGE = "Perplexity AI client initialized with middleware";
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare const models: string[];
|
|
1
|
+
export declare const models: string[];
|
|
@@ -1,21 +1,21 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.models = void 0;
|
|
4
|
-
exports.models = [
|
|
5
|
-
// Perplexity Sonar Models (2025) - Chat Completions
|
|
6
|
-
"sonar", // Lightweight, cost-effective search model
|
|
7
|
-
"sonar-pro", // Advanced search with deeper content understanding
|
|
8
|
-
"sonar-reasoning", // Quick problem-solving with step-by-step logic and search
|
|
9
|
-
"sonar-reasoning-pro", // Enhanced multi-step reasoning with web search
|
|
10
|
-
"sonar-deep-research", // Exhaustive research and detailed report generation
|
|
11
|
-
// Legacy models (deprecated - will be removed)
|
|
12
|
-
"sonar-small",
|
|
13
|
-
"sonar-small-online",
|
|
14
|
-
"sonar-medium-online",
|
|
15
|
-
"sonar-small-chat",
|
|
16
|
-
"sonar-medium-chat",
|
|
17
|
-
// OpenAI Embedding Models (use with OpenAI client directly)
|
|
18
|
-
"text-embedding-3-small", // Most capable small embedding model
|
|
19
|
-
"text-embedding-3-large", // Most capable large embedding model
|
|
20
|
-
"text-embedding-ada-002", // Legacy embedding model
|
|
21
|
-
];
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.models = void 0;
|
|
4
|
+
exports.models = [
|
|
5
|
+
// Perplexity Sonar Models (2025) - Chat Completions
|
|
6
|
+
"sonar", // Lightweight, cost-effective search model
|
|
7
|
+
"sonar-pro", // Advanced search with deeper content understanding
|
|
8
|
+
"sonar-reasoning", // Quick problem-solving with step-by-step logic and search
|
|
9
|
+
"sonar-reasoning-pro", // Enhanced multi-step reasoning with web search
|
|
10
|
+
"sonar-deep-research", // Exhaustive research and detailed report generation
|
|
11
|
+
// Legacy models (deprecated - will be removed)
|
|
12
|
+
"sonar-small",
|
|
13
|
+
"sonar-small-online",
|
|
14
|
+
"sonar-medium-online",
|
|
15
|
+
"sonar-small-chat",
|
|
16
|
+
"sonar-medium-chat",
|
|
17
|
+
// OpenAI Embedding Models (use with OpenAI client directly)
|
|
18
|
+
"text-embedding-3-small", // Most capable small embedding model
|
|
19
|
+
"text-embedding-3-large", // Most capable large embedding model
|
|
20
|
+
"text-embedding-ada-002", // Legacy embedding model
|
|
21
|
+
];
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { ITokenCounts } from "../interfaces/tokenCounts";
|
|
2
|
-
export declare function extractGoogleAITokenCounts(response: any): ITokenCounts;
|
|
1
|
+
import { ITokenCounts } from "../interfaces/tokenCounts";
|
|
2
|
+
export declare function extractGoogleAITokenCounts(response: any): ITokenCounts;
|
|
@@ -1,28 +1,28 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.extractGoogleAITokenCounts = extractGoogleAITokenCounts;
|
|
4
|
-
const Logger_1 = require("../models/Logger");
|
|
5
|
-
const safeExtract_1 = require("./safeExtract");
|
|
6
|
-
function extractGoogleAITokenCounts(response) {
|
|
7
|
-
var _a;
|
|
8
|
-
console.log;
|
|
9
|
-
try {
|
|
10
|
-
const usageMetadata = response.usage || ((_a = response.response) === null || _a === void 0 ? void 0 : _a.usage);
|
|
11
|
-
if (!usageMetadata)
|
|
12
|
-
return { inputTokens: 0, outputTokens: 0, totalTokens: 0 };
|
|
13
|
-
const inputTokens = safeExtract_1.safeExtract.number(usageMetadata, "prompt_tokens");
|
|
14
|
-
const outputTokens = safeExtract_1.safeExtract.number(usageMetadata, "completion_tokens");
|
|
15
|
-
const totalTokens = safeExtract_1.safeExtract.number(usageMetadata, "total_tokens");
|
|
16
|
-
return {
|
|
17
|
-
inputTokens,
|
|
18
|
-
outputTokens,
|
|
19
|
-
totalTokens,
|
|
20
|
-
cachedTokens: 0,
|
|
21
|
-
reasoningTokens: 0,
|
|
22
|
-
};
|
|
23
|
-
}
|
|
24
|
-
catch (error) {
|
|
25
|
-
Logger_1.logger.warning("Failed to extract Google AI token counts:", error);
|
|
26
|
-
return { inputTokens: 0, outputTokens: 0, totalTokens: 0 };
|
|
27
|
-
}
|
|
28
|
-
}
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.extractGoogleAITokenCounts = extractGoogleAITokenCounts;
|
|
4
|
+
const Logger_1 = require("../models/Logger");
|
|
5
|
+
const safeExtract_1 = require("./safeExtract");
|
|
6
|
+
function extractGoogleAITokenCounts(response) {
|
|
7
|
+
var _a;
|
|
8
|
+
console.log;
|
|
9
|
+
try {
|
|
10
|
+
const usageMetadata = response.usage || ((_a = response.response) === null || _a === void 0 ? void 0 : _a.usage);
|
|
11
|
+
if (!usageMetadata)
|
|
12
|
+
return { inputTokens: 0, outputTokens: 0, totalTokens: 0 };
|
|
13
|
+
const inputTokens = safeExtract_1.safeExtract.number(usageMetadata, "prompt_tokens");
|
|
14
|
+
const outputTokens = safeExtract_1.safeExtract.number(usageMetadata, "completion_tokens");
|
|
15
|
+
const totalTokens = safeExtract_1.safeExtract.number(usageMetadata, "total_tokens");
|
|
16
|
+
return {
|
|
17
|
+
inputTokens,
|
|
18
|
+
outputTokens,
|
|
19
|
+
totalTokens,
|
|
20
|
+
cachedTokens: 0,
|
|
21
|
+
reasoningTokens: 0,
|
|
22
|
+
};
|
|
23
|
+
}
|
|
24
|
+
catch (error) {
|
|
25
|
+
Logger_1.logger.warning("Failed to extract Google AI token counts:", error);
|
|
26
|
+
return { inputTokens: 0, outputTokens: 0, totalTokens: 0 };
|
|
27
|
+
}
|
|
28
|
+
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare function formatTimestamp(date: Date): string;
|
|
1
|
+
export declare function formatTimestamp(date: Date): string;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.formatTimestamp = formatTimestamp;
|
|
4
|
-
function formatTimestamp(date) {
|
|
5
|
-
return date.toISOString();
|
|
6
|
-
}
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.formatTimestamp = formatTimestamp;
|
|
4
|
+
function formatTimestamp(date) {
|
|
5
|
+
return date.toISOString();
|
|
6
|
+
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare function generateTransactionId(): string;
|
|
1
|
+
export declare function generateTransactionId(): string;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.generateTransactionId = generateTransactionId;
|
|
4
|
-
const uuid_1 = require("uuid");
|
|
5
|
-
function generateTransactionId() {
|
|
6
|
-
return (0, uuid_1.v4)();
|
|
7
|
-
}
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.generateTransactionId = generateTransactionId;
|
|
4
|
+
const uuid_1 = require("uuid");
|
|
5
|
+
function generateTransactionId() {
|
|
6
|
+
return (0, uuid_1.v4)();
|
|
7
|
+
}
|
package/dist/utils/index.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { PERPLEXITY_API_KEY, REVENIUM_METERING_API_KEY, REVENIUM_METERING_BASE_URL } from "./loadEnv";
|
|
2
|
-
import { PERPLEXITY_REQUIRED_API_KEY_MESSAGE, PERPLEXITY_API_KEY_INVALID_MESSAGE, PERPLEXITY_METERING_API_KEY_IS_NOT_SET_MESSAGE, PERPLEXITY_METERING_BASE_URL_IS_NOT_SET_MESSAGE, PERPLEXITY_CLIENT_INITIALIZED_MESSAGE } from "./constants/messages";
|
|
3
|
-
import { LOG_LEVELS } from "./constants/logLevels";
|
|
4
|
-
import { models } from "./constants/models";
|
|
5
|
-
import { PERPLEXITY_API_BASE_URL, COST_TYPE, MIDDLEWARE_SOURCE, PRODUCT_ID_FREE, CURRENT_CREDENTIAL } from "./constants/constants";
|
|
6
|
-
export { PERPLEXITY_API_KEY, REVENIUM_METERING_API_KEY, REVENIUM_METERING_BASE_URL, PERPLEXITY_REQUIRED_API_KEY_MESSAGE, PERPLEXITY_API_KEY_INVALID_MESSAGE, LOG_LEVELS, PERPLEXITY_METERING_API_KEY_IS_NOT_SET_MESSAGE, PERPLEXITY_METERING_BASE_URL_IS_NOT_SET_MESSAGE, PERPLEXITY_CLIENT_INITIALIZED_MESSAGE, models, PERPLEXITY_API_BASE_URL, COST_TYPE, MIDDLEWARE_SOURCE, PRODUCT_ID_FREE, CURRENT_CREDENTIAL, };
|
|
1
|
+
import { PERPLEXITY_API_KEY, REVENIUM_METERING_API_KEY, REVENIUM_METERING_BASE_URL } from "./loadEnv";
|
|
2
|
+
import { PERPLEXITY_REQUIRED_API_KEY_MESSAGE, PERPLEXITY_API_KEY_INVALID_MESSAGE, PERPLEXITY_METERING_API_KEY_IS_NOT_SET_MESSAGE, PERPLEXITY_METERING_BASE_URL_IS_NOT_SET_MESSAGE, PERPLEXITY_CLIENT_INITIALIZED_MESSAGE } from "./constants/messages";
|
|
3
|
+
import { LOG_LEVELS } from "./constants/logLevels";
|
|
4
|
+
import { models } from "./constants/models";
|
|
5
|
+
import { PERPLEXITY_API_BASE_URL, COST_TYPE, MIDDLEWARE_SOURCE, PRODUCT_ID_FREE, CURRENT_CREDENTIAL } from "./constants/constants";
|
|
6
|
+
export { PERPLEXITY_API_KEY, REVENIUM_METERING_API_KEY, REVENIUM_METERING_BASE_URL, PERPLEXITY_REQUIRED_API_KEY_MESSAGE, PERPLEXITY_API_KEY_INVALID_MESSAGE, LOG_LEVELS, PERPLEXITY_METERING_API_KEY_IS_NOT_SET_MESSAGE, PERPLEXITY_METERING_BASE_URL_IS_NOT_SET_MESSAGE, PERPLEXITY_CLIENT_INITIALIZED_MESSAGE, models, PERPLEXITY_API_BASE_URL, COST_TYPE, MIDDLEWARE_SOURCE, PRODUCT_ID_FREE, CURRENT_CREDENTIAL, };
|
package/dist/utils/index.js
CHANGED
|
@@ -1,23 +1,23 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.CURRENT_CREDENTIAL = exports.PRODUCT_ID_FREE = exports.MIDDLEWARE_SOURCE = exports.COST_TYPE = exports.PERPLEXITY_API_BASE_URL = exports.models = exports.PERPLEXITY_CLIENT_INITIALIZED_MESSAGE = exports.PERPLEXITY_METERING_BASE_URL_IS_NOT_SET_MESSAGE = exports.PERPLEXITY_METERING_API_KEY_IS_NOT_SET_MESSAGE = exports.LOG_LEVELS = exports.PERPLEXITY_API_KEY_INVALID_MESSAGE = exports.PERPLEXITY_REQUIRED_API_KEY_MESSAGE = exports.REVENIUM_METERING_BASE_URL = exports.REVENIUM_METERING_API_KEY = exports.PERPLEXITY_API_KEY = void 0;
|
|
4
|
-
const loadEnv_1 = require("./loadEnv");
|
|
5
|
-
Object.defineProperty(exports, "PERPLEXITY_API_KEY", { enumerable: true, get: function () { return loadEnv_1.PERPLEXITY_API_KEY; } });
|
|
6
|
-
Object.defineProperty(exports, "REVENIUM_METERING_API_KEY", { enumerable: true, get: function () { return loadEnv_1.REVENIUM_METERING_API_KEY; } });
|
|
7
|
-
Object.defineProperty(exports, "REVENIUM_METERING_BASE_URL", { enumerable: true, get: function () { return loadEnv_1.REVENIUM_METERING_BASE_URL; } });
|
|
8
|
-
const messages_1 = require("./constants/messages");
|
|
9
|
-
Object.defineProperty(exports, "PERPLEXITY_REQUIRED_API_KEY_MESSAGE", { enumerable: true, get: function () { return messages_1.PERPLEXITY_REQUIRED_API_KEY_MESSAGE; } });
|
|
10
|
-
Object.defineProperty(exports, "PERPLEXITY_API_KEY_INVALID_MESSAGE", { enumerable: true, get: function () { return messages_1.PERPLEXITY_API_KEY_INVALID_MESSAGE; } });
|
|
11
|
-
Object.defineProperty(exports, "PERPLEXITY_METERING_API_KEY_IS_NOT_SET_MESSAGE", { enumerable: true, get: function () { return messages_1.PERPLEXITY_METERING_API_KEY_IS_NOT_SET_MESSAGE; } });
|
|
12
|
-
Object.defineProperty(exports, "PERPLEXITY_METERING_BASE_URL_IS_NOT_SET_MESSAGE", { enumerable: true, get: function () { return messages_1.PERPLEXITY_METERING_BASE_URL_IS_NOT_SET_MESSAGE; } });
|
|
13
|
-
Object.defineProperty(exports, "PERPLEXITY_CLIENT_INITIALIZED_MESSAGE", { enumerable: true, get: function () { return messages_1.PERPLEXITY_CLIENT_INITIALIZED_MESSAGE; } });
|
|
14
|
-
const logLevels_1 = require("./constants/logLevels");
|
|
15
|
-
Object.defineProperty(exports, "LOG_LEVELS", { enumerable: true, get: function () { return logLevels_1.LOG_LEVELS; } });
|
|
16
|
-
const models_1 = require("./constants/models");
|
|
17
|
-
Object.defineProperty(exports, "models", { enumerable: true, get: function () { return models_1.models; } });
|
|
18
|
-
const constants_1 = require("./constants/constants");
|
|
19
|
-
Object.defineProperty(exports, "PERPLEXITY_API_BASE_URL", { enumerable: true, get: function () { return constants_1.PERPLEXITY_API_BASE_URL; } });
|
|
20
|
-
Object.defineProperty(exports, "COST_TYPE", { enumerable: true, get: function () { return constants_1.COST_TYPE; } });
|
|
21
|
-
Object.defineProperty(exports, "MIDDLEWARE_SOURCE", { enumerable: true, get: function () { return constants_1.MIDDLEWARE_SOURCE; } });
|
|
22
|
-
Object.defineProperty(exports, "PRODUCT_ID_FREE", { enumerable: true, get: function () { return constants_1.PRODUCT_ID_FREE; } });
|
|
23
|
-
Object.defineProperty(exports, "CURRENT_CREDENTIAL", { enumerable: true, get: function () { return constants_1.CURRENT_CREDENTIAL; } });
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.CURRENT_CREDENTIAL = exports.PRODUCT_ID_FREE = exports.MIDDLEWARE_SOURCE = exports.COST_TYPE = exports.PERPLEXITY_API_BASE_URL = exports.models = exports.PERPLEXITY_CLIENT_INITIALIZED_MESSAGE = exports.PERPLEXITY_METERING_BASE_URL_IS_NOT_SET_MESSAGE = exports.PERPLEXITY_METERING_API_KEY_IS_NOT_SET_MESSAGE = exports.LOG_LEVELS = exports.PERPLEXITY_API_KEY_INVALID_MESSAGE = exports.PERPLEXITY_REQUIRED_API_KEY_MESSAGE = exports.REVENIUM_METERING_BASE_URL = exports.REVENIUM_METERING_API_KEY = exports.PERPLEXITY_API_KEY = void 0;
|
|
4
|
+
const loadEnv_1 = require("./loadEnv");
|
|
5
|
+
Object.defineProperty(exports, "PERPLEXITY_API_KEY", { enumerable: true, get: function () { return loadEnv_1.PERPLEXITY_API_KEY; } });
|
|
6
|
+
Object.defineProperty(exports, "REVENIUM_METERING_API_KEY", { enumerable: true, get: function () { return loadEnv_1.REVENIUM_METERING_API_KEY; } });
|
|
7
|
+
Object.defineProperty(exports, "REVENIUM_METERING_BASE_URL", { enumerable: true, get: function () { return loadEnv_1.REVENIUM_METERING_BASE_URL; } });
|
|
8
|
+
const messages_1 = require("./constants/messages");
|
|
9
|
+
Object.defineProperty(exports, "PERPLEXITY_REQUIRED_API_KEY_MESSAGE", { enumerable: true, get: function () { return messages_1.PERPLEXITY_REQUIRED_API_KEY_MESSAGE; } });
|
|
10
|
+
Object.defineProperty(exports, "PERPLEXITY_API_KEY_INVALID_MESSAGE", { enumerable: true, get: function () { return messages_1.PERPLEXITY_API_KEY_INVALID_MESSAGE; } });
|
|
11
|
+
Object.defineProperty(exports, "PERPLEXITY_METERING_API_KEY_IS_NOT_SET_MESSAGE", { enumerable: true, get: function () { return messages_1.PERPLEXITY_METERING_API_KEY_IS_NOT_SET_MESSAGE; } });
|
|
12
|
+
Object.defineProperty(exports, "PERPLEXITY_METERING_BASE_URL_IS_NOT_SET_MESSAGE", { enumerable: true, get: function () { return messages_1.PERPLEXITY_METERING_BASE_URL_IS_NOT_SET_MESSAGE; } });
|
|
13
|
+
Object.defineProperty(exports, "PERPLEXITY_CLIENT_INITIALIZED_MESSAGE", { enumerable: true, get: function () { return messages_1.PERPLEXITY_CLIENT_INITIALIZED_MESSAGE; } });
|
|
14
|
+
const logLevels_1 = require("./constants/logLevels");
|
|
15
|
+
Object.defineProperty(exports, "LOG_LEVELS", { enumerable: true, get: function () { return logLevels_1.LOG_LEVELS; } });
|
|
16
|
+
const models_1 = require("./constants/models");
|
|
17
|
+
Object.defineProperty(exports, "models", { enumerable: true, get: function () { return models_1.models; } });
|
|
18
|
+
const constants_1 = require("./constants/constants");
|
|
19
|
+
Object.defineProperty(exports, "PERPLEXITY_API_BASE_URL", { enumerable: true, get: function () { return constants_1.PERPLEXITY_API_BASE_URL; } });
|
|
20
|
+
Object.defineProperty(exports, "COST_TYPE", { enumerable: true, get: function () { return constants_1.COST_TYPE; } });
|
|
21
|
+
Object.defineProperty(exports, "MIDDLEWARE_SOURCE", { enumerable: true, get: function () { return constants_1.MIDDLEWARE_SOURCE; } });
|
|
22
|
+
Object.defineProperty(exports, "PRODUCT_ID_FREE", { enumerable: true, get: function () { return constants_1.PRODUCT_ID_FREE; } });
|
|
23
|
+
Object.defineProperty(exports, "CURRENT_CREDENTIAL", { enumerable: true, get: function () { return constants_1.CURRENT_CREDENTIAL; } });
|
package/dist/utils/loadEnv.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare const PERPLEXITY_API_KEY: string | undefined, REVENIUM_METERING_API_KEY: string | undefined, REVENIUM_METERING_BASE_URL: string | undefined;
|
|
1
|
+
export declare const PERPLEXITY_API_KEY: string | undefined, REVENIUM_METERING_API_KEY: string | undefined, REVENIUM_METERING_BASE_URL: string | undefined;
|
package/dist/utils/loadEnv.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var _a;
|
|
3
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
-
exports.REVENIUM_METERING_BASE_URL = exports.REVENIUM_METERING_API_KEY = exports.PERPLEXITY_API_KEY = void 0;
|
|
5
|
-
const dotenv_1 = require("dotenv");
|
|
6
|
-
(0, dotenv_1.config)();
|
|
7
|
-
_a = process.env, exports.PERPLEXITY_API_KEY = _a.PERPLEXITY_API_KEY, exports.REVENIUM_METERING_API_KEY = _a.REVENIUM_METERING_API_KEY, exports.REVENIUM_METERING_BASE_URL = _a.REVENIUM_METERING_BASE_URL;
|
|
1
|
+
"use strict";
|
|
2
|
+
var _a;
|
|
3
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
+
exports.REVENIUM_METERING_BASE_URL = exports.REVENIUM_METERING_API_KEY = exports.PERPLEXITY_API_KEY = void 0;
|
|
5
|
+
const dotenv_1 = require("dotenv");
|
|
6
|
+
(0, dotenv_1.config)();
|
|
7
|
+
_a = process.env, exports.PERPLEXITY_API_KEY = _a.PERPLEXITY_API_KEY, exports.REVENIUM_METERING_API_KEY = _a.REVENIUM_METERING_API_KEY, exports.REVENIUM_METERING_BASE_URL = _a.REVENIUM_METERING_BASE_URL;
|
|
@@ -1,29 +1,29 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Safe extraction utility functions.
|
|
3
|
-
*/
|
|
4
|
-
export declare namespace safeExtract {
|
|
5
|
-
/**
|
|
6
|
-
* Safely extract a value from an object, returning undefined if the path doesn't exist.
|
|
7
|
-
*/
|
|
8
|
-
function get<T>(obj: any, path: string, defaultValue?: T): T | undefined;
|
|
9
|
-
/**
|
|
10
|
-
* Safely extract a string value, returning empty string if not found.
|
|
11
|
-
*/
|
|
12
|
-
function string(obj: any, path: string): string;
|
|
13
|
-
/**
|
|
14
|
-
* Safely extract a number value, returning 0 if not found.
|
|
15
|
-
*/
|
|
16
|
-
function number(obj: any, path: string): number;
|
|
17
|
-
/**
|
|
18
|
-
* Safely extract a boolean value, returning false if not found.
|
|
19
|
-
*/
|
|
20
|
-
function boolean(obj: any, path: string): boolean;
|
|
21
|
-
/**
|
|
22
|
-
* Safely extract an object value, returning empty object if not found.
|
|
23
|
-
*/
|
|
24
|
-
function object(obj: any, path: string): Record<string, any>;
|
|
25
|
-
/**
|
|
26
|
-
* Safely extract an array value, returning empty array if not found.
|
|
27
|
-
*/
|
|
28
|
-
function array(obj: any, path: string): any[];
|
|
29
|
-
}
|
|
1
|
+
/**
|
|
2
|
+
* Safe extraction utility functions.
|
|
3
|
+
*/
|
|
4
|
+
export declare namespace safeExtract {
|
|
5
|
+
/**
|
|
6
|
+
* Safely extract a value from an object, returning undefined if the path doesn't exist.
|
|
7
|
+
*/
|
|
8
|
+
function get<T>(obj: any, path: string, defaultValue?: T): T | undefined;
|
|
9
|
+
/**
|
|
10
|
+
* Safely extract a string value, returning empty string if not found.
|
|
11
|
+
*/
|
|
12
|
+
function string(obj: any, path: string): string;
|
|
13
|
+
/**
|
|
14
|
+
* Safely extract a number value, returning 0 if not found.
|
|
15
|
+
*/
|
|
16
|
+
function number(obj: any, path: string): number;
|
|
17
|
+
/**
|
|
18
|
+
* Safely extract a boolean value, returning false if not found.
|
|
19
|
+
*/
|
|
20
|
+
function boolean(obj: any, path: string): boolean;
|
|
21
|
+
/**
|
|
22
|
+
* Safely extract an object value, returning empty object if not found.
|
|
23
|
+
*/
|
|
24
|
+
function object(obj: any, path: string): Record<string, any>;
|
|
25
|
+
/**
|
|
26
|
+
* Safely extract an array value, returning empty array if not found.
|
|
27
|
+
*/
|
|
28
|
+
function array(obj: any, path: string): any[];
|
|
29
|
+
}
|
|
@@ -1,67 +1,67 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.safeExtract = void 0;
|
|
4
|
-
/**
|
|
5
|
-
* Safe extraction utility functions.
|
|
6
|
-
*/
|
|
7
|
-
var safeExtract;
|
|
8
|
-
(function (safeExtract) {
|
|
9
|
-
/**
|
|
10
|
-
* Safely extract a value from an object, returning undefined if the path doesn't exist.
|
|
11
|
-
*/
|
|
12
|
-
function get(obj, path, defaultValue) {
|
|
13
|
-
try {
|
|
14
|
-
const keys = path.split(".");
|
|
15
|
-
let result = obj;
|
|
16
|
-
for (const key of keys) {
|
|
17
|
-
if (result == null || typeof result !== "object") {
|
|
18
|
-
return defaultValue;
|
|
19
|
-
}
|
|
20
|
-
result = result[key];
|
|
21
|
-
}
|
|
22
|
-
return result !== null && result !== void 0 ? result : defaultValue;
|
|
23
|
-
}
|
|
24
|
-
catch {
|
|
25
|
-
return defaultValue;
|
|
26
|
-
}
|
|
27
|
-
}
|
|
28
|
-
safeExtract.get = get;
|
|
29
|
-
/**
|
|
30
|
-
* Safely extract a string value, returning empty string if not found.
|
|
31
|
-
*/
|
|
32
|
-
function string(obj, path) {
|
|
33
|
-
return get(obj, path, "") || "";
|
|
34
|
-
}
|
|
35
|
-
safeExtract.string = string;
|
|
36
|
-
/**
|
|
37
|
-
* Safely extract a number value, returning 0 if not found.
|
|
38
|
-
*/
|
|
39
|
-
function number(obj, path) {
|
|
40
|
-
const value = get(obj, path, 0);
|
|
41
|
-
return typeof value === "number" ? value : 0;
|
|
42
|
-
}
|
|
43
|
-
safeExtract.number = number;
|
|
44
|
-
/**
|
|
45
|
-
* Safely extract a boolean value, returning false if not found.
|
|
46
|
-
*/
|
|
47
|
-
function boolean(obj, path) {
|
|
48
|
-
return get(obj, path, false) || false;
|
|
49
|
-
}
|
|
50
|
-
safeExtract.boolean = boolean;
|
|
51
|
-
/**
|
|
52
|
-
* Safely extract an object value, returning empty object if not found.
|
|
53
|
-
*/
|
|
54
|
-
function object(obj, path) {
|
|
55
|
-
const value = get(obj, path, {});
|
|
56
|
-
return typeof value === "object" && value !== null ? value : {};
|
|
57
|
-
}
|
|
58
|
-
safeExtract.object = object;
|
|
59
|
-
/**
|
|
60
|
-
* Safely extract an array value, returning empty array if not found.
|
|
61
|
-
*/
|
|
62
|
-
function array(obj, path) {
|
|
63
|
-
const value = get(obj, path, []);
|
|
64
|
-
return Array.isArray(value) ? value : [];
|
|
65
|
-
}
|
|
66
|
-
safeExtract.array = array;
|
|
67
|
-
})(safeExtract || (exports.safeExtract = safeExtract = {}));
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.safeExtract = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* Safe extraction utility functions.
|
|
6
|
+
*/
|
|
7
|
+
var safeExtract;
|
|
8
|
+
(function (safeExtract) {
|
|
9
|
+
/**
|
|
10
|
+
* Safely extract a value from an object, returning undefined if the path doesn't exist.
|
|
11
|
+
*/
|
|
12
|
+
function get(obj, path, defaultValue) {
|
|
13
|
+
try {
|
|
14
|
+
const keys = path.split(".");
|
|
15
|
+
let result = obj;
|
|
16
|
+
for (const key of keys) {
|
|
17
|
+
if (result == null || typeof result !== "object") {
|
|
18
|
+
return defaultValue;
|
|
19
|
+
}
|
|
20
|
+
result = result[key];
|
|
21
|
+
}
|
|
22
|
+
return result !== null && result !== void 0 ? result : defaultValue;
|
|
23
|
+
}
|
|
24
|
+
catch {
|
|
25
|
+
return defaultValue;
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
safeExtract.get = get;
|
|
29
|
+
/**
|
|
30
|
+
* Safely extract a string value, returning empty string if not found.
|
|
31
|
+
*/
|
|
32
|
+
function string(obj, path) {
|
|
33
|
+
return get(obj, path, "") || "";
|
|
34
|
+
}
|
|
35
|
+
safeExtract.string = string;
|
|
36
|
+
/**
|
|
37
|
+
* Safely extract a number value, returning 0 if not found.
|
|
38
|
+
*/
|
|
39
|
+
function number(obj, path) {
|
|
40
|
+
const value = get(obj, path, 0);
|
|
41
|
+
return typeof value === "number" ? value : 0;
|
|
42
|
+
}
|
|
43
|
+
safeExtract.number = number;
|
|
44
|
+
/**
|
|
45
|
+
* Safely extract a boolean value, returning false if not found.
|
|
46
|
+
*/
|
|
47
|
+
function boolean(obj, path) {
|
|
48
|
+
return get(obj, path, false) || false;
|
|
49
|
+
}
|
|
50
|
+
safeExtract.boolean = boolean;
|
|
51
|
+
/**
|
|
52
|
+
* Safely extract an object value, returning empty object if not found.
|
|
53
|
+
*/
|
|
54
|
+
function object(obj, path) {
|
|
55
|
+
const value = get(obj, path, {});
|
|
56
|
+
return typeof value === "object" && value !== null ? value : {};
|
|
57
|
+
}
|
|
58
|
+
safeExtract.object = object;
|
|
59
|
+
/**
|
|
60
|
+
* Safely extract an array value, returning empty array if not found.
|
|
61
|
+
*/
|
|
62
|
+
function array(obj, path) {
|
|
63
|
+
const value = get(obj, path, []);
|
|
64
|
+
return Array.isArray(value) ? value : [];
|
|
65
|
+
}
|
|
66
|
+
safeExtract.array = array;
|
|
67
|
+
})(safeExtract || (exports.safeExtract = safeExtract = {}));
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@revenium/perplexity",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.22",
|
|
4
4
|
"description": "NodeJS middleware for perplexity's AI API",
|
|
5
5
|
"homepage": "https://github.com/revenium/revenium-middleware-perplexity-node#readme",
|
|
6
6
|
"bugs": {
|
|
@@ -17,6 +17,8 @@
|
|
|
17
17
|
"p-basic": "npx ts-node playground/basic.js",
|
|
18
18
|
"p-streaming": "npx ts-node playground/streaming.js",
|
|
19
19
|
"p-enhanced": "npx ts-node playground/enhanced.js",
|
|
20
|
+
"p-chat-completions": "npx ts-node playground/chat-completions.js",
|
|
21
|
+
"p-metadata": "npx ts-node playground/metadata.js",
|
|
20
22
|
"e-basic": "npx ts-node examples/basic.ts",
|
|
21
23
|
"e-streaming": "npx ts-node examples/streaming.ts",
|
|
22
24
|
"e-chat-completions": "npx ts-node examples/chat-completions.ts",
|
package/playground/basic.js
CHANGED
|
@@ -1,21 +1,17 @@
|
|
|
1
1
|
import { PerplexityReveniumMiddleware } from "@revenium/perplexity";
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
async function basicRequest() {
|
|
4
|
+
console.log("=".repeat(50));
|
|
4
5
|
try {
|
|
5
6
|
const middleware = new PerplexityReveniumMiddleware();
|
|
6
7
|
const model = middleware.getGenerativeModel("sonar-pro");
|
|
7
8
|
const result = await model.createChatCompletion({
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
role: "user",
|
|
11
|
-
content: "Hello world",
|
|
12
|
-
},
|
|
13
|
-
],
|
|
9
|
+
model: "sonar-pro",
|
|
10
|
+
messages: [{ role: "user", content: "What is the capital of France?" }],
|
|
14
11
|
});
|
|
15
|
-
console.log("[BASIC
|
|
12
|
+
console.log("[BASIC REQUEST]", result.choices[0].message);
|
|
16
13
|
} catch (error) {
|
|
17
14
|
console.log(error);
|
|
18
15
|
}
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
basicExample();
|
|
16
|
+
}
|
|
17
|
+
basicRequest();
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { PerplexityReveniumMiddleware } from "@revenium/perplexity";
|
|
2
|
+
|
|
3
|
+
const chatCompletionsExample = async () => {
|
|
4
|
+
console.log("=".repeat(50));
|
|
5
|
+
try {
|
|
6
|
+
const middleware = new PerplexityReveniumMiddleware();
|
|
7
|
+
const model = middleware.getGenerativeModel("sonar-pro");
|
|
8
|
+
const result = await model.createChatCompletion({
|
|
9
|
+
messages: [
|
|
10
|
+
{
|
|
11
|
+
role: "user",
|
|
12
|
+
content: "Hello world",
|
|
13
|
+
},
|
|
14
|
+
],
|
|
15
|
+
});
|
|
16
|
+
console.log(result.choices[0].message.content);
|
|
17
|
+
} catch (error) {
|
|
18
|
+
console.log(error);
|
|
19
|
+
}
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
chatCompletionsExample();
|
package/playground/enhanced.js
CHANGED
|
@@ -1,23 +1,20 @@
|
|
|
1
1
|
import { PerplexityReveniumMiddleware } from "@revenium/perplexity";
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
async function enhancedRequest() {
|
|
4
|
+
console.log("=".repeat(50));
|
|
4
5
|
try {
|
|
5
6
|
const middleware = new PerplexityReveniumMiddleware();
|
|
6
7
|
const model = middleware.getGenerativeModel("sonar-pro");
|
|
7
8
|
const result = await model.createChatCompletion({
|
|
8
9
|
messages: [
|
|
9
|
-
{
|
|
10
|
-
role: "user",
|
|
11
|
-
content: "Explain quantum computing in simple terms",
|
|
12
|
-
},
|
|
10
|
+
{ role: "user", content: "Explain quantum computing in simple terms" },
|
|
13
11
|
],
|
|
14
12
|
max_tokens: 100,
|
|
15
13
|
temperature: 0.7,
|
|
16
14
|
});
|
|
17
|
-
console.log("[ENHANCED
|
|
15
|
+
console.log("[ENHANCED REQUEST]", result.choices[0].message.content);
|
|
18
16
|
} catch (error) {
|
|
19
17
|
console.log(error);
|
|
20
18
|
}
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
enhancedExample();
|
|
19
|
+
}
|
|
20
|
+
enhancedRequest();
|
package/playground/streaming.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { PerplexityReveniumMiddleware } from "@revenium/perplexity";
|
|
2
2
|
|
|
3
|
-
const
|
|
3
|
+
const chatCompletionStreamingExample = async () => {
|
|
4
4
|
console.log("=".repeat(50));
|
|
5
5
|
try {
|
|
6
6
|
const middleware = new PerplexityReveniumMiddleware();
|
|
@@ -21,4 +21,4 @@ const streamingExample = async () => {
|
|
|
21
21
|
}
|
|
22
22
|
};
|
|
23
23
|
|
|
24
|
-
|
|
24
|
+
chatCompletionStreamingExample();
|