File size: 6,855 Bytes
4304c6d
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
from flask_restful import fields

from fields.member_fields import simple_account_fields
from libs.helper import TimestampField


class MessageTextField(fields.Raw):
    def format(self, value):
        return value[0]['text'] if value else ''


feedback_fields = {
    '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),
}

annotation_fields = {
    'id': fields.String,
    'question': fields.String,
    'content': fields.String,
    'account': fields.Nested(simple_account_fields, allow_null=True),
    'created_at': TimestampField
}

annotation_hit_history_fields = {
    'annotation_id': fields.String(attribute='id'),
    'annotation_create_account': fields.Nested(simple_account_fields, allow_null=True),
    'created_at': TimestampField
}

message_file_fields = {
    'id': fields.String,
    'type': fields.String,
    'url': fields.String,
    'belongs_to': fields.String(default='user'),
}

agent_thought_fields = {
    '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),
}

message_detail_fields = {
    '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
}

model_config_fields = {
    'opening_statement': fields.String,
    'suggested_questions': fields.Raw,
    'model': fields.Raw,
    'user_input_form': fields.Raw,
    'pre_prompt': fields.String,
    'agent_mode': fields.Raw,
}

simple_configs_fields = {
    'prompt_template': fields.String,
}

simple_model_config_fields = {
    'model': fields.Raw(attribute='model_dict'),
    'pre_prompt': fields.String,
}

simple_message_detail_fields = {
    'inputs': fields.Raw,
    'query': fields.String,
    'message': MessageTextField,
    'answer': fields.String,
}

conversation_fields = {
    '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')
}

conversation_pagination_fields = {
    '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')
}

conversation_message_detail_fields = {
    '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'),
}

conversation_with_summary_fields = {
    '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,
    '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)
}

conversation_with_summary_pagination_fields = {
    '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')
}

conversation_detail_fields = {
    '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)
}

simple_conversation_fields = {
    'id': fields.String,
    'name': fields.String,
    'inputs': fields.Raw,
    'status': fields.String,
    'introduction': fields.String,
    'created_at': TimestampField
}

conversation_infinite_scroll_pagination_fields = {
    'limit': fields.Integer,
    'has_more': fields.Boolean,
    'data': fields.List(fields.Nested(simple_conversation_fields))
}

conversation_with_model_config_fields = {
    **simple_conversation_fields,
    'model_config': fields.Raw,
}

conversation_with_model_config_infinite_scroll_pagination_fields = {
    'limit': fields.Integer,
    'has_more': fields.Boolean,
    'data': fields.List(fields.Nested(conversation_with_model_config_fields))
}