(self, chat_record: ChatRecord)
| 300 | version=Cache_Version.CHAT_VARIABLE.get_version()) or {} |
| 301 | |
| 302 | def append_chat_record(self, chat_record: ChatRecord): |
| 303 | chat_record.problem_text = chat_record.problem_text[0:10240] if chat_record.problem_text is not None else "" |
| 304 | chat_record.answer_text = chat_record.answer_text[0:40960] if chat_record.problem_text is not None else "" |
| 305 | is_save = True |
| 306 | # 存入缓存中 |
| 307 | for index in range(len(self.chat_record_list)): |
| 308 | record = self.chat_record_list[index] |
| 309 | if record.id == chat_record.id: |
| 310 | self.chat_record_list[index] = chat_record |
| 311 | is_save = False |
| 312 | break |
| 313 | if is_save: |
| 314 | self.chat_record_list.append(chat_record) |
| 315 | if not self.debug: |
| 316 | if not QuerySet(Chat).filter(id=self.chat_id).exists(): |
| 317 | Chat(id=self.chat_id, application_id=self.application_id, abstract=chat_record.problem_text[0:1024], |
| 318 | chat_user_id=self.chat_user_id, chat_user_type=self.chat_user_type, |
| 319 | ip_address=self.ip_address, source=self.source, |
| 320 | asker=self.get_chat_user()).save() |
| 321 | else: |
| 322 | QuerySet(Chat).filter(id=self.chat_id).update(update_time=timezone.now()) |
| 323 | # 插入会话记录 |
| 324 | QuerySet(ChatRecord).update_or_create(id=chat_record.id, |
| 325 | create_defaults={'id': chat_record.id, |
| 326 | 'chat_id': chat_record.chat_id, |
| 327 | "vote_status": chat_record.vote_status, |
| 328 | 'problem_text': chat_record.problem_text, |
| 329 | 'answer_text': chat_record.answer_text, |
| 330 | 'answer_text_list': chat_record.answer_text_list, |
| 331 | 'message_tokens': chat_record.message_tokens, |
| 332 | 'answer_tokens': chat_record.answer_tokens, |
| 333 | 'const': chat_record.const, |
| 334 | 'details': chat_record.details, |
| 335 | 'improve_paragraph_id_list': chat_record.improve_paragraph_id_list, |
| 336 | 'run_time': chat_record.run_time, |
| 337 | 'source': chat_record.source, |
| 338 | 'ip_address': chat_record.ip_address or '', |
| 339 | 'index': chat_record.index}, |
| 340 | defaults={ |
| 341 | "vote_status": chat_record.vote_status, |
| 342 | 'problem_text': chat_record.problem_text, |
| 343 | 'answer_text': chat_record.answer_text, |
| 344 | 'answer_text_list': chat_record.answer_text_list, |
| 345 | 'message_tokens': chat_record.message_tokens, |
| 346 | 'answer_tokens': chat_record.answer_tokens, |
| 347 | 'const': chat_record.const, |
| 348 | 'details': chat_record.details, |
| 349 | 'improve_paragraph_id_list': chat_record.improve_paragraph_id_list, |
| 350 | 'run_time': chat_record.run_time, |
| 351 | 'index': chat_record.index, |
| 352 | 'source': chat_record.source, |
| 353 | 'ip_address': chat_record.ip_address or '', |
| 354 | }) |
| 355 | ChatCountSerializer(data={'chat_id': self.chat_id}).update_chat() |
| 356 | |
| 357 | def to_dict(self): |
| 358 |
no test coverage detected