Skip to content

Commit 86951b0

Browse files
authored
feat!: Remove deprecated LDAIClient method aliases (#1370)
feat!: Remove `LDAIClient.config` — use `LDAIClient.completionConfig` instead feat!: Remove `LDAIClient.agent` — use `LDAIClient.agentConfig` instead feat!: Remove `LDAIClient.agents` — use `LDAIClient.agentConfigs` instead feat!: Remove `LDAIClient.createChat` — use `LDAIClient.createModel` instead feat!: Remove `LDAIClient.initChat` — use `LDAIClient.createModel` instead feat!: Remove `ChatResponse` type and the `api/chat` module — use `RunnerResult` from `api/model` instead feat!: Change `Judge.evaluateMessages` parameter type from `ChatResponse` to `RunnerResult` feat!: Remove `evaluationMetricKeys` (plural) field from `LDAIJudgeConfig` and `LDAIJudgeConfigDefault` — use `evaluationMetricKey` (singular) instead; the wire-read fallback still accepts the plural in flag variations for backward compatibility feat!: Remove `LDAIConfigTracker.trackOpenAIMetrics` — use `tracker.trackMetricsOf(getAIMetricsFromResponse, fn)` from `@launchdarkly/server-sdk-ai-openai` instead feat!: Remove `LDAIConfigTracker.trackVercelAISDKGenerateTextMetrics` — use `tracker.trackMetricsOf(getAIMetricsFromResponse, fn)` from `@launchdarkly/server-sdk-ai-vercel` instead feat!: Remove `createOpenAiUsage` helper — no longer needed; `trackMetricsOf` extracts usage feat!: Remove `createVercelAISDKTokenUsage` helper — no longer needed; `trackMetricsOf` extracts usage
1 parent 3173625 commit 86951b0

21 files changed

Lines changed: 14 additions & 740 deletions

packages/sdk/server-ai/__tests__/Judge.test.ts

Lines changed: 5 additions & 134 deletions
Original file line numberDiff line numberDiff line change
@@ -318,11 +318,10 @@ describe('Judge', () => {
318318
Math.random = originalRandom;
319319
});
320320

321-
it('returns error result when evaluationMetricKey and evaluationMetricKeys are both missing', async () => {
321+
it('returns error result when evaluationMetricKey is missing', async () => {
322322
const configWithoutMetrics: LDAIJudgeConfig = {
323323
...judgeConfig,
324324
evaluationMetricKey: undefined,
325-
evaluationMetricKeys: [],
326325
};
327326
const judgeWithoutMetrics = new Judge(configWithoutMetrics, mockRunner, 1.0, mockLogger);
328327

@@ -344,7 +343,6 @@ describe('Judge', () => {
344343
const configWithSingleKey: LDAIJudgeConfig = {
345344
...judgeConfig,
346345
evaluationMetricKey: 'relevance',
347-
evaluationMetricKeys: undefined,
348346
};
349347
const judgeWithSingleKey = new Judge(configWithSingleKey, mockRunner, 1.0, mockLogger);
350348

@@ -375,112 +373,6 @@ describe('Judge', () => {
375373
});
376374
});
377375

378-
it('falls back to first value in evaluationMetricKeys when evaluationMetricKey is not provided', async () => {
379-
const configWithLegacyKeys: LDAIJudgeConfig = {
380-
...judgeConfig,
381-
evaluationMetricKey: undefined,
382-
evaluationMetricKeys: ['relevance', 'accuracy'],
383-
};
384-
const judgeWithLegacyKeys = new Judge(configWithLegacyKeys, mockRunner, 1.0, mockLogger);
385-
386-
const mockRunnerResult: RunnerResult = {
387-
content: '',
388-
parsed: {
389-
score: 0.8,
390-
reasoning: 'The response is relevant',
391-
},
392-
metrics: {
393-
success: true,
394-
tokens: { total: 100, input: 50, output: 50 },
395-
},
396-
};
397-
398-
mockTracker.trackMetricsOf.mockImplementation(async (extractor, func) => func());
399-
mockRunner.run.mockResolvedValue(mockRunnerResult);
400-
401-
const result = await judgeWithLegacyKeys.evaluate('test input', 'test output');
402-
403-
expect(result).toEqual({
404-
score: 0.8,
405-
reasoning: 'The response is relevant',
406-
metricKey: 'relevance',
407-
success: true,
408-
sampled: true,
409-
judgeConfigKey: 'test-judge',
410-
});
411-
});
412-
413-
it('skips empty and whitespace-only strings in evaluationMetricKeys array', async () => {
414-
const configWithInvalidKeys: LDAIJudgeConfig = {
415-
...judgeConfig,
416-
evaluationMetricKey: undefined,
417-
evaluationMetricKeys: ['', ' ', 'relevance', 'accuracy'],
418-
};
419-
const judgeWithInvalidKeys = new Judge(configWithInvalidKeys, mockRunner, 1.0, mockLogger);
420-
421-
const mockRunnerResult: RunnerResult = {
422-
content: '',
423-
parsed: {
424-
score: 0.8,
425-
reasoning: 'The response is relevant',
426-
},
427-
metrics: {
428-
success: true,
429-
tokens: { total: 100, input: 50, output: 50 },
430-
},
431-
};
432-
433-
mockTracker.trackMetricsOf.mockImplementation(async (extractor, func) => func());
434-
mockRunner.run.mockResolvedValue(mockRunnerResult);
435-
436-
const result = await judgeWithInvalidKeys.evaluate('test input', 'test output');
437-
438-
// Should skip empty and whitespace strings, use first valid value
439-
expect(result).toEqual({
440-
score: 0.8,
441-
reasoning: 'The response is relevant',
442-
metricKey: 'relevance',
443-
success: true,
444-
sampled: true,
445-
judgeConfigKey: 'test-judge',
446-
});
447-
});
448-
449-
it('prioritizes evaluationMetricKey over evaluationMetricKeys when both are provided', async () => {
450-
const configWithBoth: LDAIJudgeConfig = {
451-
...judgeConfig,
452-
evaluationMetricKey: 'helpfulness',
453-
evaluationMetricKeys: ['relevance', 'accuracy'],
454-
};
455-
const judgeWithBoth = new Judge(configWithBoth, mockRunner, 1.0, mockLogger);
456-
457-
const mockRunnerResult: RunnerResult = {
458-
content: '',
459-
parsed: {
460-
score: 0.7,
461-
reasoning: 'The response is helpful',
462-
},
463-
metrics: {
464-
success: true,
465-
tokens: { total: 100, input: 50, output: 50 },
466-
},
467-
};
468-
469-
mockTracker.trackMetricsOf.mockImplementation(async (extractor, func) => func());
470-
mockRunner.run.mockResolvedValue(mockRunnerResult);
471-
472-
const result = await judgeWithBoth.evaluate('test input', 'test output');
473-
474-
expect(result).toEqual({
475-
score: 0.7,
476-
reasoning: 'The response is helpful',
477-
metricKey: 'helpfulness',
478-
success: true,
479-
sampled: true,
480-
judgeConfigKey: 'test-judge',
481-
});
482-
});
483-
484376
it('proceeds (does not error early) when messages is undefined', async () => {
485377
const configWithoutMessages: LDAIJudgeConfig = {
486378
...judgeConfig,
@@ -629,8 +521,8 @@ describe('Judge', () => {
629521
{ role: 'user', content: 'What is the capital of France?' },
630522
{ role: 'assistant', content: 'Paris is the capital of France.' },
631523
];
632-
const response = {
633-
message: { role: 'assistant' as const, content: 'Paris is the capital of France.' },
524+
const response: RunnerResult = {
525+
content: 'Paris is the capital of France.',
634526
metrics: { success: true },
635527
};
636528

@@ -668,8 +560,8 @@ describe('Judge', () => {
668560

669561
it('handles sampling rate correctly', async () => {
670562
const messages: LDMessage[] = [{ role: 'user', content: 'test' }];
671-
const response = {
672-
message: { role: 'assistant' as const, content: 'test response' },
563+
const response: RunnerResult = {
564+
content: 'test response',
673565
metrics: { success: true },
674566
};
675567

@@ -774,26 +666,5 @@ describe('Judge', () => {
774666
expect(result).toBeUndefined();
775667
});
776668

777-
it('handles empty evaluationMetricKeys array fallback', async () => {
778-
const configWithEmptyKeys: LDAIJudgeConfig = {
779-
...judgeConfig,
780-
evaluationMetricKey: undefined,
781-
evaluationMetricKeys: [],
782-
};
783-
const judgeWithEmptyKeys = new Judge(configWithEmptyKeys, mockRunner, 1.0, mockLogger);
784-
785-
const result = await judgeWithEmptyKeys.evaluate('test input', 'test output');
786-
787-
expect(result).toEqual({
788-
success: false,
789-
sampled: true,
790-
errorMessage: 'Judge configuration is missing required evaluation metric key',
791-
judgeConfigKey: 'test-judge',
792-
});
793-
expect(mockLogger.warn).toHaveBeenCalledWith(
794-
'Judge configuration is missing required evaluation metric key',
795-
mockTrackData,
796-
);
797-
});
798669
});
799670
});

packages/sdk/server-ai/__tests__/LDAIClientImpl.test.ts

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -627,7 +627,7 @@ describe('judgeConfig method', () => {
627627
enabled: true,
628628
model: { name: 'gpt-4' },
629629
provider: { name: 'openai' },
630-
evaluationMetricKeys: ['relevance'],
630+
evaluationMetricKey: 'relevance',
631631
messages: [{ role: 'system' as const, content: 'You are a judge for {{metric}}.' }],
632632
createTracker: () => ({}) as any,
633633
toVercelAISDK: jest.fn(),
@@ -720,7 +720,7 @@ describe('createJudge method', () => {
720720
enabled: true,
721721
model: { name: 'gpt-4' },
722722
provider: { name: 'openai' },
723-
evaluationMetricKeys: ['relevance', 'accuracy'],
723+
evaluationMetricKey: 'relevance',
724724
messages: [{ role: 'system' as const, content: 'You are a judge.' }],
725725
createTracker: () => mockTrackerInstance,
726726
toVercelAISDK: jest.fn(),
@@ -754,7 +754,6 @@ describe('createJudge method', () => {
754754
const mockJudgeConfig = {
755755
key: 'test-judge',
756756
enabled: false,
757-
evaluationMetricKeys: [],
758757
};
759758

760759
const judgeConfigSpy = jest.spyOn(client as any, '_judgeConfig');
@@ -780,7 +779,7 @@ describe('createJudge method', () => {
780779
enabled: true,
781780
model: { name: 'gpt-4' },
782781
provider: { name: 'openai' },
783-
evaluationMetricKeys: ['relevance'],
782+
evaluationMetricKey: 'relevance',
784783
messages: [{ role: 'system' as const, content: 'You are a judge.' }],
785784
createTracker: () => ({}) as any,
786785
toVercelAISDK: jest.fn(),

0 commit comments

Comments
 (0)