From 4d567d98f4ac9e875a317d17a62abd79ebdc8791 Mon Sep 17 00:00:00 2001 From: hailin Date: Tue, 29 Oct 2024 18:12:55 +0800 Subject: [PATCH] . --- app.py | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/app.py b/app.py index 86e47ee..9035c65 100644 --- a/app.py +++ b/app.py @@ -49,7 +49,7 @@ def store_to_es(key, data: Dict[str, Any], index: str) -> bool: logging.info(f".............保存到ES出错!...............{e}..") #print(e) return False - + def search_es(key: str, index: str) -> Optional[Dict]: # 使用term查询来根据文档的_id搜索 @@ -81,6 +81,14 @@ def load_indices_from_es(key: str, index: str, buf: Dict[str, Any]) -> Any: return None +def reload_buf(ikey, ibuf): + ret = load_indices_from_es(ikey, 'customer', ibuf) + if not ret: + exit("客服AI员工不能拥有数据库。") + + customer_data=buf[key]['customer database'] + app.set_customer_data(customer_data) + def extract_index_structure(es_client, index_name): """ 扫描 Elasticsearch 索引中的一个文档,递归提取字段结构(包括嵌套字段),生成包含所有字段的层级关系和类型信息。 @@ -209,6 +217,8 @@ def calculate_statistics(): @app.route('/customer/') def view_customer(index): + + reload_buf(key, buf) # 判断是否有数据 if not customer_data: return "No customer data provided.", 400 @@ -309,6 +319,7 @@ def search_by_email(): if not email: return "Email address is required.", 400 + reload_buf(key, buf) # 遍历 customer_data 查找匹配的邮件地址 for index, customer in enumerate(customer_data): for domain, info in customer.items(): @@ -328,7 +339,8 @@ def search_by_domain(): domain = request.args.get('domain') if not domain: return "Domain is required.", 400 - + + reload_buf(key, buf) # 遍历 customer_data 查找匹配的域名 for index, customer in enumerate(customer_data): if domain in customer: