@@ -39,25 +39,25 @@ def traced_method(wrapped, instance, args, kwargs):
3939 ),
4040 }
4141 span_attributes ["dspy.optimizer.module.prog" ] = json .dumps (prog )
42- if "metric" in instance and instance . metric :
43- span_attributes ["dspy.optimizer.metric" ] = instance . metric .__name__
42+ if hasattr ( instance , ' metric' ) :
43+ span_attributes ["dspy.optimizer.metric" ] = getattr ( instance , ' metric' ) .__name__
4444 if kwargs .get ("trainset" ) and len (kwargs .get ("trainset" )) > 0 :
4545 span_attributes ["dspy.optimizer.trainset" ] = str (kwargs .get ("trainset" ))
4646 config = {}
47- if "metric_threshold" in instance and instance . metric_threshold :
48- config ["metric_threshold" ] = instance . metric_threshold
49- if "teacher_settings" in instance and instance . teacher_settings :
50- config ["teacher_settings" ] = instance . teacher_settings
51- if "max_bootstrapped_demos" in instance and instance . max_bootstrapped_demos :
52- config ["max_bootstrapped_demos" ] = instance . max_bootstrapped_demos
53- if "max_labeled_demos" in instance and instance . max_labeled_demos :
54- config ["max_labeled_demos" ] = instance . max_labeled_demos
55- if "max_rounds" in instance and instance . max_rounds :
56- config ["max_rounds" ] = instance . max_rounds
57- if "max_errors" in instance and instance . max_errors :
58- config ["max_errors" ] = instance . max_errors
59- if "error_count" in instance and instance . error_count :
60- config ["error_count" ] = instance . error_count
47+ if hasattr ( instance , ' metric_threshold' ) :
48+ config ["metric_threshold" ] = getattr ( instance , ' metric_threshold' )
49+ if hasattr ( instance , ' teacher_settings' ) :
50+ config ["teacher_settings" ] = getattr ( instance , ' teacher_settings' )
51+ if hasattr ( instance , ' max_bootstrapped_demos' ) :
52+ config ["max_bootstrapped_demos" ] = getattr ( instance , ' max_bootstrapped_demos' )
53+ if hasattr ( instance , ' max_labeled_demos' ) :
54+ config ["max_labeled_demos" ] = getattr ( instance , ' max_labeled_demos' )
55+ if hasattr ( instance , ' max_rounds' ) :
56+ config ["max_rounds" ] = getattr ( instance , ' max_rounds' )
57+ if hasattr ( instance , 'max_steps' ) :
58+ config ["max_errors" ] = getattr ( instance , ' max_errors' )
59+ if hasattr ( instance , ' error_count' ) :
60+ config ["error_count" ] = getattr ( instance , ' error_count' )
6161 if config and len (config ) > 0 :
6262 span_attributes ["dspy.optimizer.config" ] = json .dumps (config )
6363
@@ -147,30 +147,30 @@ def traced_method(wrapped, instance, args, kwargs):
147147 ** (extra_attributes if extra_attributes is not None else {}),
148148 }
149149
150- if "devset" in instance and instance . devset is not None :
151- span_attributes ["dspy.evaluate.devset" ] = str (instance . devset )
152- if "display" in instance and instance . display is not None :
153- span_attributes ["dspy.evaluate.display" ] = str (instance . display )
154- if "num_threads" in instance and instance . num_threads is not None :
155- span_attributes ["dspy.evaluate.num_threads" ] = str (instance . num_threads )
156- if "return_outputs" in instance and instance . return_outputs is not None :
150+ if hasattr ( instance , " devset" ) :
151+ span_attributes ["dspy.evaluate.devset" ] = str (getattr ( instance , " devset" ) )
152+ if hasattr ( instance , "trainset" ) :
153+ span_attributes ["dspy.evaluate.display" ] = str (getattr ( instance , "trainset" ) )
154+ if hasattr ( instance , " num_threads" ) :
155+ span_attributes ["dspy.evaluate.num_threads" ] = str (getattr ( instance , " num_threads" ) )
156+ if hasattr ( instance , " return_outputs" ) :
157157 span_attributes ["dspy.evaluate.return_outputs" ] = str (
158- instance . return_outputs
158+ getattr ( instance , " return_outputs" )
159159 )
160- if "display_table" in instance and instance . display_table is not None :
161- span_attributes ["dspy.evaluate.display_table" ] = str (instance . display_table )
162- if "display_progress" in instance and instance . display_progress is not None :
160+ if hasattr ( instance , " display_table" ) :
161+ span_attributes ["dspy.evaluate.display_table" ] = str (getattr ( instance , " display_table" ) )
162+ if hasattr ( instance , " display_progress" ) :
163163 span_attributes ["dspy.evaluate.display_progress" ] = str (
164- instance . display_progress
164+ getattr ( instance , " display_progress" )
165165 )
166- if "metric" in instance and instance . metric is not None :
167- span_attributes ["dspy.evaluate.metric" ] = instance . metric .__name__
168- if "error_count" in instance and instance . error_count is not None :
169- span_attributes ["dspy.evaluate.error_count" ] = str (instance . error_count )
170- if "error_lock" in instance and instance . error_lock is not None :
171- span_attributes ["dspy.evaluate.error_lock" ] = str (instance . error_lock )
172- if "max_errors" in instance and instance . max_errors is not None :
173- span_attributes ["dspy.evaluate.max_errors" ] = str (instance . max_errors )
166+ if hasattr ( instance , " metric" ) :
167+ span_attributes ["dspy.evaluate.metric" ] = getattr ( instance , " metric" ) .__name__
168+ if hasattr ( instance , " error_count" ) :
169+ span_attributes ["dspy.evaluate.error_count" ] = str (getattr ( instance , " error_count" ) )
170+ if hasattr ( instance , " error_lock" ) :
171+ span_attributes ["dspy.evaluate.error_lock" ] = str (getattr ( instance , " error_lock" ) )
172+ if hasattr ( instance , " max_errors" ) :
173+ span_attributes ["dspy.evaluate.max_errors" ] = str (getattr ( instance , " max_errors" ) )
174174 if args and len (args ) > 0 :
175175 span_attributes ["dspy.evaluate.args" ] = str (args )
176176
0 commit comments