mirror of
https://github.com/langgenius/dify.git
synced 2024-11-16 03:32:23 +08:00
feat: implement function dispatch table for trace processing (#6628)
This commit is contained in:
parent
3e18d32ce5
commit
f78d0082ae
|
@ -298,34 +298,29 @@ class TraceTask:
|
||||||
self.file_base_url = os.getenv("FILES_URL", "http://127.0.0.1:5001")
|
self.file_base_url = os.getenv("FILES_URL", "http://127.0.0.1:5001")
|
||||||
|
|
||||||
def execute(self):
|
def execute(self):
|
||||||
method_name, trace_info = self.preprocess()
|
return self.preprocess()
|
||||||
return trace_info
|
|
||||||
|
|
||||||
def preprocess(self):
|
def preprocess(self):
|
||||||
if self.trace_type == TraceTaskName.CONVERSATION_TRACE:
|
preprocess_map = {
|
||||||
return TraceTaskName.CONVERSATION_TRACE, self.conversation_trace(**self.kwargs)
|
TraceTaskName.CONVERSATION_TRACE: lambda: self.conversation_trace(**self.kwargs),
|
||||||
if self.trace_type == TraceTaskName.WORKFLOW_TRACE:
|
TraceTaskName.WORKFLOW_TRACE: lambda: self.workflow_trace(self.workflow_run, self.conversation_id),
|
||||||
return TraceTaskName.WORKFLOW_TRACE, self.workflow_trace(self.workflow_run, self.conversation_id)
|
TraceTaskName.MESSAGE_TRACE: lambda: self.message_trace(self.message_id),
|
||||||
elif self.trace_type == TraceTaskName.MESSAGE_TRACE:
|
TraceTaskName.MODERATION_TRACE: lambda: self.moderation_trace(
|
||||||
return TraceTaskName.MESSAGE_TRACE, self.message_trace(self.message_id)
|
|
||||||
elif self.trace_type == TraceTaskName.MODERATION_TRACE:
|
|
||||||
return TraceTaskName.MODERATION_TRACE, self.moderation_trace(self.message_id, self.timer, **self.kwargs)
|
|
||||||
elif self.trace_type == TraceTaskName.SUGGESTED_QUESTION_TRACE:
|
|
||||||
return TraceTaskName.SUGGESTED_QUESTION_TRACE, self.suggested_question_trace(
|
|
||||||
self.message_id, self.timer, **self.kwargs
|
self.message_id, self.timer, **self.kwargs
|
||||||
)
|
),
|
||||||
elif self.trace_type == TraceTaskName.DATASET_RETRIEVAL_TRACE:
|
TraceTaskName.SUGGESTED_QUESTION_TRACE: lambda: self.suggested_question_trace(
|
||||||
return TraceTaskName.DATASET_RETRIEVAL_TRACE, self.dataset_retrieval_trace(
|
|
||||||
self.message_id, self.timer, **self.kwargs
|
self.message_id, self.timer, **self.kwargs
|
||||||
)
|
),
|
||||||
elif self.trace_type == TraceTaskName.TOOL_TRACE:
|
TraceTaskName.DATASET_RETRIEVAL_TRACE: lambda: self.dataset_retrieval_trace(
|
||||||
return TraceTaskName.TOOL_TRACE, self.tool_trace(self.message_id, self.timer, **self.kwargs)
|
self.message_id, self.timer, **self.kwargs
|
||||||
elif self.trace_type == TraceTaskName.GENERATE_NAME_TRACE:
|
),
|
||||||
return TraceTaskName.GENERATE_NAME_TRACE, self.generate_name_trace(
|
TraceTaskName.TOOL_TRACE: lambda: self.tool_trace(self.message_id, self.timer, **self.kwargs),
|
||||||
|
TraceTaskName.GENERATE_NAME_TRACE: lambda: self.generate_name_trace(
|
||||||
self.conversation_id, self.timer, **self.kwargs
|
self.conversation_id, self.timer, **self.kwargs
|
||||||
)
|
),
|
||||||
else:
|
}
|
||||||
return '', {}
|
|
||||||
|
return preprocess_map.get(self.trace_type, lambda: None)()
|
||||||
|
|
||||||
# process methods for different trace types
|
# process methods for different trace types
|
||||||
def conversation_trace(self, **kwargs):
|
def conversation_trace(self, **kwargs):
|
||||||
|
|
Loading…
Reference in New Issue
Block a user