@mate-academy/prompt-client 1.0.0 → 2.0.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/README.md +127 -69
- package/dist/LLMPromptClient.constants.d.ts +2 -0
- package/dist/LLMPromptClient.constants.js +3 -1
- package/dist/LLMPromptClient.errors.d.ts +5 -0
- package/dist/LLMPromptClient.errors.js +10 -1
- package/dist/LLMPromptClient.typedefs.d.ts +88 -3
- package/dist/LLMPromptClient.typedefs.js +8 -1
- package/dist/PromptManagement.typedefs.d.ts +6 -5
- package/dist/index.d.ts +0 -4
- package/dist/index.js +0 -4
- package/dist/providers/InMemory/InMemory.factory.js +1 -8
- package/dist/providers/InMemory/InMemory.typedefs.d.ts +9 -13
- package/dist/providers/InMemory/InMemoryPrompt.client.d.ts +14 -2
- package/dist/providers/InMemory/InMemoryPrompt.client.js +113 -0
- package/dist/providers/Langfuse/Langfuse.factory.js +7 -9
- package/dist/providers/Langfuse/Langfuse.helpers.d.ts +8 -1
- package/dist/providers/Langfuse/Langfuse.helpers.js +27 -11
- package/dist/providers/Langfuse/Langfuse.typedefs.d.ts +0 -2
- package/dist/providers/Langfuse/LangfusePrompt.client.d.ts +18 -5
- package/dist/providers/Langfuse/LangfusePrompt.client.js +170 -18
- package/dist/providers/Langfuse/LangfusePrompt.d.ts +13 -2
- package/dist/providers/Langfuse/LangfusePrompt.js +19 -1
- package/dist/utilities/index.d.ts +0 -1
- package/dist/utilities/index.js +0 -1
- package/package.json +3 -4
- package/dist/LLMTracer.errors.d.ts +0 -4
- package/dist/LLMTracer.errors.js +0 -11
- package/dist/LLMTracer.typedefs.d.ts +0 -45
- package/dist/LLMTracer.typedefs.js +0 -2
- package/dist/providers/InMemory/InMemoryTracer.client.d.ts +0 -15
- package/dist/providers/InMemory/InMemoryTracer.client.js +0 -63
- package/dist/providers/Langfuse/LangfuseTracer.client.d.ts +0 -13
- package/dist/providers/Langfuse/LangfuseTracer.client.js +0 -49
- package/dist/utilities/usageDetails/index.d.ts +0 -1
- package/dist/utilities/usageDetails/index.js +0 -17
- package/dist/utilities/usageDetails/usageDetails.helpers.d.ts +0 -17
- package/dist/utilities/usageDetails/usageDetails.helpers.js +0 -33
|
@@ -1,45 +0,0 @@
|
|
|
1
|
-
import { type LLMPrompt } from './LLMPromptClient.typedefs';
|
|
2
|
-
export interface LLMTraceOptions {
|
|
3
|
-
name: string;
|
|
4
|
-
sessionId?: string;
|
|
5
|
-
userId?: string;
|
|
6
|
-
tags?: string[];
|
|
7
|
-
metadata?: Record<string, unknown>;
|
|
8
|
-
input?: unknown;
|
|
9
|
-
output?: unknown;
|
|
10
|
-
}
|
|
11
|
-
export interface LLMTraceUpdateOptions<Input = unknown, Output = unknown> {
|
|
12
|
-
input?: Input;
|
|
13
|
-
output?: Output;
|
|
14
|
-
metadata?: Record<string, unknown>;
|
|
15
|
-
}
|
|
16
|
-
export interface LLMTrace {
|
|
17
|
-
id: string;
|
|
18
|
-
getTraceUrl(): string;
|
|
19
|
-
update<Input = unknown, Output = unknown>(options: LLMTraceUpdateOptions<Input, Output>): void;
|
|
20
|
-
}
|
|
21
|
-
export interface LLMGenerationOptions {
|
|
22
|
-
name: string;
|
|
23
|
-
model?: string;
|
|
24
|
-
modelParameters?: Record<string, string | number | boolean | null>;
|
|
25
|
-
metadata?: Record<string, unknown>;
|
|
26
|
-
input?: unknown;
|
|
27
|
-
output?: unknown;
|
|
28
|
-
prompt?: LLMPrompt;
|
|
29
|
-
}
|
|
30
|
-
export interface LLMGenerationEndOptions {
|
|
31
|
-
output?: unknown;
|
|
32
|
-
metadata?: Record<string, unknown>;
|
|
33
|
-
usageDetails?: Record<string, number>;
|
|
34
|
-
costDetails?: Record<string, number>;
|
|
35
|
-
}
|
|
36
|
-
export interface LLMGeneration {
|
|
37
|
-
id: string;
|
|
38
|
-
end(options?: LLMGenerationEndOptions): void;
|
|
39
|
-
}
|
|
40
|
-
export interface LLMTracer {
|
|
41
|
-
createTrace(options: LLMTraceOptions): LLMTrace;
|
|
42
|
-
createGeneration(trace: LLMTrace, options: LLMGenerationOptions): LLMGeneration;
|
|
43
|
-
flush(): Promise<void>;
|
|
44
|
-
shutdown(): Promise<void>;
|
|
45
|
-
}
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
import { type LLMGeneration, type LLMGenerationOptions, type LLMTrace, type LLMTraceOptions, type LLMTracer } from '../../LLMTracer.typedefs';
|
|
2
|
-
import { type InMemoryRecordedGeneration, type InMemoryRecordedTrace } from '../../providers/InMemory/InMemory.typedefs';
|
|
3
|
-
export declare class InMemoryTracer implements LLMTracer {
|
|
4
|
-
readonly traces: InMemoryRecordedTrace[];
|
|
5
|
-
readonly generations: InMemoryRecordedGeneration[];
|
|
6
|
-
flushCallCount: number;
|
|
7
|
-
shutdownCallCount: number;
|
|
8
|
-
private nextEntityNumber;
|
|
9
|
-
createTrace(options: LLMTraceOptions): LLMTrace;
|
|
10
|
-
createGeneration(trace: LLMTrace, options: LLMGenerationOptions): LLMGeneration;
|
|
11
|
-
flush(): Promise<void>;
|
|
12
|
-
shutdown(): Promise<void>;
|
|
13
|
-
reset(): void;
|
|
14
|
-
private takeEntityNumber;
|
|
15
|
-
}
|
|
@@ -1,63 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.InMemoryTracer = void 0;
|
|
4
|
-
class InMemoryTracer {
|
|
5
|
-
constructor() {
|
|
6
|
-
this.traces = [];
|
|
7
|
-
this.generations = [];
|
|
8
|
-
this.flushCallCount = 0;
|
|
9
|
-
this.shutdownCallCount = 0;
|
|
10
|
-
this.nextEntityNumber = 1;
|
|
11
|
-
}
|
|
12
|
-
createTrace(options) {
|
|
13
|
-
const recordedTrace = {
|
|
14
|
-
id: `trace-${this.takeEntityNumber()}`,
|
|
15
|
-
options,
|
|
16
|
-
updates: [],
|
|
17
|
-
};
|
|
18
|
-
this.traces.push(recordedTrace);
|
|
19
|
-
return {
|
|
20
|
-
id: recordedTrace.id,
|
|
21
|
-
getTraceUrl: () => `in-memory://traces/${recordedTrace.id}`,
|
|
22
|
-
update: (updateOptions) => {
|
|
23
|
-
recordedTrace.updates.push(updateOptions);
|
|
24
|
-
},
|
|
25
|
-
};
|
|
26
|
-
}
|
|
27
|
-
createGeneration(trace, options) {
|
|
28
|
-
const recordedGeneration = {
|
|
29
|
-
id: `generation-${this.takeEntityNumber()}`,
|
|
30
|
-
traceId: trace.id,
|
|
31
|
-
options,
|
|
32
|
-
endOptions: null,
|
|
33
|
-
isEnded: false,
|
|
34
|
-
};
|
|
35
|
-
this.generations.push(recordedGeneration);
|
|
36
|
-
return {
|
|
37
|
-
id: recordedGeneration.id,
|
|
38
|
-
end: (endOptions) => {
|
|
39
|
-
recordedGeneration.endOptions = endOptions ?? null;
|
|
40
|
-
recordedGeneration.isEnded = true;
|
|
41
|
-
},
|
|
42
|
-
};
|
|
43
|
-
}
|
|
44
|
-
async flush() {
|
|
45
|
-
this.flushCallCount += 1;
|
|
46
|
-
}
|
|
47
|
-
async shutdown() {
|
|
48
|
-
this.shutdownCallCount += 1;
|
|
49
|
-
}
|
|
50
|
-
reset() {
|
|
51
|
-
this.traces.splice(0);
|
|
52
|
-
this.generations.splice(0);
|
|
53
|
-
this.flushCallCount = 0;
|
|
54
|
-
this.shutdownCallCount = 0;
|
|
55
|
-
this.nextEntityNumber = 1;
|
|
56
|
-
}
|
|
57
|
-
takeEntityNumber() {
|
|
58
|
-
const entityNumber = this.nextEntityNumber;
|
|
59
|
-
this.nextEntityNumber += 1;
|
|
60
|
-
return entityNumber;
|
|
61
|
-
}
|
|
62
|
-
}
|
|
63
|
-
exports.InMemoryTracer = InMemoryTracer;
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
import { type Langfuse } from 'langfuse';
|
|
2
|
-
import { type LLMGeneration, type LLMGenerationOptions, type LLMTrace, type LLMTraceOptions, type LLMTracer } from '../../LLMTracer.typedefs';
|
|
3
|
-
import { type PromptManagementLogger } from '../../utilities/logger';
|
|
4
|
-
export declare class LangfuseTracer implements LLMTracer {
|
|
5
|
-
private readonly client;
|
|
6
|
-
private readonly logger;
|
|
7
|
-
constructor(client: Langfuse, logger: PromptManagementLogger);
|
|
8
|
-
createTrace(options: LLMTraceOptions): LLMTrace;
|
|
9
|
-
createGeneration(trace: LLMTrace, options: LLMGenerationOptions): LLMGeneration;
|
|
10
|
-
flush(): Promise<void>;
|
|
11
|
-
shutdown(): Promise<void>;
|
|
12
|
-
private wrapError;
|
|
13
|
-
}
|
|
@@ -1,49 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.LangfuseTracer = void 0;
|
|
4
|
-
const LLMTracer_errors_1 = require("../../LLMTracer.errors");
|
|
5
|
-
const LangfusePrompt_1 = require("../../providers/Langfuse/LangfusePrompt");
|
|
6
|
-
class LangfuseTracer {
|
|
7
|
-
constructor(client, logger) {
|
|
8
|
-
this.client = client;
|
|
9
|
-
this.logger = logger;
|
|
10
|
-
}
|
|
11
|
-
createTrace(options) {
|
|
12
|
-
try {
|
|
13
|
-
return this.client.trace(options);
|
|
14
|
-
}
|
|
15
|
-
catch (error) {
|
|
16
|
-
throw this.wrapError('Failed to create Langfuse trace', error, {
|
|
17
|
-
traceName: options.name,
|
|
18
|
-
});
|
|
19
|
-
}
|
|
20
|
-
}
|
|
21
|
-
createGeneration(trace, options) {
|
|
22
|
-
const { prompt, ...generationOptions } = options;
|
|
23
|
-
try {
|
|
24
|
-
return this.client.generation({
|
|
25
|
-
...generationOptions,
|
|
26
|
-
traceId: trace.id,
|
|
27
|
-
...(prompt instanceof LangfusePrompt_1.LangfusePrompt
|
|
28
|
-
? { prompt: prompt.nativePrompt }
|
|
29
|
-
: {}),
|
|
30
|
-
});
|
|
31
|
-
}
|
|
32
|
-
catch (error) {
|
|
33
|
-
throw this.wrapError('Failed to create Langfuse generation', error, {
|
|
34
|
-
generationName: options.name,
|
|
35
|
-
});
|
|
36
|
-
}
|
|
37
|
-
}
|
|
38
|
-
flush() {
|
|
39
|
-
return this.client.flushAsync();
|
|
40
|
-
}
|
|
41
|
-
shutdown() {
|
|
42
|
-
return this.client.shutdownAsync();
|
|
43
|
-
}
|
|
44
|
-
wrapError(message, error, fields) {
|
|
45
|
-
this.logger.error(message, { error, ...fields });
|
|
46
|
-
return new LLMTracer_errors_1.LLMTracerError(message, error);
|
|
47
|
-
}
|
|
48
|
-
}
|
|
49
|
-
exports.LangfuseTracer = LangfuseTracer;
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export * from '../../utilities/usageDetails/usageDetails.helpers';
|
|
@@ -1,17 +0,0 @@
|
|
|
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
|
-
__exportStar(require("../../utilities/usageDetails/usageDetails.helpers"), exports);
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
export interface LLMUsageInput {
|
|
2
|
-
inputTextTokens?: number;
|
|
3
|
-
outputTextTokens?: number;
|
|
4
|
-
inputAudioTokens?: number;
|
|
5
|
-
outputAudioTokens?: number;
|
|
6
|
-
inputCachedTextTokens?: number;
|
|
7
|
-
inputCachedAudioTokens?: number;
|
|
8
|
-
outputReasoningTokens?: number;
|
|
9
|
-
}
|
|
10
|
-
export interface LLMCostInput {
|
|
11
|
-
input: number;
|
|
12
|
-
output: number;
|
|
13
|
-
total: number;
|
|
14
|
-
currency: string;
|
|
15
|
-
}
|
|
16
|
-
export declare const usageToUsageDetails: (usage?: LLMUsageInput) => Record<string, number> | undefined;
|
|
17
|
-
export declare const costToCostDetails: (cost?: LLMCostInput) => Record<string, number> | undefined;
|
|
@@ -1,33 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.costToCostDetails = exports.usageToUsageDetails = void 0;
|
|
4
|
-
const toPositiveDetails = (keyedAmounts) => {
|
|
5
|
-
const populated = keyedAmounts.filter(([, amount]) => amount > 0);
|
|
6
|
-
if (populated.length === 0) {
|
|
7
|
-
return undefined;
|
|
8
|
-
}
|
|
9
|
-
return Object.fromEntries(populated);
|
|
10
|
-
};
|
|
11
|
-
const usageToUsageDetails = (usage) => {
|
|
12
|
-
if (!usage) {
|
|
13
|
-
return undefined;
|
|
14
|
-
}
|
|
15
|
-
return toPositiveDetails([
|
|
16
|
-
['input', usage.inputTextTokens ?? 0],
|
|
17
|
-
['input_cached', usage.inputCachedTextTokens ?? 0],
|
|
18
|
-
['output', (usage.outputTextTokens ?? 0) + (usage.outputReasoningTokens ?? 0)],
|
|
19
|
-
['input_audio', usage.inputAudioTokens ?? 0],
|
|
20
|
-
['output_audio', usage.outputAudioTokens ?? 0],
|
|
21
|
-
]);
|
|
22
|
-
};
|
|
23
|
-
exports.usageToUsageDetails = usageToUsageDetails;
|
|
24
|
-
const costToCostDetails = (cost) => {
|
|
25
|
-
if (!cost) {
|
|
26
|
-
return undefined;
|
|
27
|
-
}
|
|
28
|
-
return toPositiveDetails([
|
|
29
|
-
['input', cost.input],
|
|
30
|
-
['output', cost.output],
|
|
31
|
-
]);
|
|
32
|
-
};
|
|
33
|
-
exports.costToCostDetails = costToCostDetails;
|