Skip to content

Commit

Permalink
fix: langfuse do not have created_at args and fix the typing in the f…
Browse files Browse the repository at this point in the history
…ile (#11648)

Signed-off-by: yihong0618 <zouzou0208@gmail.com>
  • Loading branch information
yihong0618 authored and iamjoel committed Dec 16, 2024
1 parent aff3309 commit 294be84
Showing 1 changed file with 11 additions and 5 deletions.
16 changes: 11 additions & 5 deletions api/core/ops/langfuse_trace/langfuse_trace.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
from datetime import datetime, timedelta
from typing import Optional

from langfuse import Langfuse
from langfuse import Langfuse # type: ignore

from core.ops.base_trace_instance import BaseTraceInstance
from core.ops.entities.config_entity import LangfuseConfig
Expand Down Expand Up @@ -82,8 +82,6 @@ def workflow_trace(self, trace_info: WorkflowTraceInfo):
metadata=metadata,
session_id=trace_info.conversation_id,
tags=["message", "workflow"],
created_at=trace_info.start_time,
updated_at=trace_info.end_time,
)
self.add_trace(langfuse_trace_data=trace_data)
workflow_span_data = LangfuseSpan(
Expand Down Expand Up @@ -242,11 +240,13 @@ def message_trace(self, trace_info: MessageTraceInfo, **kwargs):
file_list = trace_info.file_list
metadata = trace_info.metadata
message_data = trace_info.message_data
if message_data is None:
return
message_id = message_data.id

user_id = message_data.from_account_id
if message_data.from_end_user_id:
end_user_data: EndUser = (
end_user_data: Optional[EndUser] = (
db.session.query(EndUser).filter(EndUser.id == message_data.from_end_user_id).first()
)
if end_user_data is not None:
Expand Down Expand Up @@ -303,6 +303,8 @@ def message_trace(self, trace_info: MessageTraceInfo, **kwargs):
self.add_generation(langfuse_generation_data)

def moderation_trace(self, trace_info: ModerationTraceInfo):
if trace_info.message_data is None:
return
span_data = LangfuseSpan(
name=TraceTaskName.MODERATION_TRACE.value,
input=trace_info.inputs,
Expand All @@ -322,9 +324,11 @@ def moderation_trace(self, trace_info: ModerationTraceInfo):

def suggested_question_trace(self, trace_info: SuggestedQuestionTraceInfo):
message_data = trace_info.message_data
if message_data is None:
return
generation_usage = GenerationUsage(
total=len(str(trace_info.suggested_question)),
input=len(trace_info.inputs),
input=len(trace_info.inputs) if trace_info.inputs else 0,
output=len(trace_info.suggested_question),
unit=UnitEnum.CHARACTERS,
)
Expand All @@ -345,6 +349,8 @@ def suggested_question_trace(self, trace_info: SuggestedQuestionTraceInfo):
self.add_generation(langfuse_generation_data=generation_data)

def dataset_retrieval_trace(self, trace_info: DatasetRetrievalTraceInfo):
if trace_info.message_data is None:
return
dataset_retrieval_span_data = LangfuseSpan(
name=TraceTaskName.DATASET_RETRIEVAL_TRACE.value,
input=trace_info.inputs,
Expand Down

0 comments on commit 294be84

Please sign in to comment.