|
@@ -1,16 +1,33 @@
|
|
|
-from flask import Flask,render_template, request, jsonify
|
|
|
+from flask import Flask, render_template, request, jsonify
|
|
|
+import psycopg2
|
|
|
+from psycopg2.extras import DictCursor
|
|
|
+import logging
|
|
|
import ollama
|
|
|
import json
|
|
|
|
|
|
app = Flask(__name__)
|
|
|
|
|
|
+
|
|
|
+# 配置日志
|
|
|
+logging.basicConfig(level=logging.INFO)
|
|
|
+logger = logging.getLogger(__name__)
|
|
|
+
|
|
|
+# 连接数据库
|
|
|
+conn = psycopg2.connect(
|
|
|
+ dbname="real3d",
|
|
|
+ user="postgres",
|
|
|
+ password="postgis",
|
|
|
+ host="192.168.100.30",
|
|
|
+ port="5432"
|
|
|
+)
|
|
|
+
|
|
|
+
|
|
|
# 后台接口
|
|
|
@app.route("/")
|
|
|
def home():
|
|
|
return render_template('index.html')
|
|
|
|
|
|
# 接收消息,大模型解析
|
|
|
-
|
|
|
@app.route('/msg', methods=['POST'])
|
|
|
def inputMsg():
|
|
|
# 从请求中获取JSON数据
|
|
@@ -23,7 +40,7 @@ def inputMsg():
|
|
|
# 打印接收到的消息
|
|
|
print(data['msg'])
|
|
|
|
|
|
- msg=data['msg']
|
|
|
+ msg = data['msg']
|
|
|
# 调用大模型解析
|
|
|
# 这里调用大模型,并返回解析结果
|
|
|
# 生成提示信息
|
|
@@ -52,10 +69,21 @@ def inputMsg():
|
|
|
json_res = res["response"]
|
|
|
json_res = json.loads(json_res)
|
|
|
|
|
|
-
|
|
|
# 返回响应
|
|
|
return jsonify(json_res)
|
|
|
|
|
|
|
|
|
-if __name__ == '__main__':
|
|
|
- app.run()
|
|
|
+def getFactorByName(name):
|
|
|
+ with conn.cursor(cursor_factory=DictCursor) as cur:
|
|
|
+ sql = "SELECT id,bsm FROM base.t_fzss_fzxz_factor WHERE name = %s"
|
|
|
+ complete_sql = cur.mogrify(sql, (name,)).decode('utf-8')
|
|
|
+ logger.info(f"Executing SQL: {complete_sql}")
|
|
|
+ cur.execute(sql, (name,))
|
|
|
+ # res = cur.fetchall()
|
|
|
+ res = cur.fetchone()
|
|
|
+ id=str(res['id'])
|
|
|
+ return res
|
|
|
+
|
|
|
+getFactorByName("幼儿园服务半径")
|
|
|
+# if __name__ == '__main__':
|
|
|
+# app.run()
|