### What problem does this PR solve? #381 ### Type of change - [x] Refactoringtags/v0.3.0
| res = { | res = { | ||||
| "pv": [(o["dt"], o["pv"]) for o in objs], | "pv": [(o["dt"], o["pv"]) for o in objs], | ||||
| "uv": [(o["dt"], o["uv"]) for o in objs], | "uv": [(o["dt"], o["uv"]) for o in objs], | ||||
| "speed": [(o["dt"], o["tokens"]/o["duration"]) for o in objs], | |||||
| "tokens": [(o["dt"], o["tokens"]/1000.) for o in objs], | |||||
| "speed": [(o["dt"], float(o["tokens"])/float(o["duration"])) for o in objs], | |||||
| "tokens": [(o["dt"], float(o["tokens"])/1000.) for o in objs], | |||||
| "round": [(o["dt"], o["round"]) for o in objs], | "round": [(o["dt"], o["round"]) for o in objs], | ||||
| "thumb_up": [(o["dt"], o["thumb_up"]) for o in objs] | "thumb_up": [(o["dt"], o["thumb_up"]) for o in objs] | ||||
| } | } | ||||
| return server_error_response(e) | return server_error_response(e) | ||||
| @manager.route('/new_conversation', methods=['POST']) | |||||
| @validate_request("user_id") | |||||
| @manager.route('/new_conversation', methods=['GET']) | |||||
| def set_conversation(): | def set_conversation(): | ||||
| token = request.headers.get('Authorization').split()[1] | token = request.headers.get('Authorization').split()[1] | ||||
| objs = APIToken.query(token=token) | objs = APIToken.query(token=token) | ||||
| conv = { | conv = { | ||||
| "id": get_uuid(), | "id": get_uuid(), | ||||
| "dialog_id": dia.id, | "dialog_id": dia.id, | ||||
| "user_id": req["user_id"], | |||||
| "user_id": request.args.get("user_id", ""), | |||||
| "message": [{"role": "assistant", "content": dia.prompt_config["prologue"]}] | "message": [{"role": "assistant", "content": dia.prompt_config["prologue"]}] | ||||
| } | } | ||||
| API4ConversationService.save(**conv) | API4ConversationService.save(**conv) |
| max_length=128, | max_length=128, | ||||
| null=False, | null=False, | ||||
| default="local", | default="local", | ||||
| help_text="where dose this document from") | |||||
| help_text="where dose this document come from") | |||||
| type = CharField(max_length=32, null=False, help_text="file extension") | type = CharField(max_length=32, null=False, help_text="file extension") | ||||
| created_by = CharField( | created_by = CharField( | ||||
| max_length=32, | max_length=32, |
| model_dir, "updown_concat_xgb.model")) | model_dir, "updown_concat_xgb.model")) | ||||
| except Exception as e: | except Exception as e: | ||||
| model_dir = snapshot_download( | model_dir = snapshot_download( | ||||
| repo_id="InfiniFlow/text_concat_xgb_v1.0") | |||||
| repo_id="InfiniFlow/text_concat_xgb_v1.0", | |||||
| local_dir=os.path.join(get_project_base_directory(), "rag/res/deepdoc"), | |||||
| local_dir_use_symlinks=False) | |||||
| self.updown_cnt_mdl.load_model(os.path.join( | self.updown_cnt_mdl.load_model(os.path.join( | ||||
| model_dir, "updown_concat_xgb.model")) | model_dir, "updown_concat_xgb.model")) | ||||
| "rag/res/deepdoc") | "rag/res/deepdoc") | ||||
| super().__init__(self.labels, domain, model_dir) | super().__init__(self.labels, domain, model_dir) | ||||
| except Exception as e: | except Exception as e: | ||||
| model_dir = snapshot_download(repo_id="InfiniFlow/deepdoc") | |||||
| model_dir = snapshot_download(repo_id="InfiniFlow/deepdoc", | |||||
| local_dir=os.path.join(get_project_base_directory(), "rag/res/deepdoc"), | |||||
| local_dir_use_symlinks=False) | |||||
| super().__init__(self.labels, domain, model_dir) | super().__init__(self.labels, domain, model_dir) | ||||
| self.garbage_layouts = ["footer", "header", "reference"] | self.garbage_layouts = ["footer", "header", "reference"] |
| self.text_detector = TextDetector(model_dir) | self.text_detector = TextDetector(model_dir) | ||||
| self.text_recognizer = TextRecognizer(model_dir) | self.text_recognizer = TextRecognizer(model_dir) | ||||
| except Exception as e: | except Exception as e: | ||||
| model_dir = snapshot_download(repo_id="InfiniFlow/deepdoc") | |||||
| model_dir = snapshot_download(repo_id="InfiniFlow/deepdoc", | |||||
| local_dir=os.path.join(get_project_base_directory(), "rag/res/deepdoc"), | |||||
| local_dir_use_symlinks=False) | |||||
| self.text_detector = TextDetector(model_dir) | self.text_detector = TextDetector(model_dir) | ||||
| self.text_recognizer = TextRecognizer(model_dir) | self.text_recognizer = TextRecognizer(model_dir) | ||||
| "rag/res/deepdoc") | "rag/res/deepdoc") | ||||
| model_file_path = os.path.join(model_dir, task_name + ".onnx") | model_file_path = os.path.join(model_dir, task_name + ".onnx") | ||||
| if not os.path.exists(model_file_path): | if not os.path.exists(model_file_path): | ||||
| model_dir = snapshot_download(repo_id="InfiniFlow/deepdoc") | |||||
| model_dir = snapshot_download(repo_id="InfiniFlow/deepdoc", | |||||
| local_dir=os.path.join(get_project_base_directory(), "rag/res/deepdoc"), | |||||
| local_dir_use_symlinks=False) | |||||
| model_file_path = os.path.join(model_dir, task_name + ".onnx") | model_file_path = os.path.join(model_dir, task_name + ".onnx") | ||||
| else: | else: | ||||
| model_file_path = os.path.join(model_dir, task_name + ".onnx") | model_file_path = os.path.join(model_dir, task_name + ".onnx") |
| get_project_base_directory(), | get_project_base_directory(), | ||||
| "rag/res/deepdoc")) | "rag/res/deepdoc")) | ||||
| except Exception as e: | except Exception as e: | ||||
| super().__init__(self.labels, "tsr", snapshot_download(repo_id="InfiniFlow/deepdoc")) | |||||
| super().__init__(self.labels, "tsr", snapshot_download(repo_id="InfiniFlow/deepdoc", | |||||
| local_dir=os.path.join(get_project_base_directory(), "rag/res/deepdoc"), | |||||
| local_dir_use_symlinks=False)) | |||||
| def __call__(self, images, thr=0.2): | def __call__(self, images, thr=0.2): | ||||
| tbls = super().__call__(images, thr) | tbls = super().__call__(images, thr) |
| # limitations under the License. | # limitations under the License. | ||||
| # | # | ||||
| from typing import Optional | from typing import Optional | ||||
| from huggingface_hub import snapshot_download | |||||
| from zhipuai import ZhipuAI | from zhipuai import ZhipuAI | ||||
| import os | import os | ||||
| from abc import ABC | from abc import ABC | ||||
| query_instruction_for_retrieval="为这个句子生成表示以用于检索相关文章:", | query_instruction_for_retrieval="为这个句子生成表示以用于检索相关文章:", | ||||
| use_fp16=torch.cuda.is_available()) | use_fp16=torch.cuda.is_available()) | ||||
| except Exception as e: | except Exception as e: | ||||
| flag_model = FlagModel("BAAI/bge-large-zh-v1.5", | |||||
| model_dir = snapshot_download(repo_id="BAAI/bge-large-zh-v1.5", | |||||
| local_dir=os.path.join(get_project_base_directory(), "rag/res/bge-large-zh-v1.5"), | |||||
| local_dir_use_symlinks=False) | |||||
| flag_model = FlagModel(model_dir, | |||||
| query_instruction_for_retrieval="为这个句子生成表示以用于检索相关文章:", | query_instruction_for_retrieval="为这个句子生成表示以用于检索相关文章:", | ||||
| use_fp16=torch.cuda.is_available()) | use_fp16=torch.cuda.is_available()) | ||||