Commit 376c0271 by 赵增煜

pyautogui防止故障报错关闭,prompt管理界面

parent b186ed7b
...@@ -315,7 +315,7 @@ class YiyanAi(object): ...@@ -315,7 +315,7 @@ class YiyanAi(object):
time.sleep(1) time.sleep(1)
# 回车发送 # 回车发送
pyautogui.press('enter') pyautogui.press('enter')
pyautogui.FAILSAFE=False
# 监听是否已经停止输出 # 监听是否已经停止输出
try: try:
time.sleep(3) time.sleep(3)
......
...@@ -9,3 +9,4 @@ from .admin_user import User ...@@ -9,3 +9,4 @@ from .admin_user import User
from .admin_user_role import user_role from .admin_user_role import user_role
from .admin_mail import Mail from .admin_mail import Mail
from .ai_file_parser import AiFileParser from .ai_file_parser import AiFileParser
from .ai_prompt import AiPrompt
\ No newline at end of file
...@@ -4,7 +4,7 @@ from applications.extensions import db ...@@ -4,7 +4,7 @@ from applications.extensions import db
class AiFileParser(db.Model): class AiFileParser(db.Model):
__tablename__ = 'ai_file_parser' __tablename__ = 'ai_file_parser'
id = db.Column(db.Integer, primary_key=True) id = db.Column(db.Integer, primary_key=True)
file_path = db.Column(db.String(255), unique=True, nullable=False) file_path = db.Column(db.String(255), nullable=False)
wx_ai_parser = db.Column(db.Text, nullable=False) wx_ai_parser = db.Column(db.Text, nullable=False)
gpt_ai_parser = db.Column(db.Text, nullable=False) gpt_ai_parser = db.Column(db.Text, nullable=False)
kimi_ai_parser = db.Column(db.Text, nullable=False) kimi_ai_parser = db.Column(db.Text, nullable=False)
...@@ -12,7 +12,7 @@ class AiFileParser(db.Model): ...@@ -12,7 +12,7 @@ class AiFileParser(db.Model):
parser_engine = db.Column(db.String(255), nullable=False) parser_engine = db.Column(db.String(255), nullable=False)
prompt_id = db.Column(db.Integer, nullable=False) prompt_id = db.Column(db.Integer, nullable=False)
status = db.Column(db.Integer, nullable=False) status = db.Column(db.Integer, nullable=False)
create_date = db.Column(db.DateTime, default=datetime.datetime.now, onupdate=datetime.datetime.now, comment='更新时间') create_date = db.Column(db.DateTime, default=datetime.datetime.now, onupdate=datetime.datetime.now, comment='创建时间')
def __repr__(self): def __repr__(self):
......
import datetime
from applications.extensions import db
class AiPrompt(db.Model):
__tablename__ = 'ai_prompt'
id = db.Column(db.Integer, primary_key=True)
prompt = db.Column(db.Text, nullable=False)
type = db.Column(db.String(255), nullable=False)
create_date = db.Column(db.DateTime, default=datetime.datetime.now, onupdate=datetime.datetime.now, comment='创建时间')
def __repr__(self):
return '<User %r>' % self.id
def to_dict(self):
return {c.name: getattr(self, c.name) for c in self.__table__.columns}
...@@ -3,8 +3,9 @@ from flask_login import login_required, current_user ...@@ -3,8 +3,9 @@ from flask_login import login_required, current_user
import os, requests, base64, json import os, requests, base64, json
from pathlib import Path from pathlib import Path
from datetime import datetime from datetime import datetime
from applications.models import AiFileParser from applications.models import AiFileParser, AiPrompt
from applications.common.utils.http import table_api, fail_api, success_api from applications.common.utils.http import table_api, fail_api, success_api
from applications.common.utils.validate import str_escape
from applications.extensions import db, flask_mail from applications.extensions import db, flask_mail
bp = Blueprint('parser', __name__, url_prefix='/') bp = Blueprint('parser', __name__, url_prefix='/')
...@@ -20,7 +21,6 @@ def test(): ...@@ -20,7 +21,6 @@ def test():
@bp.get("/ai_index_page") @bp.get("/ai_index_page")
def ai_index_page(): def ai_index_page():
print("123")
return render_template('system/parser/main.html') return render_template('system/parser/main.html')
status_dic = {0:"未解析",2:"解析成功"} status_dic = {0:"未解析",2:"解析成功"}
...@@ -59,8 +59,54 @@ def detail(id): ...@@ -59,8 +59,54 @@ def detail(id):
return render_template('system/parser/detail.html',data=data,pdf_base64=full_base64_string) return render_template('system/parser/detail.html',data=data,pdf_base64=full_base64_string)
# 列表页
@bp.route("/prompt_page")
def prompt_page():
return render_template('system/parser/prompt.html')
@bp.get("/get_prompt")
def get_prompt():
query = db.session.query(AiPrompt).filter().order_by(AiPrompt.id.desc()).layui_paginate()
data = []
for row in query.items:
data.append({
"id":row.id,
"prompt":row.prompt,
"type":row.type,
})
return table_api(data=data,count=query.total)
# 编辑页
@bp.get("/prompt_edit_page")
def prompt_edit_page():
id = request.args.get('id', type=int)
data = {"id":id,"prompt":"","type":""}
if id > 0:
prompt = AiPrompt.query.get(id)
data['type'] = prompt.type
data['prompt'] = prompt.prompt
return render_template('system/parser/prompt_edit.html',data=data)
@bp.post("/prompt_edit")
def prompt_edit():
req_json = request.get_json(force=True)
id = req_json.get("id")
type = str_escape(req_json.get('type'))
prompt = str_escape(req_json.get('prompt'))
if not type or not prompt:
return fail_api(msg="请填写完整")
if int(id) > 0:
db.session.query(AiPrompt).filter(AiPrompt.id == id).update({
"type": type,
"prompt": prompt
})
else:
new_prompt = AiPrompt(type=type, prompt=prompt)
db.session.add(new_prompt)
db.session.commit()
return success_api(msg="成功")
@bp.route("/upload_page") @bp.route("/upload_page")
def upload_page(): def upload_page():
return render_template('system/parser/upload.html') return render_template('system/parser/upload.html')
......
...@@ -23,7 +23,11 @@ ...@@ -23,7 +23,11 @@
<i class="pear-icon pear-icon-add"></i> <i class="pear-icon pear-icon-add"></i>
上传pdf 上传pdf
</button> </button>
<button class="pear-btn pear-btn-primary pear-btn-md" lay-event="prompt_manage">
<i class="pear-icon pear-icon-add"></i>
Prompt管理
</button>
</script> </script>
{# 用户修改操作 #} {# 用户修改操作 #}
<script type="text/html" id="upc-bar"> <script type="text/html" id="upc-bar">
...@@ -98,6 +102,8 @@ ...@@ -98,6 +102,8 @@
table.resize() table.resize()
} else if(obj.event === 'import_pdf'){ } else if(obj.event === 'import_pdf'){
window.import_pdf() window.import_pdf()
} else if(obj.event === 'prompt_manage'){
window.prompt_manage()
} }
}) })
//查询刷新 //查询刷新
...@@ -123,6 +129,13 @@ ...@@ -123,6 +129,13 @@
window.import_pdf = function () { window.import_pdf = function () {
window.open('/upload_page', '_blank'); window.open('/upload_page', '_blank');
} }
window.prompt_manage = function () {
window.open('/prompt_page', '_blank');
}
window.remove = function (obj) { window.remove = function (obj) {
layer.confirm('确定要删除该UPC', {icon: 3, title: '提示'}, function (index) { layer.confirm('确定要删除该UPC', {icon: 3, title: '提示'}, function (index) {
layer.close(index) layer.close(index)
......
<!DOCTYPE html>
<html>
<head>
<title>AI解析管理</title>
{% include 'system/common/header.html' %}
<link rel="stylesheet" href="{{ url_for('static', filename='system/admin/css/other/user.css') }}"/>
</head>
<body class="pear-container">
{# UPC表格 #}
<div class="user-main user-collasped">
<div class="layui-card">
<div class="layui-card-body">
<table id="upc-table" lay-filter="upc-table"></table>
</div>
</div>
</div>
</body>
{# 表格操作 #}
<script type="text/html" id="upc-toolbar">
<button class="pear-btn pear-btn-primary pear-btn-md" lay-event="add">
<i class="pear-icon pear-icon-add"></i>
新增Prompt
</button>
</script>
{# 用户修改操作 #}
<script type="text/html" id="upc-bar">
<button class="pear-btn pear-btn-primary pear-btn-sm" lay-event="edit"><i class="pear-icon pear-icon-edit">编辑</i>
</button>
</script>
{% raw %}
<script type="text/html" id="upc-createDate">
{{layui.util.toDateString(d.create_date, "yyyy-MM-dd HH:mm:ss")}}
</script>
<script type="text/html" id="upc-updateDate">
{{layui.util.toDateString(d.update_date, "yyyy-MM-dd HH:mm:ss")}}
</script>
{% endraw %}
{% include 'system/common/footer.html' %}
<script>
layui.use(['table', 'dtree', 'form', 'jquery', 'popup', 'common'], function () {
let table = layui.table
let form = layui.form
let $ = layui.jquery
let dtree = layui.dtree
let popup = layui.popup
let common = layui.common
let MODULE_PATH = "/get_prompt"
// 表格数据
let cols = [
[
{title: 'id', field: 'id', align: 'center', width: 50},
{title: 'prompt', field: 'prompt', align: 'center', width: 650},
{title: 'type', field: 'type', align: 'center', width: 250},
{title: '操作', toolbar: '#upc-bar', align: 'center'}
]
]
// 渲染表格数据
table.render({
elem: '#upc-table',
url: MODULE_PATH,
page: true,
cols: cols,
skin: 'line',
height: 'full-148',
toolbar: '#upc-toolbar', /*工具栏*/
text: {none: '暂无AI信息'},
defaultToolbar: [{layEvent: 'refresh', icon: 'layui-icon-refresh'}, 'filter', 'print', 'exports'] /*默认工具栏*/
})
table.on('tool(upc-table)', function (obj) {
if (obj.event === 'edit') {
window.edit(obj)
}
})
table.on('toolbar(upc-table)', function (obj) {
if (obj.event === 'add') {
window.add()
} else if (obj.event === 'refresh') {
window.refresh()
} else if (obj.event === 'batchRemove') {
window.batchRemove(obj)
} else if (obj.event === 'collasped') {
$('.user-left').toggleClass('user-collasped')
$('.user-main').toggleClass('user-collasped')
table.resize()
} else if(obj.event === 'import_pdf'){
window.import_pdf()
}
})
//查询刷新
form.on('submit(upc-query)', function (data) {
window.refresh(data.field)
return false
})
window.add = function () {
window.open('/prompt_edit_page?id=0', '_blank');
}
window.edit = function (obj) {
window.open('/prompt_edit_page?id='+ obj.data['id'], '_blank');
}
window.remove = function (obj) {
layer.confirm('确定要删除该UPC', {icon: 3, title: '提示'}, function (index) {
layer.close(index)
let loading = layer.load()
$.ajax({
url: MODULE_PATH + 'remove/' + obj.data['id'],
dataType: 'json',
type: 'delete',
success: function (result) {
layer.close(loading)
if (result.success) {
popup.success(result.msg, function () {
obj.del()
})
} else {
popup.failure(result.msg)
}
}
})
})
}
window.refresh = function (param) {
table.reload('upc-table', {where: param})
}
})
</script>
</html>
\ No newline at end of file
<!DOCTYPE html>
<html>
<head>
<title>pdf上传</title>
{% include 'system/common/header.html' %}</head>
<body>
<form class="layui-form">
<div class="mainBox">
<div class="main-container">
<div class="main-container">
<div class="layui-btn-container">
<label class="layui-form-label">ID</label>
<div class="layui-input-block">
<input type="text" name="id" value="{{data.id}}" readonly lay-verify="required" autocomplete="off" placeholder="id" id="layui-input-id" class="layui-input">
</div>
</div>
</div>
<div class="main-container">
<div class="layui-btn-container">
<label class="layui-form-label">type</label>
<div class="layui-input-block">
<input type="text" name="type" value="{{data.type}}" required lay-verify="required" autocomplete="off" placeholder="type" id="layui-input-type" class="layui-input">
</div>
</div>
</div>
<div class="main-container">
<div class="layui-btn-container">
<label class="layui-form-label">prompt</label>
<div class="layui-input-block">
<textarea name="prompt" placeholder="请输入内容" lay-verify="required" class="layui-textarea">{{data.prompt}}</textarea>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
<div class="bottom">
<div class="button-container">
<button type="submit" class="pear-btn pear-btn-primary pear-btn-sm" lay-submit="" lay-filter="upc-save">
<i class="layui-icon layui-icon-ok"></i>
提交
</button>
<button type="reset" class="pear-btn pear-btn-sm">
<i class="layui-icon layui-icon-refresh"></i>
重置
</button>
</div>
</div>
</form>
{% include 'system/common/footer.html' %}
<script>
layui.use(['layer', 'form', 'jquery','upload','popup','element', 'laydate'], function () {
let form = layui.form;
let $ = layui.jquery;
let upload = layui.upload;
let popup = layui.popup;
let element = layui.element;
let layer = layui.layer;
let laydate = layui.laydate;
let date = '';
laydate.render({
elem: '#layui-input-date'
});
//此处暂未调通
form.on('submit(upc-save)', function (data) {
$.ajax({
url: '/prompt_edit',
data: JSON.stringify(data.field),
dataType: 'json',
contentType: 'application/json',
type: 'post',
success: function (result) {
if (result.success) {
layer.msg(result.msg, { icon: 1, time: 1000 }, function () {
})
} else {
layer.msg(result.msg, { icon: 2, time: 1000 })
}
}
})
return false
})
})
</script>
</body>
</html>
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment