Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -385,6 +385,7 @@ def _build_from_streaming_response(
# this function would not be able to catch the errors, as they are
# raised later, after the generator is returned, and when it is being
# consumed.
span.add_event("llm.content.completion.chunk")
chunk_result = process_stream_chunk(
chunk,
role,
Expand Down Expand Up @@ -435,6 +436,7 @@ async def _abuild_from_streaming_response(
# this function would not be able to catch the errors, as they are
# raised later, after the generator is returned, and when it is being
# consumed.
span.add_event("llm.content.completion.chunk")
chunk_result = process_stream_chunk(
chunk,
role,
Expand Down
6 changes: 3 additions & 3 deletions src/lmnr/sdk/laminar.py
Original file line number Diff line number Diff line change
Expand Up @@ -671,12 +671,12 @@ def set_span_attributes(
instrumentation.
Example:
```python
with L.start_as_current_span(
with Laminar.start_as_current_span(
name="my_span_name", input=input["messages"], span_type="LLM"
):
response = await my_custom_call_to_openai(input)
L.set_span_output(response["choices"][0]["message"]["content"])
L.set_span_attributes({
Laminar.set_span_output(response["choices"][0]["message"]["content"])
Laminar.set_span_attributes({
Attributes.PROVIDER: 'openai',
Attributes.REQUEST_MODEL: input["model"],
Attributes.RESPONSE_MODEL: response["model"],
Expand Down
4 changes: 4 additions & 0 deletions tests/test_google_genai.py
Original file line number Diff line number Diff line change
Expand Up @@ -847,8 +847,10 @@ def test_google_genai_streaming(span_exporter: InMemorySpanExporter):
],
)
final_response = ""
chunk_count = 0
for chunk in stream:
final_response += chunk.text or ""
chunk_count += 1

spans = span_exporter.get_finished_spans()
assert len(spans) == 1
Expand Down Expand Up @@ -885,6 +887,8 @@ def test_google_genai_streaming(span_exporter: InMemorySpanExporter):
assert span.attributes["gen_ai.usage.input_tokens"] == 7
assert span.attributes["gen_ai.usage.output_tokens"] == 166
assert span.attributes["llm.usage.total_tokens"] == 175 # 173 + 2 (thinking tokens)
assert len(span.events) == chunk_count
assert all(event.name == "llm.content.completion.chunk" for event in span.events)


@pytest.mark.vcr
Expand Down