Skip to content
Open
Show file tree
Hide file tree
Changes from all 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 @@ -2,9 +2,14 @@


class Config:
use_legacy_attributes = True
emit_prompt_events = True
emit_completion_events = True
enrich_token_usage = False
enrich_assistant = False
exception_logger = None
get_common_metrics_attributes: Callable[[], dict] = lambda: {}
upload_base64_image: Callable[[str, str, str], str] = lambda trace_id, span_id, base64_image_url: str
upload_base64_image: Callable[[str, str, str], str] = (
lambda trace_id, span_id, base64_image_url: str
)
enable_trace_context_propagation: bool = True
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,20 @@ async def start_as_current_span_async(tracer, *args, **kwargs):
yield span


def record_prompt_and_completion(span, prompt: str, completion: str):
"""
Emit prompt/completion as attributes or events based on Config.
"""
if Config.use_legacy_attributes:
span.set_attribute("llm.prompt", prompt)
span.set_attribute("llm.completion", completion)
else:
if Config.emit_prompt_events:
span.add_event("prompt", {"llm.prompt": prompt})
if Config.emit_completion_events:
span.add_event("completion", {"llm.completion": completion})


def dont_throw(func):
"""
A decorator that wraps the passed in function and logs exceptions instead of throwing them.
Expand Down