Skip to content

Commit b010b4b

Browse files
gustavocidornelaswhoseoyster
authored andcommitted
Fix pylint issues
1 parent ef024cb commit b010b4b

File tree

5 files changed

+33
-10
lines changed

5 files changed

+33
-10
lines changed

openlayer/llm_monitors.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -178,6 +178,7 @@ def stream_chunks():
178178
start_time = time.time()
179179
first_token_time = None
180180
num_of_completion_tokens = None
181+
latency = None
181182
try:
182183
i = 0
183184
for i, chunk in enumerate(chunks):

openlayer/tracing/enums.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
"""Module with the enums used in the tracing module."""
2+
13
import enum
24

35

openlayer/tracing/steps.py

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,17 +7,24 @@
77

88

99
class Step:
10+
"""Step, defined as a single function call being traced.
11+
12+
This is the base class for all the different types of steps that can be
13+
used in a trace. Steps can also contain nested steps, which represent
14+
function calls made within the parent step.
15+
"""
16+
1017
def __init__(
1118
self,
1219
name: str,
1320
inputs: Optional[Any] = None,
1421
output: Optional[Any] = None,
15-
metadata: Dict[str, any] = {},
22+
metadata: Optional[Dict[str, any]] = None,
1623
) -> None:
1724
self.name = name
1825
self.inputs = inputs
1926
self.output = output
20-
self.metadata = metadata
27+
self.metadata = metadata or {}
2128

2229
self.step_type: enums.StepType = None
2330
self.start_time = time.time()
@@ -54,24 +61,28 @@ def to_dict(self) -> Dict[str, Any]:
5461

5562

5663
class UserCallStep(Step):
64+
"""User call step represents a generic user call in the trace."""
65+
5766
def __init__(
5867
self,
5968
name: str,
6069
inputs: Optional[Any] = None,
6170
output: Optional[Any] = None,
62-
metadata: Dict[str, any] = {},
71+
metadata: Optional[Dict[str, any]] = None,
6372
) -> None:
6473
super().__init__(name=name, inputs=inputs, output=output, metadata=metadata)
6574
self.step_type = enums.StepType.USER_CALL
6675

6776

6877
class ChatCompletionStep(Step):
78+
"""Chat completion step represents an LLM chat completion in the trace."""
79+
6980
def __init__(
7081
self,
7182
name: str,
7283
inputs: Optional[Any] = None,
7384
output: Optional[Any] = None,
74-
metadata: Dict[str, any] = {},
85+
metadata: Optional[Dict[str, any]] = None,
7586
) -> None:
7687
super().__init__(name=name, inputs=inputs, output=output, metadata=metadata)
7788

openlayer/tracing/tracer.py

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
_streamer = None
1717
try:
1818
_streamer = data_streamer.DataStreamer(publish=True)
19+
# pylint: disable=broad-except
1920
except 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

9293
def 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,

openlayer/tracing/traces.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,12 @@
66

77

88
class Trace:
9+
"""Trace, defined as a sequence of steps.
10+
11+
Each step represents a function call being traced. Steps can also
12+
contain nested steps, which represent function calls made within the
13+
parent step."""
14+
915
def __init__(self):
1016
self.steps = []
1117
self.current_step = None

0 commit comments

Comments
 (0)