44
55from langchain_core .language_models .chat_models import BaseChatModel
66from langchain_core .messages import AIMessage , BaseMessage , HumanMessage , SystemMessage
7- from ldai import LDMessage
7+ from ldai import LDMessage , log
88from ldai .models import AIConfigKind
99from ldai .providers import AIProvider
1010from ldai .providers .types import ChatResponse , LDAIMetrics , StructuredResponse
@@ -18,27 +18,24 @@ class LangChainProvider(AIProvider):
1818 This provider integrates LangChain models with LaunchDarkly's tracking capabilities.
1919 """
2020
21- def __init__ (self , llm : BaseChatModel , logger : Optional [ Any ] = None ):
21+ def __init__ (self , llm : BaseChatModel ):
2222 """
2323 Initialize the LangChain provider.
2424
2525 :param llm: A LangChain BaseChatModel instance
26- :param logger: Optional logger for logging provider operations
2726 """
28- super ().__init__ (logger )
2927 self ._llm = llm
3028
3129 @staticmethod
32- async def create (ai_config : AIConfigKind , logger : Optional [ Any ] = None ) -> 'LangChainProvider' :
30+ async def create (ai_config : AIConfigKind ) -> 'LangChainProvider' :
3331 """
3432 Static factory method to create a LangChain AIProvider from an AI configuration.
3533
3634 :param ai_config: The LaunchDarkly AI configuration
37- :param logger: Optional logger for the provider
3835 :return: Configured LangChainProvider instance
3936 """
4037 llm = LangChainProvider .create_langchain_model (ai_config )
41- return LangChainProvider (llm , logger )
38+ return LangChainProvider (llm )
4239
4340 async def invoke_model (self , messages : List [LDMessage ]) -> ChatResponse :
4441 """
@@ -56,20 +53,18 @@ async def invoke_model(self, messages: List[LDMessage]) -> ChatResponse:
5653 if isinstance (response .content , str ):
5754 content = response .content
5855 else :
59- if self .logger :
60- self .logger .warn (
61- f'Multimodal response not supported, expecting a string. '
62- f'Content type: { type (response .content )} , Content: { response .content } '
63- )
56+ log .warn (
57+ f'Multimodal response not supported, expecting a string. '
58+ f'Content type: { type (response .content )} , Content: { response .content } '
59+ )
6460 metrics = LDAIMetrics (success = False , usage = metrics .usage )
6561
6662 return ChatResponse (
6763 message = LDMessage (role = 'assistant' , content = content ),
6864 metrics = metrics ,
6965 )
7066 except Exception as error :
71- if self .logger :
72- self .logger .warn (f'LangChain model invocation failed: { error } ' )
67+ log .warn (f'LangChain model invocation failed: { error } ' )
7368
7469 return ChatResponse (
7570 message = LDMessage (role = 'assistant' , content = '' ),
@@ -94,11 +89,10 @@ async def invoke_structured_model(
9489 response = await structured_llm .ainvoke (langchain_messages )
9590
9691 if not isinstance (response , dict ):
97- if self .logger :
98- self .logger .warn (
99- f'Structured output did not return a dict. '
100- f'Got: { type (response )} '
101- )
92+ log .warn (
93+ f'Structured output did not return a dict. '
94+ f'Got: { type (response )} '
95+ )
10296 return StructuredResponse (
10397 data = {},
10498 raw_response = '' ,
@@ -117,8 +111,7 @@ async def invoke_structured_model(
117111 ),
118112 )
119113 except Exception as error :
120- if self .logger :
121- self .logger .warn (f'LangChain structured model invocation failed: { error } ' )
114+ log .warn (f'LangChain structured model invocation failed: { error } ' )
122115
123116 return StructuredResponse (
124117 data = {},
0 commit comments