MCPcopy Create free account
hub / github.com/AgentOps-AI/agentops / LLMEvent

Class LLMEvent

app/api/agentops/exporter/models.py:362–502  ·  view source on GitHub ↗

LLMEvent becomes a (child) Span

Source from the content-addressed store, hash-verified

360
361
362class LLMEvent(BaseModel):
363 """
364 LLMEvent becomes a (child) Span
365 """
366
367 id: UUID
368 session_id: Optional[UUID] = None
369 agent_id: Optional[UUID] = None
370 thread_id: Optional[UUID] = None
371 prompt: Optional[dict] = None
372 completion: Optional[dict] = None
373 model: Optional[str] = None
374 prompt_tokens: Optional[int] = None
375 completion_tokens: Optional[int] = None
376 cost: Optional[float] = None
377 promptarmor_flag: Optional[bool] = None
378 params: Optional[Union[str, dict]] = None
379 returns: Optional[Union[str, dict]] = None
380 init_timestamp: Optional[datetime] = None
381 end_timestamp: Optional[datetime] = None
382
383 async def to_span(
384 self,
385 trace_id: Optional[str] = None,
386 parent_span_id: Optional[str] = None,
387 project_id: Optional[str] = None,
388 ) -> Span:
389 """Convert an LLMEvent to a Span with GenAI semantic conventions"""
390
391 # Use GenAI semantic conventions for span attributes
392 # See: https://github.com/open-telemetry/semantic-conventions/blob/main/docs/gen-ai/gen-ai.md
393
394 # {
395 # "gen_ai.completion.0.content": "Why couldn't the bicycle stand up by itself? It was two tired.",
396 # "gen_ai.completion.0.finish_reason": "stop",
397 # "gen_ai.completion.0.role": "assistant",
398 # "gen_ai.openai.api_base": "https://api.openai.com/v1/",
399 # "gen_ai.prompt.0.content": "Write a one-line joke",
400 # "gen_ai.prompt.0.role": "user",
401 # "gen_ai.request.model": "gpt-3.5-turbo",
402 # "gen_ai.response.id": "chatcmpl-B9ekm6iX1GDInqhtj5XlmIqFHamFf",
403 # "gen_ai.response.model": "gpt-3.5-turbo-0125",
404 # "gen_ai.system": "OpenAI",
405 # "gen_ai.usage.completion_tokens": "16",
406 # "gen_ai.usage.prompt_tokens": "12",
407 # "llm.headers": "None",
408 # "llm.is_streaming": "false",
409 # "llm.request.type": "chat",
410 # "llm.usage.total_tokens": "28"
411 # }
412
413 span_attributes = {
414 "llm.id": str(self.id),
415 "llm.model": self.model if self.model else "",
416 "llm.prompt_tokens": str(self.prompt_tokens),
417 "llm.completion_tokens": str(self.completion_tokens),
418 "llm.total_tokens": str(self.prompt_tokens + self.completion_tokens),
419 "llm.cost": str(self.cost) if self.cost is not None else "0.0",

Callers 2

create_llm_eventFunction · 0.70
update_llm_eventFunction · 0.70

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…