Skip to content

Commit 6daf423

Browse files
authored
Merge branch 'confident-ai:main' into main
2 parents c0b09fa + cd64a04 commit 6daf423

2 files changed

Lines changed: 27 additions & 25 deletions

File tree

deepeval/tracing/otel/exporter.py

Lines changed: 25 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@ def _extract_llm_attributes(self, span: ReadableSpan, res: Dict) -> Dict:
151151
if event.name in ["gen_ai.system.message", "gen_ai.user.message"]:
152152
attributes = event.attributes
153153
res["input"].append(
154-
{"role": event.name, "content": dict(attributes)}
154+
{"role": event.name, "content": dict(attributes) if attributes is not None else {}}
155155
)
156156
# output
157157
if event.name in [
@@ -161,43 +161,45 @@ def _extract_llm_attributes(self, span: ReadableSpan, res: Dict) -> Dict:
161161
]:
162162
res["output"] = str(event.attributes)
163163

164-
res["model"] = str(span.attributes.get("gen_ai.request.model"))
165-
res["input_token_count"] = int(
166-
span.attributes.get("gen_ai.usage.input_tokens")
167-
)
168-
res["output_token_count"] = int(
169-
span.attributes.get("gen_ai.usage.output_tokens")
170-
)
171-
res["cost_per_input_token"] = float(
172-
span.attributes.get("confident.llm.cost_per_input_token")
173-
)
174-
res["cost_per_output_token"] = float(
175-
span.attributes.get("confident.llm.cost_per_output_token")
176-
)
164+
model = span.attributes.get("gen_ai.request.model")
165+
res["model"] = str(model) if model is not None else None
166+
167+
input_tokens = span.attributes.get("gen_ai.usage.input_tokens")
168+
res["input_token_count"] = int(input_tokens) if input_tokens is not None else None
169+
170+
output_tokens = span.attributes.get("gen_ai.usage.output_tokens")
171+
res["output_token_count"] = int(output_tokens) if output_tokens is not None else None
172+
173+
cost_per_input = span.attributes.get("confident.llm.cost_per_input_token")
174+
res["cost_per_input_token"] = float(cost_per_input) if cost_per_input is not None else None
175+
176+
cost_per_output = span.attributes.get("confident.llm.cost_per_output_token")
177+
res["cost_per_output_token"] = float(cost_per_output) if cost_per_output is not None else None
177178

178179
return res
179180

180181
def _extract_tool_attributes(self, span: ReadableSpan, res: Dict) -> Dict:
181182
for event in span.events:
182183
# input
183184
if event.name in ["confident.tool.input"]:
184-
res["input"] = dict(event.attributes)
185+
res["input"] = dict(event.attributes) if event.attributes is not None else {}
185186
# output
186187
if event.name in ["confident.tool.output"]:
187-
res["output"] = dict(event.attributes)
188+
res["output"] = dict(event.attributes) if event.attributes is not None else {}
188189

189-
res["description"] = str(span.attributes.get("gen_ai.tool.description"))
190+
description = span.attributes.get("gen_ai.tool.description")
191+
res["description"] = str(description) if description is not None else None
190192

191193
return res
192194

193195
def _extract_agent_attributes(self, span: ReadableSpan, res: Dict) -> Dict:
194196
for event in span.events:
195197
# input
196198
if event.name in ["confident.agent.input"]:
197-
res["input"] = dict(event.attributes)
199+
res["input"] = dict(event.attributes) if event.attributes is not None else {}
198200
# output
199201
if event.name in ["confident.agent.output"]:
200-
res["output"] = dict(event.attributes)
202+
res["output"] = dict(event.attributes) if event.attributes is not None else {}
201203

202204
available_tools = span.attributes.get("confident.agent.available_tools")
203205
if isinstance(available_tools, tuple):
@@ -226,10 +228,10 @@ def _extract_retriever_attributes(
226228
res["output"] = [str(attribute) for attribute in attributes]
227229

228230
res["embedder"] = str(span.attributes.get("gen_ai.request.model"))
229-
res["top_k"] = int(span.attributes.get("confident.retriever.top_k"))
230-
res["chunk_size"] = int(
231-
span.attributes.get("confident.retriever.chunk_size")
232-
)
231+
top_k = span.attributes.get("confident.retriever.top_k")
232+
res["top_k"] = int(top_k) if top_k is not None else None
233+
chunk_size = span.attributes.get("confident.retriever.chunk_size")
234+
res["chunk_size"] = int(chunk_size) if chunk_size is not None else None
233235
return res
234236

235237
def aggregate_base_api_spans_to_traces(

poetry.lock

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)