44import os
55from typing import Any , Dict , Iterable , List , Optional , cast
66
7+ from ldclient import log
8+
79from ldai import LDMessage
810from ldai .models import AIConfigKind
911from ldai .providers import AIProvider
@@ -25,17 +27,14 @@ def __init__(
2527 client : AsyncOpenAI ,
2628 model_name : str ,
2729 parameters : Dict [str , Any ],
28- logger : Optional [Any ] = None
2930 ):
3031 """
3132 Initialize the OpenAI provider.
3233
3334 :param client: An AsyncOpenAI client instance
3435 :param model_name: The name of the model to use
3536 :param parameters: Additional model parameters
36- :param logger: Optional logger for logging provider operations
3737 """
38- super ().__init__ (logger )
3938 self ._client = client
4039 self ._model_name = model_name
4140 self ._parameters = parameters
@@ -45,12 +44,11 @@ def __init__(
4544 # =============================================================================
4645
4746 @staticmethod
48- async def create (ai_config : AIConfigKind , logger : Optional [ Any ] = None ) -> 'OpenAIProvider' :
47+ async def create (ai_config : AIConfigKind ) -> 'OpenAIProvider' :
4948 """
5049 Static factory method to create an OpenAI AIProvider from an AI configuration.
5150
5251 :param ai_config: The LaunchDarkly AI configuration
53- :param logger: Optional logger for the provider
5452 :return: Configured OpenAIProvider instance
5553 """
5654 client = AsyncOpenAI (
@@ -62,7 +60,7 @@ async def create(ai_config: AIConfigKind, logger: Optional[Any] = None) -> 'Open
6260 model_name = model_dict .get ('name' , '' )
6361 parameters = model_dict .get ('parameters' ) or {}
6462
65- return OpenAIProvider (client , model_name , parameters , logger )
63+ return OpenAIProvider (client , model_name , parameters )
6664
6765 # =============================================================================
6866 # INSTANCE METHODS (AIProvider Implementation)
@@ -99,17 +97,15 @@ async def invoke_model(self, messages: List[LDMessage]) -> ChatResponse:
9997 content = message .content
10098
10199 if not content :
102- if self .logger :
103- self .logger .warn ('OpenAI response has no content available' )
100+ log .warn ('OpenAI response has no content available' )
104101 metrics = LDAIMetrics (success = False , usage = metrics .usage )
105102
106103 return ChatResponse (
107104 message = LDMessage (role = 'assistant' , content = content ),
108105 metrics = metrics ,
109106 )
110107 except Exception as error :
111- if self .logger :
112- self .logger .warn (f'OpenAI model invocation failed: { error } ' )
108+ log .warn (f'OpenAI model invocation failed: { error } ' )
113109
114110 return ChatResponse (
115111 message = LDMessage (role = 'assistant' , content = '' ),
@@ -160,8 +156,7 @@ async def invoke_structured_model(
160156 content = message .content
161157
162158 if not content :
163- if self .logger :
164- self .logger .warn ('OpenAI structured response has no content available' )
159+ log .warn ('OpenAI structured response has no content available' )
165160 metrics = LDAIMetrics (success = False , usage = metrics .usage )
166161 return StructuredResponse (
167162 data = {},
@@ -177,17 +172,15 @@ async def invoke_structured_model(
177172 metrics = metrics ,
178173 )
179174 except json .JSONDecodeError as parse_error :
180- if self .logger :
181- self .logger .warn (f'OpenAI structured response contains invalid JSON: { parse_error } ' )
175+ log .warn (f'OpenAI structured response contains invalid JSON: { parse_error } ' )
182176 metrics = LDAIMetrics (success = False , usage = metrics .usage )
183177 return StructuredResponse (
184178 data = {},
185179 raw_response = content ,
186180 metrics = metrics ,
187181 )
188182 except Exception as error :
189- if self .logger :
190- self .logger .warn (f'OpenAI structured model invocation failed: { error } ' )
183+ log .warn (f'OpenAI structured model invocation failed: { error } ' )
191184
192185 return StructuredResponse (
193186 data = {},
0 commit comments