Skip to content

Commit cd534e3

Browse files
committed
pass logger to ai providers
1 parent cb4a25e commit cd534e3

File tree

2 files changed

+10
-2
lines changed

2 files changed

+10
-2
lines changed

packages/sdk/server-ai/src/api/chat/TrackedChatFactory.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ export class TrackedChatFactory {
8383
// eslint-disable-next-line import/no-extraneous-dependencies, global-require
8484
const { LangChainProvider } = require('@launchdarkly/server-sdk-ai-langchain');
8585

86-
const provider = await LangChainProvider.create(aiConfig);
86+
const provider = await LangChainProvider.create(aiConfig, logger);
8787
logger?.debug('Successfully created LangChain provider');
8888
return provider;
8989
} catch (error) {

packages/sdk/server-ai/src/api/providers/AIProvider.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import { LDLogger } from '@launchdarkly/js-server-sdk-common';
2+
13
import { ChatResponse } from '../chat/types';
24
import { LDAIConfig, LDMessage } from '../config/LDAIConfig';
35

@@ -10,6 +12,11 @@ import { LDAIConfig, LDMessage } from '../config/LDAIConfig';
1012
* for better extensibility and backwards compatibility.
1113
*/
1214
export abstract class AIProvider {
15+
protected readonly logger?: LDLogger;
16+
17+
constructor(logger?: LDLogger) {
18+
this.logger = logger;
19+
}
1320
/**
1421
* Invoke the chat model with an array of messages.
1522
* This method should convert messages to provider format, invoke the model,
@@ -26,10 +33,11 @@ export abstract class AIProvider {
2633
* that accepts an AIConfig and returns a configured instance.
2734
*
2835
* @param aiConfig The LaunchDarkly AI configuration
36+
* @param logger Optional logger for the provider
2937
* @returns Promise that resolves to a configured provider instance
3038
*/
3139
// eslint-disable-next-line @typescript-eslint/no-unused-vars
32-
static async create(aiConfig: LDAIConfig): Promise<AIProvider> {
40+
static async create(aiConfig: LDAIConfig, logger?: LDLogger): Promise<AIProvider> {
3341
throw new Error('Provider implementations must override the static create method');
3442
}
3543
}

0 commit comments

Comments
 (0)