5 Commits 08b3fe7a98 ... 1f28c6e2bd

Author SHA1 Message Date
  dujunlong 1f28c6e2bd 移除已提交的 .pyc 文件 2 months ago
  dujunlong 27dfd409ea 封装响应类 2 months ago
  dujunlong 0571937a23 Merge branch 'master' of http://120.24.5.168:8050/dujunlong/bjqa 2 months ago
  dujunlong 44dd6c44b3 update .gitignore 2 months ago
  dujunlong 156f0e5705 ... 2 months ago

+ 38 - 0
final/ByLLM/app.spec

@@ -0,0 +1,38 @@
+# -*- mode: python ; coding: utf-8 -*-
+
+
+a = Analysis(
+    ['app.py'],
+    pathex=[],
+    binaries=[],
+    datas=[('../Json/json_data', 'Json/json_data'), ('../Json/json_Schema', 'Json/json_Schema'), ('../Json/sjgxys', 'Json/sjgxys'), ('templatesJson', 'templatesJson')],
+    hiddenimports=[],
+    hookspath=[],
+    hooksconfig={},
+    runtime_hooks=[],
+    excludes=[],
+    noarchive=False,
+    optimize=0,
+)
+pyz = PYZ(a.pure)
+
+exe = EXE(
+    pyz,
+    a.scripts,
+    a.binaries,
+    a.datas,
+    [],
+    name='app',
+    debug=False,
+    bootloader_ignore_signals=False,
+    strip=False,
+    upx=True,
+    upx_exclude=[],
+    runtime_tmpdir=None,
+    console=True,
+    disable_windowed_traceback=False,
+    argv_emulation=False,
+    target_arch=None,
+    codesign_identity=None,
+    entitlements_file=None,
+)

BIN
final/ByRules/__pycache__/commonUtil.cpython-38.pyc


BIN
final/ByRules/__pycache__/commonUtil.cpython-39.pyc


BIN
final/ByRules/__pycache__/similarity_answer_json.cpython-39.pyc


BIN
final/ByRules/__pycache__/util.cpython-38.pyc


BIN
final/ByRules/__pycache__/util.cpython-39.pyc


+ 18 - 9
final/ByRules/app.py

@@ -3,6 +3,7 @@ import sys
 from flask import Flask, request, jsonify
 
 from commonUtil import fill_template, fill_template_auto
+from responseUtil import *
 from similarity_answer_json import *
 from util import *
 import os
@@ -40,8 +41,9 @@ def process_query_route():
     data = request.get_json()
     query = data.get("query")
     if not query:
-        return jsonify({"error": "Query cannot be empty"}), 400
-
+        # return jsonify({"error": "Query cannot be empty"}), 400
+        # return jsonify({"error": "Query cannot be empty"}), 400
+        return jsonify(error_response("Query cannot be empty"))
     try:
         result = process_query(query, template_dict, TEMPLATE_FOLDER)
 
@@ -55,7 +57,8 @@ def process_query_route():
                 "name": result["name"],
                 "play": result["play"]
             }
-            return jsonify(response)
+            # return jsonify(response)
+            return jsonify(success_response(data=response))
         #  查询类问题:
         if result['type'] == 'query':
             if result["flag"]:
@@ -75,7 +78,8 @@ def process_query_route():
                 "play": result["play"],
                 "unit": result["unit"],
             }
-            return jsonify(response)
+            # return jsonify(response)
+            return jsonify(success_response(data=response))
         # 计算类问题
         elif result['type'] == 'calculate':
             conditions = result["conditions"]
@@ -95,7 +99,8 @@ def process_query_route():
                 "play": result["play"],
                 "unit": result["unit"],
             }
-            return jsonify(response)
+            # return jsonify(response)
+            return jsonify(success_response(data=response))
         # 最值类问题
         elif result['type'] == 'compare_max_min':
             find_max = str(result['find_max']).lower() == 'true'
@@ -117,7 +122,8 @@ def process_query_route():
                 "play": result["play"],
                 "unit": result["unit"],
             }
-            return jsonify(response)
+            # return jsonify(response)
+            return jsonify(success_response(data=response))
         # TopN
         elif result['type'] == 'topN':
             topN = result["conditions"]['rank']
@@ -143,7 +149,8 @@ def process_query_route():
                 "play": result["play"],
                 "unit": result["unit"],
             }
-            return jsonify(response)
+            # return jsonify(response)
+            return jsonify(success_response(data=response))
         # TopN
         elif result['type'] == 'rank':
             rank = result["conditions"]['rank2']
@@ -174,9 +181,11 @@ def process_query_route():
                 "qcode": result["qcode"],
                 "unit": result["unit"],
             }
-            return jsonify(response)
+            # return jsonify(response)
+            return jsonify(success_response(data=response))
     except Exception as e:
-        return jsonify({"error": str(e)}), 500
+        # return jsonify({"error": str(e)}), 500
+        return jsonify(error_response(data=str(e)))
 
 
 if __name__ == "__main__":

+ 21 - 0
final/ByRules/responseUtil.py

@@ -0,0 +1,21 @@
+# 通用返回函数
+def make_response(data, code, msg,):
+    return {
+        "code": code,
+        "msg": msg,
+        "data": data
+    }
+# 成功返回函数
+def success_response(data=None, code=200, msg="success"):
+    return {
+        "code": code,
+        "msg": msg,
+        "data": data
+    }
+# 失败返回函数
+def error_response(data=None, code=500, msg="error"):
+    return {
+        "code": code,
+        "msg": msg,
+        "data": data
+    }

+ 2 - 1
final/ByRules/similarity_answer_json.py

@@ -469,7 +469,8 @@ def process_query(query, template_dict, json_folder, tokenizer=jieba_tokenizer):
             "similarity_score": best_score,
             "content": "您提问的问题目前我还没有掌握",
             "query": query,
-            "play": "疑问"
+            "play": "疑问",
+            "name": "疑问"
         }
 
     if (best_score - second_score) < diff_threshold: