diff --git a/api/core/ops/entities/trace_entity.py b/api/core/ops/entities/trace_entity.py index 3dc3ac60a3169c..17eba251dc8551 100644 --- a/api/core/ops/entities/trace_entity.py +++ b/api/core/ops/entities/trace_entity.py @@ -5,12 +5,12 @@ class BaseTraceInfo(BaseModel): - message_id: str + message_id: Optional[str] = None message_data: Any inputs: Union[str, dict[str, Any], list, None] outputs: Union[str, dict[str, Any], list, None] - start_time: datetime - end_time: datetime + start_time: Optional[datetime] = None + end_time: Optional[datetime] = None metadata: dict[str, Any] diff --git a/api/core/ops/langfuse_trace/langfuse_trace.py b/api/core/ops/langfuse_trace/langfuse_trace.py index e966e220f92ec4..ba37441c8aa2cd 100644 --- a/api/core/ops/langfuse_trace/langfuse_trace.py +++ b/api/core/ops/langfuse_trace/langfuse_trace.py @@ -158,7 +158,7 @@ def message_trace( "total_tokens": trace_info.total_tokens, "error": trace_info.error, "provider_response_latency": message_data.provider_response_latency, - "created_at": trace_info.start_at, + "created_at": trace_info.start_time, }, output=trace_info.outputs, metadata=metadata, @@ -179,7 +179,7 @@ def message_trace( langfuse_generation_data = LangfuseGeneration( name=f"generation_{message_id}", trace_id=message_id, - start_time=trace_info.start_at, + start_time=trace_info.start_time, end_time=trace_info.end_time, model=message_data.model_id, input=trace_info.inputs, diff --git a/api/core/ops/langsmith_trace/langsmith_trace.py b/api/core/ops/langsmith_trace/langsmith_trace.py index 3e173ea22985ed..a2db80e9c248c8 100644 --- a/api/core/ops/langsmith_trace/langsmith_trace.py +++ b/api/core/ops/langsmith_trace/langsmith_trace.py @@ -169,7 +169,7 @@ def message_trace(self, trace_info: MessageTraceInfo, **kwargs): name=f"message_{message_id}", inputs=trace_info.inputs, run_type=LangSmithRunType.chain, - start_time=trace_info.start_at, + start_time=trace_info.start_time, end_time=trace_info.end_time, outputs=message_data.answer, extra={ @@ -189,7 +189,7 @@ def message_trace(self, trace_info: MessageTraceInfo, **kwargs): name=f"llm_{message_id}", inputs=trace_info.inputs, run_type=LangSmithRunType.llm, - start_time=trace_info.start_at, + start_time=trace_info.start_time, end_time=trace_info.end_time, outputs=message_data.answer, extra={ diff --git a/api/core/ops/trace_queue_manager.py b/api/core/ops/trace_queue_manager.py index 4a177c51b307de..444b983b34d303 100644 --- a/api/core/ops/trace_queue_manager.py +++ b/api/core/ops/trace_queue_manager.py @@ -183,7 +183,7 @@ def message_trace(self, message_id): inputs=inputs, outputs=message_data.answer, file_list=message_data.message[0].get("files", []), - start_at=created_at, + start_time=created_at, end_time=created_at + timedelta(seconds=message_data.provider_response_latency), metadata=metadata, message_file_data=message_file_data,