1616_streamer = None
1717try :
1818 _streamer = data_streamer .DataStreamer (publish = True )
19+ # pylint: disable=broad-except
1920except Exception as exc :
2021 logger .error (
2122 "You have not provided enough information to upload traces to Openlayer."
@@ -34,7 +35,7 @@ def create_step(
3435 step_type : enums .StepType = enums .StepType .USER_CALL ,
3536 inputs : Optional [Any ] = None ,
3637 output : Optional [Any ] = None ,
37- metadata : Dict [str , any ] = {} ,
38+ metadata : Optional [ Dict [str , Any ]] = None ,
3839) -> Generator [steps .Step , None , None ]:
3940 """Starts a trace and yields a Step object."""
4041 new_step : steps .Step = steps .step_factory (
@@ -50,7 +51,7 @@ def create_step(
5051 _current_trace .set (current_trace ) # Set the current trace in context
5152 current_trace .add_step (new_step )
5253 else :
53- logger .debug (f "Adding step { name } to parent step { parent_step .name } " )
54+ logger .debug ("Adding step %s to parent step %s" , name , parent_step .name )
5455 current_trace = _current_trace .get ()
5556 parent_step .add_nested_step (new_step )
5657
@@ -86,7 +87,7 @@ def create_step(
8687 " Openlayer."
8788 )
8889 else :
89- logger .debug (f "Ending step { name } " )
90+ logger .debug ("Ending step %s" , name )
9091
9192
9293def add_openai_chat_completion_step_to_trace (** kwargs ) -> None :
@@ -133,17 +134,19 @@ def wrapper(*func_args, **func_kwargs):
133134
134135
135136# --------------------- Helper post-processing functions --------------------- #
136- def process_trace_for_upload (trace : traces .Trace ) -> Tuple [Dict [str , Any ], List [str ]]:
137+ def process_trace_for_upload (
138+ trace_obj : traces .Trace ,
139+ ) -> Tuple [Dict [str , Any ], List [str ]]:
137140 """Post processing of the trace data before uploading to Openlayer.
138141
139142 This is done to ensure backward compatibility with data on Openlayer.
140143 """
141- root_step = trace .steps [0 ]
144+ root_step = trace_obj .steps [0 ]
142145
143146 input_variables = root_step .inputs
144147 input_variable_names = list (input_variables .keys ())
145148
146- processed_steps = bubble_up_costs_and_tokens (trace .to_dict ())
149+ processed_steps = bubble_up_costs_and_tokens (trace_obj .to_dict ())
147150
148151 trace_data = {
149152 ** input_variables ,
0 commit comments