2023-09-27 16:06:32 +08:00
|
|
|
from flask_restful import fields
|
2024-02-06 13:21:13 +08:00
|
|
|
|
2024-04-08 18:51:46 +08:00
|
|
|
from fields.member_fields import simple_account_fields
|
2023-09-27 16:06:32 +08:00
|
|
|
from libs.helper import TimestampField
|
|
|
|
|
|
|
|
|
|
|
|
class MessageTextField(fields.Raw):
|
|
|
|
def format(self, value):
|
2024-08-15 12:54:05 +08:00
|
|
|
return value[0]["text"] if value else ""
|
2023-09-27 16:06:32 +08:00
|
|
|
|
|
|
|
|
|
|
|
feedback_fields = {
|
2024-08-15 12:54:05 +08:00
|
|
|
"rating": fields.String,
|
|
|
|
"content": fields.String,
|
|
|
|
"from_source": fields.String,
|
|
|
|
"from_end_user_id": fields.String,
|
|
|
|
"from_account": fields.Nested(simple_account_fields, allow_null=True),
|
2023-09-27 16:06:32 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
annotation_fields = {
|
2024-08-15 12:54:05 +08:00
|
|
|
"id": fields.String,
|
|
|
|
"question": fields.String,
|
|
|
|
"content": fields.String,
|
|
|
|
"account": fields.Nested(simple_account_fields, allow_null=True),
|
|
|
|
"created_at": TimestampField,
|
2023-09-27 16:06:32 +08:00
|
|
|
}
|
|
|
|
|
2023-12-18 13:10:05 +08:00
|
|
|
annotation_hit_history_fields = {
|
2024-08-15 12:54:05 +08:00
|
|
|
"annotation_id": fields.String(attribute="id"),
|
|
|
|
"annotation_create_account": fields.Nested(simple_account_fields, allow_null=True),
|
|
|
|
"created_at": TimestampField,
|
2023-12-18 13:10:05 +08:00
|
|
|
}
|
|
|
|
|
2023-11-13 22:05:46 +08:00
|
|
|
message_file_fields = {
|
2024-08-15 12:54:05 +08:00
|
|
|
"id": fields.String,
|
|
|
|
"type": fields.String,
|
|
|
|
"url": fields.String,
|
|
|
|
"belongs_to": fields.String(default="user"),
|
2024-01-23 19:58:23 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
agent_thought_fields = {
|
2024-08-15 12:54:05 +08:00
|
|
|
"id": fields.String,
|
|
|
|
"chain_id": fields.String,
|
|
|
|
"message_id": fields.String,
|
|
|
|
"position": fields.Integer,
|
|
|
|
"thought": fields.String,
|
|
|
|
"tool": fields.String,
|
|
|
|
"tool_labels": fields.Raw,
|
|
|
|
"tool_input": fields.String,
|
|
|
|
"created_at": TimestampField,
|
|
|
|
"observation": fields.String,
|
|
|
|
"files": fields.List(fields.String),
|
2023-11-13 22:05:46 +08:00
|
|
|
}
|
|
|
|
|
2023-09-27 16:06:32 +08:00
|
|
|
message_detail_fields = {
|
2024-08-15 12:54:05 +08:00
|
|
|
"id": fields.String,
|
|
|
|
"conversation_id": fields.String,
|
|
|
|
"inputs": fields.Raw,
|
|
|
|
"query": fields.String,
|
|
|
|
"message": fields.Raw,
|
|
|
|
"message_tokens": fields.Integer,
|
|
|
|
"answer": fields.String(attribute="re_sign_file_url_answer"),
|
|
|
|
"answer_tokens": fields.Integer,
|
|
|
|
"provider_response_latency": fields.Float,
|
|
|
|
"from_source": fields.String,
|
|
|
|
"from_end_user_id": fields.String,
|
|
|
|
"from_account_id": fields.String,
|
|
|
|
"feedbacks": fields.List(fields.Nested(feedback_fields)),
|
|
|
|
"workflow_run_id": fields.String,
|
|
|
|
"annotation": fields.Nested(annotation_fields, allow_null=True),
|
|
|
|
"annotation_hit_history": fields.Nested(annotation_hit_history_fields, allow_null=True),
|
|
|
|
"created_at": TimestampField,
|
|
|
|
"agent_thoughts": fields.List(fields.Nested(agent_thought_fields)),
|
|
|
|
"message_files": fields.List(fields.Nested(message_file_fields), attribute="files"),
|
|
|
|
"metadata": fields.Raw(attribute="message_metadata_dict"),
|
|
|
|
"status": fields.String,
|
|
|
|
"error": fields.String,
|
|
|
|
}
|
|
|
|
|
|
|
|
feedback_stat_fields = {"like": fields.Integer, "dislike": fields.Integer}
|
2023-09-27 16:06:32 +08:00
|
|
|
|
|
|
|
model_config_fields = {
|
2024-08-15 12:54:05 +08:00
|
|
|
"opening_statement": fields.String,
|
|
|
|
"suggested_questions": fields.Raw,
|
|
|
|
"model": fields.Raw,
|
|
|
|
"user_input_form": fields.Raw,
|
|
|
|
"pre_prompt": fields.String,
|
|
|
|
"agent_mode": fields.Raw,
|
2023-09-27 16:06:32 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
simple_configs_fields = {
|
2024-08-15 12:54:05 +08:00
|
|
|
"prompt_template": fields.String,
|
2023-09-27 16:06:32 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
simple_model_config_fields = {
|
2024-08-15 12:54:05 +08:00
|
|
|
"model": fields.Raw(attribute="model_dict"),
|
|
|
|
"pre_prompt": fields.String,
|
2023-09-27 16:06:32 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
simple_message_detail_fields = {
|
2024-08-15 12:54:05 +08:00
|
|
|
"inputs": fields.Raw,
|
|
|
|
"query": fields.String,
|
|
|
|
"message": MessageTextField,
|
|
|
|
"answer": fields.String,
|
2023-09-27 16:06:32 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
conversation_fields = {
|
2024-08-15 12:54:05 +08:00
|
|
|
"id": fields.String,
|
|
|
|
"status": fields.String,
|
|
|
|
"from_source": fields.String,
|
|
|
|
"from_end_user_id": fields.String,
|
|
|
|
"from_end_user_session_id": fields.String(),
|
|
|
|
"from_account_id": fields.String,
|
|
|
|
"read_at": TimestampField,
|
|
|
|
"created_at": TimestampField,
|
|
|
|
"annotation": fields.Nested(annotation_fields, allow_null=True),
|
|
|
|
"model_config": fields.Nested(simple_model_config_fields),
|
|
|
|
"user_feedback_stats": fields.Nested(feedback_stat_fields),
|
|
|
|
"admin_feedback_stats": fields.Nested(feedback_stat_fields),
|
|
|
|
"message": fields.Nested(simple_message_detail_fields, attribute="first_message"),
|
2023-09-27 16:06:32 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
conversation_pagination_fields = {
|
2024-08-15 12:54:05 +08:00
|
|
|
"page": fields.Integer,
|
|
|
|
"limit": fields.Integer(attribute="per_page"),
|
|
|
|
"total": fields.Integer,
|
|
|
|
"has_more": fields.Boolean(attribute="has_next"),
|
|
|
|
"data": fields.List(fields.Nested(conversation_fields), attribute="items"),
|
2023-09-27 16:06:32 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
conversation_message_detail_fields = {
|
2024-08-15 12:54:05 +08:00
|
|
|
"id": fields.String,
|
|
|
|
"status": fields.String,
|
|
|
|
"from_source": fields.String,
|
|
|
|
"from_end_user_id": fields.String,
|
|
|
|
"from_account_id": fields.String,
|
|
|
|
"created_at": TimestampField,
|
|
|
|
"model_config": fields.Nested(model_config_fields),
|
|
|
|
"message": fields.Nested(message_detail_fields, attribute="first_message"),
|
2023-09-27 16:06:32 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
conversation_with_summary_fields = {
|
2024-08-15 12:54:05 +08:00
|
|
|
"id": fields.String,
|
|
|
|
"status": fields.String,
|
|
|
|
"from_source": fields.String,
|
|
|
|
"from_end_user_id": fields.String,
|
|
|
|
"from_end_user_session_id": fields.String,
|
|
|
|
"from_account_id": fields.String,
|
|
|
|
"name": fields.String,
|
|
|
|
"summary": fields.String(attribute="summary_or_query"),
|
|
|
|
"read_at": TimestampField,
|
|
|
|
"created_at": TimestampField,
|
2024-08-20 17:55:44 +08:00
|
|
|
"updated_at": TimestampField,
|
2024-08-15 12:54:05 +08:00
|
|
|
"annotated": fields.Boolean,
|
|
|
|
"model_config": fields.Nested(simple_model_config_fields),
|
|
|
|
"message_count": fields.Integer,
|
|
|
|
"user_feedback_stats": fields.Nested(feedback_stat_fields),
|
|
|
|
"admin_feedback_stats": fields.Nested(feedback_stat_fields),
|
2023-09-27 16:06:32 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
conversation_with_summary_pagination_fields = {
|
2024-08-15 12:54:05 +08:00
|
|
|
"page": fields.Integer,
|
|
|
|
"limit": fields.Integer(attribute="per_page"),
|
|
|
|
"total": fields.Integer,
|
|
|
|
"has_more": fields.Boolean(attribute="has_next"),
|
|
|
|
"data": fields.List(fields.Nested(conversation_with_summary_fields), attribute="items"),
|
2023-09-27 16:06:32 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
conversation_detail_fields = {
|
2024-08-15 12:54:05 +08:00
|
|
|
"id": fields.String,
|
|
|
|
"status": fields.String,
|
|
|
|
"from_source": fields.String,
|
|
|
|
"from_end_user_id": fields.String,
|
|
|
|
"from_account_id": fields.String,
|
|
|
|
"created_at": TimestampField,
|
|
|
|
"annotated": fields.Boolean,
|
|
|
|
"introduction": fields.String,
|
|
|
|
"model_config": fields.Nested(model_config_fields),
|
|
|
|
"message_count": fields.Integer,
|
|
|
|
"user_feedback_stats": fields.Nested(feedback_stat_fields),
|
|
|
|
"admin_feedback_stats": fields.Nested(feedback_stat_fields),
|
2023-09-27 16:06:32 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
simple_conversation_fields = {
|
2024-08-15 12:54:05 +08:00
|
|
|
"id": fields.String,
|
|
|
|
"name": fields.String,
|
|
|
|
"inputs": fields.Raw,
|
|
|
|
"status": fields.String,
|
|
|
|
"introduction": fields.String,
|
|
|
|
"created_at": TimestampField,
|
2023-09-27 16:06:32 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
conversation_infinite_scroll_pagination_fields = {
|
2024-08-15 12:54:05 +08:00
|
|
|
"limit": fields.Integer,
|
|
|
|
"has_more": fields.Boolean,
|
|
|
|
"data": fields.List(fields.Nested(simple_conversation_fields)),
|
2023-09-27 16:06:32 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
conversation_with_model_config_fields = {
|
|
|
|
**simple_conversation_fields,
|
2024-08-15 12:54:05 +08:00
|
|
|
"model_config": fields.Raw,
|
2023-09-27 16:06:32 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
conversation_with_model_config_infinite_scroll_pagination_fields = {
|
2024-08-15 12:54:05 +08:00
|
|
|
"limit": fields.Integer,
|
|
|
|
"has_more": fields.Boolean,
|
|
|
|
"data": fields.List(fields.Nested(conversation_with_model_config_fields)),
|
2023-11-13 22:05:46 +08:00
|
|
|
}
|