代码重构,删除无用文件
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
from flask import Flask
|
||||
from flask_sqlalchemy import SQLAlchemy
|
||||
from flask_migrate import Migrate
|
||||
from config import Config
|
||||
from src.flask_prompt_master.config import Config
|
||||
import os
|
||||
from flask_cors import CORS
|
||||
|
||||
@@ -24,7 +24,7 @@ def create_app(config_class=Config):
|
||||
migrate.init_app(app, db)
|
||||
|
||||
# 注册蓝图
|
||||
from flask_prompt_master.routes import main_bp
|
||||
from src.flask_prompt_master.routes import main_bp
|
||||
app.register_blueprint(main_bp)
|
||||
|
||||
return app
|
||||
23
src/flask_prompt_master/config.py
Normal file
23
src/flask_prompt_master/config.py
Normal file
@@ -0,0 +1,23 @@
|
||||
import os
|
||||
from dotenv import load_dotenv
|
||||
|
||||
# 在配置类定义前加载环境变量
|
||||
load_dotenv()
|
||||
|
||||
class Config:
|
||||
SECRET_KEY = os.environ.get('SECRET_KEY') or 'dev-key'
|
||||
|
||||
# MySQL数据库配置
|
||||
SQLALCHEMY_DATABASE_URI = 'mysql+pymysql://root:123456@localhost:3306/pro_db?charset=utf8mb4'
|
||||
SQLALCHEMY_TRACK_MODIFICATIONS = False
|
||||
|
||||
# OpenAI兼容API配置
|
||||
LLM_API_URL = os.environ.get('LLM_API_URL') or 'https://api.deepseek.com/v1'
|
||||
LLM_API_KEY = os.environ.get('LLM_API_KEY') or 'sk-fdf7cc1c73504e628ec0119b7e11b8cc'
|
||||
|
||||
# 微信小程序配置
|
||||
WX_APPID = os.environ.get('WX_APPID') or 'wx2c65877d37fc29bf' # 替换为你的小程序 appid
|
||||
WX_SECRET = os.environ.get('WX_SECRET') or '89aa97dda3c1347c6ae3d6ab4627f1f4' # 替换为你的小程序 secret
|
||||
|
||||
# 添加跨域支持
|
||||
CORS_ORIGINS = ['*'] # 生产环境建议设置具体域名
|
||||
8
src/flask_prompt_master/forms/__init__.py
Normal file
8
src/flask_prompt_master/forms/__init__.py
Normal file
@@ -0,0 +1,8 @@
|
||||
"""
|
||||
表单包
|
||||
包含所有表单定义
|
||||
"""
|
||||
|
||||
from .forms import *
|
||||
|
||||
__all__ = ['LoginForm', 'RegisterForm', 'PromptForm']
|
||||
8
src/flask_prompt_master/models/__init__.py
Normal file
8
src/flask_prompt_master/models/__init__.py
Normal file
@@ -0,0 +1,8 @@
|
||||
"""
|
||||
数据模型包
|
||||
包含所有数据库模型定义
|
||||
"""
|
||||
|
||||
from .models import *
|
||||
|
||||
__all__ = ['User', 'Prompt', 'Feedback']
|
||||
@@ -1,4 +1,4 @@
|
||||
from flask_prompt_master import db
|
||||
from src.flask_prompt_master import db
|
||||
from datetime import datetime
|
||||
|
||||
class User(db.Model):
|
||||
|
||||
3699
src/flask_prompt_master/promptsTemplates.py
Normal file
3699
src/flask_prompt_master/promptsTemplates.py
Normal file
File diff suppressed because it is too large
Load Diff
8
src/flask_prompt_master/routes/__init__.py
Normal file
8
src/flask_prompt_master/routes/__init__.py
Normal file
@@ -0,0 +1,8 @@
|
||||
"""
|
||||
路由包
|
||||
包含所有应用路由定义
|
||||
"""
|
||||
|
||||
from .routes import *
|
||||
|
||||
__all__ = ['main', 'auth', 'prompts']
|
||||
36
src/flask_prompt_master/routes/prompts.py
Normal file
36
src/flask_prompt_master/routes/prompts.py
Normal file
@@ -0,0 +1,36 @@
|
||||
from flask import Blueprint, render_template, request
|
||||
from flask_prompt_master.templates.prompts import TEMPLATE_CATEGORIES
|
||||
from flask_prompt_master.models import PromptTemplate
|
||||
|
||||
bp = Blueprint('prompts', __name__)
|
||||
|
||||
ITEMS_PER_PAGE = 9 # 每页显示的模板数量
|
||||
|
||||
@bp.route('/prompts')
|
||||
def list():
|
||||
page = request.args.get('page', 1, type=int)
|
||||
category = request.args.get('category', '全部')
|
||||
|
||||
# 获取模板数据
|
||||
query = PromptTemplate.query
|
||||
|
||||
if category != '全部':
|
||||
query = query.filter_by(category=category)
|
||||
|
||||
# 分页
|
||||
pagination = query.paginate(
|
||||
page=page,
|
||||
per_page=ITEMS_PER_PAGE,
|
||||
error_out=False
|
||||
)
|
||||
|
||||
templates = pagination.items
|
||||
|
||||
return render_template('prompt_list.html',
|
||||
templates=templates,
|
||||
categories=TEMPLATE_CATEGORIES,
|
||||
current_category=category,
|
||||
page=page,
|
||||
has_next=pagination.has_next,
|
||||
total_pages=pagination.pages
|
||||
)
|
||||
@@ -1,9 +1,9 @@
|
||||
from flask import Blueprint, render_template, request, redirect, url_for, flash, jsonify, current_app
|
||||
from openai import OpenAI
|
||||
from flask_prompt_master import db
|
||||
from flask_prompt_master.models import User, Prompt, Feedback, PromptTemplate, WxUser
|
||||
from flask_prompt_master.forms import PromptForm, FeedbackForm
|
||||
from config import Config
|
||||
from src.flask_prompt_master import db
|
||||
from src.flask_prompt_master.models import User, Prompt, Feedback, PromptTemplate, WxUser
|
||||
from src.flask_prompt_master.forms import PromptForm, FeedbackForm
|
||||
from src.flask_prompt_master.config import Config
|
||||
import pymysql
|
||||
from datetime import datetime
|
||||
import requests
|
||||
|
||||
10
src/flask_prompt_master/services/__init__.py
Normal file
10
src/flask_prompt_master/services/__init__.py
Normal file
@@ -0,0 +1,10 @@
|
||||
"""
|
||||
业务逻辑包
|
||||
包含所有业务逻辑服务
|
||||
"""
|
||||
|
||||
# 这里将导入具体的服务类
|
||||
# from .prompt_service import PromptService
|
||||
# from .user_service import UserService
|
||||
|
||||
__all__ = []
|
||||
90
src/flask_prompt_master/static/css/chat.css
Normal file
90
src/flask_prompt_master/static/css/chat.css
Normal file
@@ -0,0 +1,90 @@
|
||||
.chat-container {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
height: 80vh;
|
||||
max-width: 600px;
|
||||
margin: 0 auto;
|
||||
border: 1px solid #ccc;
|
||||
border-radius: 8px;
|
||||
overflow: hidden;
|
||||
}
|
||||
|
||||
.chat-sidebar {
|
||||
width: 260px;
|
||||
border-right: 1px solid #e5e7eb;
|
||||
padding: 1rem;
|
||||
}
|
||||
|
||||
.new-chat-btn {
|
||||
width: 100%;
|
||||
padding: 0.75rem;
|
||||
background: #2563eb;
|
||||
color: white;
|
||||
border: none;
|
||||
border-radius: 0.5rem;
|
||||
cursor: pointer;
|
||||
}
|
||||
|
||||
.chat-main {
|
||||
flex: 1;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
}
|
||||
|
||||
.chat-messages {
|
||||
flex: 1;
|
||||
padding: 10px;
|
||||
overflow-y: auto;
|
||||
background-color: #f9f9f9;
|
||||
}
|
||||
|
||||
.message {
|
||||
margin: 10px 0;
|
||||
padding: 10px;
|
||||
border-radius: 5px;
|
||||
max-width: 70%;
|
||||
}
|
||||
|
||||
.user-message {
|
||||
background-color: #e3f2fd;
|
||||
margin-left: auto;
|
||||
}
|
||||
|
||||
.ai-message {
|
||||
background-color: #f5f5f5;
|
||||
margin-right: auto;
|
||||
}
|
||||
|
||||
.system-message {
|
||||
background-color: #ffebee;
|
||||
margin: 10px auto;
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
.chat-input {
|
||||
display: flex;
|
||||
padding: 10px;
|
||||
border-top: 1px solid #ccc;
|
||||
background-color: #fff;
|
||||
}
|
||||
|
||||
#messageInput {
|
||||
flex: 1;
|
||||
padding: 10px;
|
||||
border: 1px solid #ccc;
|
||||
border-radius: 5px;
|
||||
}
|
||||
|
||||
#sendButton {
|
||||
padding: 10px 20px;
|
||||
margin-left: 10px;
|
||||
background-color: #2196f3;
|
||||
color: white;
|
||||
border: none;
|
||||
border-radius: 5px;
|
||||
cursor: pointer;
|
||||
}
|
||||
|
||||
#sendButton:hover {
|
||||
background-color: #1976d2;
|
||||
}
|
||||
91
src/flask_prompt_master/static/css/style.css
Normal file
91
src/flask_prompt_master/static/css/style.css
Normal file
@@ -0,0 +1,91 @@
|
||||
/* 基础样式 */
|
||||
body {
|
||||
font-family: 'Segoe UI', sans-serif;
|
||||
line-height: 1.6;
|
||||
margin: 0;
|
||||
padding: 0;
|
||||
color: #333;
|
||||
background-color: #f5f5f5;
|
||||
}
|
||||
|
||||
/* 布局 */
|
||||
.container {
|
||||
max-width: 1200px;
|
||||
margin: 0 auto;
|
||||
padding: 20px;
|
||||
}
|
||||
|
||||
/* 导航栏 */
|
||||
nav {
|
||||
background-color: #2c3e50;
|
||||
padding: 1rem;
|
||||
margin-bottom: 2rem;
|
||||
}
|
||||
|
||||
nav a {
|
||||
color: white;
|
||||
text-decoration: none;
|
||||
margin-right: 1rem;
|
||||
}
|
||||
|
||||
nav a:hover {
|
||||
text-decoration: underline;
|
||||
}
|
||||
|
||||
/* 表单样式 */
|
||||
.form-group {
|
||||
margin-bottom: 1rem;
|
||||
}
|
||||
|
||||
.form-control {
|
||||
width: 100%;
|
||||
padding: 0.5rem;
|
||||
border: 1px solid #ddd;
|
||||
border-radius: 4px;
|
||||
}
|
||||
|
||||
.btn {
|
||||
padding: 0.5rem 1rem;
|
||||
border: none;
|
||||
border-radius: 4px;
|
||||
cursor: pointer;
|
||||
}
|
||||
|
||||
.btn-primary {
|
||||
background-color: #3498db;
|
||||
color: white;
|
||||
}
|
||||
|
||||
.btn-primary:hover {
|
||||
background-color: #2980b9;
|
||||
}
|
||||
|
||||
/* 提示词卡片 */
|
||||
.prompt-card {
|
||||
background: white;
|
||||
padding: 2rem;
|
||||
border-radius: 8px;
|
||||
box-shadow: 0 2px 4px rgba(0,0,0,0.1);
|
||||
margin-bottom: 2rem;
|
||||
}
|
||||
|
||||
.prompt-input, .prompt-output {
|
||||
margin-bottom: 1.5rem;
|
||||
}
|
||||
|
||||
/* 错误提示 */
|
||||
.error {
|
||||
color: #e74c3c;
|
||||
font-size: 0.9rem;
|
||||
}
|
||||
|
||||
/* 响应式设计 */
|
||||
@media (max-width: 768px) {
|
||||
.container {
|
||||
padding: 10px;
|
||||
}
|
||||
|
||||
.prompt-card {
|
||||
padding: 1rem;
|
||||
}
|
||||
}
|
||||
34
src/flask_prompt_master/static/js/main.js
Normal file
34
src/flask_prompt_master/static/js/main.js
Normal file
@@ -0,0 +1,34 @@
|
||||
// 初始化函数
|
||||
document.addEventListener('DOMContentLoaded', function() {
|
||||
// 处理表单提交
|
||||
const forms = document.querySelectorAll('form');
|
||||
forms.forEach(form => {
|
||||
form.addEventListener('submit', function(e) {
|
||||
const submitBtn = form.querySelector('button[type="submit"]');
|
||||
if (submitBtn) {
|
||||
submitBtn.disabled = true;
|
||||
submitBtn.textContent = '处理中...';
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
// 处理提示词卡片交互
|
||||
const promptCards = document.querySelectorAll('.prompt-card');
|
||||
promptCards.forEach(card => {
|
||||
card.addEventListener('click', function(e) {
|
||||
if (e.target.classList.contains('btn-feedback')) {
|
||||
// 处理反馈按钮点击
|
||||
console.log('反馈按钮被点击');
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
// 处理闪存消息
|
||||
const flashMessages = document.querySelectorAll('.flash-message');
|
||||
flashMessages.forEach(message => {
|
||||
setTimeout(() => {
|
||||
message.style.opacity = '0';
|
||||
setTimeout(() => message.remove(), 500);
|
||||
}, 5000);
|
||||
});
|
||||
});
|
||||
1
src/flask_prompt_master/templates/__init__.py
Normal file
1
src/flask_prompt_master/templates/__init__.py
Normal file
@@ -0,0 +1 @@
|
||||
from .prompts import templates
|
||||
165
src/flask_prompt_master/templates/base.html
Normal file
165
src/flask_prompt_master/templates/base.html
Normal file
@@ -0,0 +1,165 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="zh-CN">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<title>提示词大师 - {% block title %}{% endblock %}</title>
|
||||
<!-- 添加 Google Fonts -->
|
||||
<link rel="preconnect" href="https://fonts.googleapis.com">
|
||||
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
|
||||
<link href="https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600&display=swap" rel="stylesheet">
|
||||
<!-- Font Awesome -->
|
||||
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.15.4/css/all.min.css">
|
||||
<style>
|
||||
/* 全局样式 */
|
||||
:root {
|
||||
--primary-color: #2196f3;
|
||||
--primary-dark: #1976d2;
|
||||
--secondary-color: #6c757d;
|
||||
--success-color: #28a745;
|
||||
--background-color: #f8f9fa;
|
||||
--border-color: #e0e0e0;
|
||||
--text-color: #2c3e50;
|
||||
--text-light: #666;
|
||||
}
|
||||
|
||||
* {
|
||||
margin: 0;
|
||||
padding: 0;
|
||||
box-sizing: border-box;
|
||||
}
|
||||
|
||||
body {
|
||||
font-family: 'Inter', -apple-system, BlinkMacSystemFont, system-ui, sans-serif;
|
||||
line-height: 1.5;
|
||||
color: var(--text-color);
|
||||
background-color: var(--background-color);
|
||||
}
|
||||
|
||||
/* 导航栏样式 */
|
||||
header {
|
||||
background: white;
|
||||
box-shadow: 0 2px 4px rgba(0,0,0,0.1);
|
||||
position: sticky;
|
||||
top: 0;
|
||||
z-index: 100;
|
||||
}
|
||||
|
||||
nav {
|
||||
max-width: 1200px;
|
||||
margin: 0 auto;
|
||||
padding: 1rem;
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
align-items: center;
|
||||
}
|
||||
|
||||
.nav-brand {
|
||||
font-size: 1.25rem;
|
||||
font-weight: 600;
|
||||
color: var(--primary-color);
|
||||
text-decoration: none;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 0.5rem;
|
||||
}
|
||||
|
||||
.nav-brand i {
|
||||
font-size: 1.5rem;
|
||||
}
|
||||
|
||||
/* 主要内容区域 */
|
||||
main {
|
||||
min-height: calc(100vh - 120px);
|
||||
}
|
||||
|
||||
/* 闪现消息样式 */
|
||||
.flash-messages {
|
||||
position: fixed;
|
||||
top: 1rem;
|
||||
right: 1rem;
|
||||
z-index: 1000;
|
||||
}
|
||||
|
||||
.flash-message {
|
||||
background: white;
|
||||
padding: 1rem;
|
||||
border-radius: 8px;
|
||||
box-shadow: 0 2px 4px rgba(0,0,0,0.1);
|
||||
margin-bottom: 0.5rem;
|
||||
animation: slideIn 0.3s ease-out;
|
||||
}
|
||||
|
||||
@keyframes slideIn {
|
||||
from {
|
||||
transform: translateX(100%);
|
||||
opacity: 0;
|
||||
}
|
||||
to {
|
||||
transform: translateX(0);
|
||||
opacity: 1;
|
||||
}
|
||||
}
|
||||
|
||||
/* 页脚样式 */
|
||||
footer {
|
||||
background: white;
|
||||
padding: 2rem 1rem;
|
||||
text-align: center;
|
||||
color: var(--text-light);
|
||||
margin-top: 3rem;
|
||||
}
|
||||
|
||||
/* 响应式设计 */
|
||||
@media (max-width: 768px) {
|
||||
nav {
|
||||
padding: 1rem;
|
||||
}
|
||||
}
|
||||
</style>
|
||||
{% block extra_css %}{% endblock %}
|
||||
</head>
|
||||
<body>
|
||||
<header>
|
||||
<nav>
|
||||
<a href="{{ url_for('main.index') }}" class="nav-brand">
|
||||
<i class="fas fa-magic"></i>
|
||||
提示词大师
|
||||
</a>
|
||||
</nav>
|
||||
</header>
|
||||
|
||||
<main>
|
||||
{% with messages = get_flashed_messages() %}
|
||||
{% if messages %}
|
||||
<div class="flash-messages">
|
||||
{% for message in messages %}
|
||||
<div class="flash-message">{{ message }}</div>
|
||||
{% endfor %}
|
||||
</div>
|
||||
{% endif %}
|
||||
{% endwith %}
|
||||
|
||||
{% block content %}{% endblock %}
|
||||
</main>
|
||||
|
||||
<footer>
|
||||
<p>© 2025 提示词大师 - 让AI更好地理解您的需求</p>
|
||||
</footer>
|
||||
|
||||
{% block extra_js %}{% endblock %}
|
||||
<script>
|
||||
// 自动隐藏闪现消息
|
||||
document.addEventListener('DOMContentLoaded', function() {
|
||||
const messages = document.querySelectorAll('.flash-message');
|
||||
messages.forEach(message => {
|
||||
setTimeout(() => {
|
||||
message.style.opacity = '0';
|
||||
message.style.transform = 'translateX(100%)';
|
||||
setTimeout(() => message.remove(), 300);
|
||||
}, 3000);
|
||||
});
|
||||
});
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
250
src/flask_prompt_master/templates/expert_generate.html
Normal file
250
src/flask_prompt_master/templates/expert_generate.html
Normal file
@@ -0,0 +1,250 @@
|
||||
{% extends "base.html" %}
|
||||
|
||||
{% block content %}
|
||||
<div class="container mt-4">
|
||||
<div class="row">
|
||||
<div class="col-md-8 offset-md-2">
|
||||
<div class="d-flex justify-content-between align-items-center mb-4">
|
||||
<h2>专家提示词生成器</h2>
|
||||
<a href="{{ url_for('main.index') }}" class="btn btn-outline-primary">
|
||||
<i class="fas fa-arrow-left"></i> 返回基础模式
|
||||
</a>
|
||||
</div>
|
||||
|
||||
<div class="card">
|
||||
<div class="card-body">
|
||||
<form id="expertPromptForm">
|
||||
<div class="mb-3">
|
||||
<label for="input_text" class="form-label">请描述您的需求</label>
|
||||
<textarea class="form-control" id="input_text" name="input_text" rows="4" required></textarea>
|
||||
<div class="form-text">详细描述您的需求,系统将进行专业分析并生成高质量提示词</div>
|
||||
</div>
|
||||
<button type="submit" class="btn btn-primary" id="generateBtn">
|
||||
<i class="fas fa-magic"></i> 生成专家提示词
|
||||
</button>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div id="loadingIndicator" class="text-center mt-4 d-none">
|
||||
<div class="spinner-border text-primary" role="status">
|
||||
<span class="visually-hidden">生成中...</span>
|
||||
</div>
|
||||
<p class="mt-2">正在分析需求并生成专业提示词...</p>
|
||||
</div>
|
||||
|
||||
<div id="resultCard" class="card mt-4 d-none">
|
||||
<div class="card-body">
|
||||
<h5 class="card-title mb-4">生成结果</h5>
|
||||
|
||||
<div class="mb-4">
|
||||
<h6 class="mb-3">需求分析</h6>
|
||||
<div id="intentAnalysis" class="border rounded p-3 bg-light">
|
||||
<div class="row">
|
||||
<div class="col-md-6">
|
||||
<p><strong>核心意图:</strong><span id="coreIntent"></span></p>
|
||||
<p><strong>专业领域:</strong><span id="domain"></span></p>
|
||||
</div>
|
||||
<div class="col-md-6">
|
||||
<p><strong>预期输出:</strong><span id="expectedOutput"></span></p>
|
||||
</div>
|
||||
</div>
|
||||
<div class="mt-2">
|
||||
<p><strong>关键需求:</strong></p>
|
||||
<ul id="keyRequirements" class="mb-0"></ul>
|
||||
</div>
|
||||
<div class="mt-2">
|
||||
<p><strong>约束条件:</strong></p>
|
||||
<ul id="constraints" class="mb-0"></ul>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div>
|
||||
<h6 class="mb-3">生成的专家提示词</h6>
|
||||
<div id="generatedPrompt" class="border rounded p-3"></div>
|
||||
<div class="mt-3">
|
||||
<button class="btn btn-sm btn-primary copy-btn" data-target="generatedPrompt">
|
||||
<i class="fas fa-copy"></i> 复制提示词
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{% block scripts %}
|
||||
<script>
|
||||
document.getElementById('expertPromptForm').addEventListener('submit', async function(e) {
|
||||
e.preventDefault();
|
||||
|
||||
const input_text = document.getElementById('input_text').value;
|
||||
const loadingIndicator = document.getElementById('loadingIndicator');
|
||||
const resultCard = document.getElementById('resultCard');
|
||||
const generateBtn = document.getElementById('generateBtn');
|
||||
|
||||
// 显示加载指示器
|
||||
loadingIndicator.classList.remove('d-none');
|
||||
generateBtn.disabled = true;
|
||||
resultCard.classList.add('d-none');
|
||||
|
||||
try {
|
||||
const response = await fetch('/api/wx/generate/expert', {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
},
|
||||
body: JSON.stringify({
|
||||
input_text: input_text,
|
||||
uid: '12345' // 这里应该使用实际的用户ID
|
||||
})
|
||||
});
|
||||
|
||||
const data = await response.json();
|
||||
|
||||
if (data.code === 200) {
|
||||
// 更新意图分析结果
|
||||
document.getElementById('coreIntent').textContent = data.data.intent_analysis.core_intent;
|
||||
document.getElementById('domain').textContent = data.data.intent_analysis.domain;
|
||||
document.getElementById('expectedOutput').textContent = data.data.intent_analysis.expected_output;
|
||||
|
||||
// 更新关键需求列表
|
||||
const keyRequirementsList = document.getElementById('keyRequirements');
|
||||
keyRequirementsList.innerHTML = data.data.intent_analysis.key_requirements
|
||||
.map(req => `<li>${req}</li>`).join('');
|
||||
|
||||
// 更新约束条件列表
|
||||
const constraintsList = document.getElementById('constraints');
|
||||
constraintsList.innerHTML = data.data.intent_analysis.constraints
|
||||
.map(constraint => `<li>${constraint}</li>`).join('');
|
||||
|
||||
// 更新生成的提示词
|
||||
document.getElementById('generatedPrompt').textContent = data.data.generated_prompt;
|
||||
|
||||
// 显示结果卡片
|
||||
resultCard.classList.remove('d-none');
|
||||
} else {
|
||||
alert('生成失败:' + data.message);
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('Error:', error);
|
||||
alert('请求失败,请稍后重试');
|
||||
} finally {
|
||||
// 隐藏加载指示器并启用按钮
|
||||
loadingIndicator.classList.add('d-none');
|
||||
generateBtn.disabled = false;
|
||||
}
|
||||
});
|
||||
|
||||
// 改进的复制功能实现
|
||||
function copyToClipboard(text) {
|
||||
// 创建临时文本区域
|
||||
const textArea = document.createElement('textarea');
|
||||
textArea.value = text;
|
||||
document.body.appendChild(textArea);
|
||||
|
||||
try {
|
||||
// 选择文本
|
||||
textArea.select();
|
||||
textArea.setSelectionRange(0, 99999); // 对于移动设备
|
||||
|
||||
// 尝试使用新的 API
|
||||
if (navigator.clipboard && window.isSecureContext) {
|
||||
// 对于现代浏览器
|
||||
navigator.clipboard.writeText(text).then(() => {
|
||||
showCopySuccess();
|
||||
}).catch(err => {
|
||||
console.error('复制失败:', err);
|
||||
// 回退到传统方法
|
||||
document.execCommand('copy');
|
||||
showCopySuccess();
|
||||
});
|
||||
} else {
|
||||
// 对于不支持 Clipboard API 的浏览器
|
||||
const successful = document.execCommand('copy');
|
||||
if (successful) {
|
||||
showCopySuccess();
|
||||
} else {
|
||||
console.error('复制失败');
|
||||
}
|
||||
}
|
||||
} catch (err) {
|
||||
console.error('复制出错:', err);
|
||||
} finally {
|
||||
// 清理临时元素
|
||||
document.body.removeChild(textArea);
|
||||
}
|
||||
}
|
||||
|
||||
// 显示复制成功的反馈
|
||||
function showCopySuccess() {
|
||||
const copyBtn = document.querySelector('.copy-btn');
|
||||
const originalHtml = copyBtn.innerHTML;
|
||||
copyBtn.innerHTML = '<i class="fas fa-check"></i> 已复制';
|
||||
copyBtn.classList.add('copied');
|
||||
|
||||
setTimeout(() => {
|
||||
copyBtn.innerHTML = originalHtml;
|
||||
copyBtn.classList.remove('copied');
|
||||
}, 2000);
|
||||
}
|
||||
|
||||
// 绑定复制按钮点击事件
|
||||
document.addEventListener('DOMContentLoaded', function() {
|
||||
const copyBtn = document.querySelector('.copy-btn');
|
||||
copyBtn.addEventListener('click', function() {
|
||||
const targetId = this.dataset.target;
|
||||
const text = document.getElementById(targetId).textContent;
|
||||
copyToClipboard(text);
|
||||
});
|
||||
});
|
||||
</script>
|
||||
|
||||
<style>
|
||||
/* 添加复制按钮样式 */
|
||||
.copy-btn {
|
||||
padding: 8px 16px;
|
||||
background-color: #4a90e2;
|
||||
color: white;
|
||||
border: none;
|
||||
border-radius: 4px;
|
||||
cursor: pointer;
|
||||
transition: all 0.3s ease;
|
||||
}
|
||||
|
||||
.copy-btn:hover {
|
||||
background-color: #357abd;
|
||||
}
|
||||
|
||||
.copy-btn.copied {
|
||||
background-color: #45a049;
|
||||
}
|
||||
|
||||
.copy-btn i {
|
||||
margin-right: 6px;
|
||||
}
|
||||
|
||||
/* 生成的提示词样式 */
|
||||
#generatedPrompt {
|
||||
background-color: #f8f9fa;
|
||||
padding: 1rem;
|
||||
margin-bottom: 1rem;
|
||||
white-space: pre-wrap;
|
||||
font-family: monospace;
|
||||
line-height: 1.5;
|
||||
}
|
||||
|
||||
/* 加载指示器样式 */
|
||||
#loadingIndicator {
|
||||
margin: 2rem 0;
|
||||
}
|
||||
|
||||
.spinner-border {
|
||||
width: 3rem;
|
||||
height: 3rem;
|
||||
}
|
||||
</style>
|
||||
{% endblock %}
|
||||
{% endblock %}
|
||||
1235
src/flask_prompt_master/templates/generate.html
Normal file
1235
src/flask_prompt_master/templates/generate.html
Normal file
File diff suppressed because it is too large
Load Diff
26
src/flask_prompt_master/templates/index.html
Normal file
26
src/flask_prompt_master/templates/index.html
Normal file
@@ -0,0 +1,26 @@
|
||||
{% extends "base.html" %}
|
||||
|
||||
{% block title %}首页{% endblock %}
|
||||
|
||||
{% block content %}
|
||||
<section class="hero">
|
||||
<h1>欢迎使用提示词大师</h1>
|
||||
<p>智能生成高质量提示词,提升您的工作效率</p>
|
||||
<a href="{{ url_for('main.generate_prompt') }}" class="cta-button">开始生成</a>
|
||||
</section>
|
||||
|
||||
<section class="features">
|
||||
<div class="feature">
|
||||
<h2>智能生成</h2>
|
||||
<p>基于先进的大模型技术,快速生成精准提示词</p>
|
||||
</div>
|
||||
<div class="feature">
|
||||
<h2>用户友好</h2>
|
||||
<p>简洁直观的界面设计,轻松上手</p>
|
||||
</div>
|
||||
<div class="feature">
|
||||
<h2>持续优化</h2>
|
||||
<p>通过用户反馈不断改进提示词质量</p>
|
||||
</div>
|
||||
</section>
|
||||
{% endblock %}
|
||||
105
src/flask_prompt_master/templates/prompt.html
Normal file
105
src/flask_prompt_master/templates/prompt.html
Normal file
@@ -0,0 +1,105 @@
|
||||
{% extends "base.html" %}
|
||||
|
||||
{% block title %}生成结果{% endblock %}
|
||||
|
||||
{% block content %}
|
||||
<div class="prompt-container">
|
||||
<h1>生成结果</h1>
|
||||
|
||||
<div class="prompt-card">
|
||||
<div class="prompt-section">
|
||||
<h2>原始文本</h2>
|
||||
<div class="text-content">{{ prompt.input_text }}</div>
|
||||
</div>
|
||||
|
||||
<div class="prompt-section">
|
||||
<h2>生成的提示词</h2>
|
||||
<div class="text-content">{{ prompt.generated_text }}</div>
|
||||
<button class="btn btn-copy" onclick="copyText('{{ prompt.generated_text }}')">复制</button>
|
||||
</div>
|
||||
|
||||
<div class="prompt-actions">
|
||||
<a href="{{ url_for('main.index') }}" class="btn btn-primary">继续生成</a>
|
||||
<a href="{{ url_for('main.submit_feedback', prompt_id=prompt.id) }}" class="btn btn-secondary">提供反馈</a>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<style>
|
||||
.prompt-container {
|
||||
max-width: 800px;
|
||||
margin: 2rem auto;
|
||||
padding: 2rem;
|
||||
}
|
||||
|
||||
.prompt-card {
|
||||
background: white;
|
||||
border-radius: 8px;
|
||||
box-shadow: 0 2px 4px rgba(0,0,0,0.1);
|
||||
padding: 2rem;
|
||||
}
|
||||
|
||||
.prompt-section {
|
||||
margin-bottom: 2rem;
|
||||
}
|
||||
|
||||
.prompt-section h2 {
|
||||
color: #333;
|
||||
font-size: 1.25rem;
|
||||
margin-bottom: 1rem;
|
||||
}
|
||||
|
||||
.text-content {
|
||||
background: #f8f9fa;
|
||||
padding: 1rem;
|
||||
border-radius: 4px;
|
||||
white-space: pre-wrap;
|
||||
margin-bottom: 1rem;
|
||||
}
|
||||
|
||||
.prompt-actions {
|
||||
display: flex;
|
||||
gap: 1rem;
|
||||
margin-top: 2rem;
|
||||
}
|
||||
|
||||
.btn {
|
||||
padding: 0.75rem 1.5rem;
|
||||
border: none;
|
||||
border-radius: 4px;
|
||||
cursor: pointer;
|
||||
font-size: 1rem;
|
||||
text-decoration: none;
|
||||
}
|
||||
|
||||
.btn-primary {
|
||||
background-color: #2196f3;
|
||||
color: white;
|
||||
}
|
||||
|
||||
.btn-secondary {
|
||||
background-color: #6c757d;
|
||||
color: white;
|
||||
}
|
||||
|
||||
.btn-copy {
|
||||
background-color: #28a745;
|
||||
color: white;
|
||||
}
|
||||
|
||||
.btn:hover {
|
||||
opacity: 0.9;
|
||||
}
|
||||
</style>
|
||||
|
||||
<script>
|
||||
function copyText(text) {
|
||||
navigator.clipboard.writeText(text).then(function() {
|
||||
alert('已复制到剪贴板');
|
||||
}).catch(function(err) {
|
||||
console.error('复制失败:', err);
|
||||
alert('复制失败,请手动复制');
|
||||
});
|
||||
}
|
||||
</script>
|
||||
{% endblock %}
|
||||
366
src/flask_prompt_master/templates/prompt_list.html
Normal file
366
src/flask_prompt_master/templates/prompt_list.html
Normal file
@@ -0,0 +1,366 @@
|
||||
{% extends "base.html" %}
|
||||
|
||||
{% block content %}
|
||||
<div class="container">
|
||||
<!-- 页面标题区域 -->
|
||||
<div class="page-header">
|
||||
<h1>提示词模板库</h1>
|
||||
<p class="subtitle">选择适合您需求的专业模板</p>
|
||||
</div>
|
||||
|
||||
<!-- 分类导航 -->
|
||||
<div class="category-nav">
|
||||
<div class="category-item {% if current_category == '全部' %}active{% endif %}">
|
||||
<i class="fas fa-th-large"></i>
|
||||
<a href="{{ url_for('prompts.list', category='全部') }}">全部模板</a>
|
||||
</div>
|
||||
{% for category, info in categories.items() %}
|
||||
<div class="category-item {% if current_category == category %}active{% endif %}">
|
||||
<i class="{{ info.icon }}"></i>
|
||||
<a href="{{ url_for('prompts.list', category=category) }}">
|
||||
{{ category }}
|
||||
<span class="template-count">{{ info.templates|length }}</span>
|
||||
</a>
|
||||
</div>
|
||||
{% endfor %}
|
||||
</div>
|
||||
|
||||
<!-- 搜索和筛选区域 -->
|
||||
<div class="filter-section">
|
||||
<div class="search-box">
|
||||
<i class="fas fa-search"></i>
|
||||
<input type="text" placeholder="搜索模板..." id="templateSearch">
|
||||
</div>
|
||||
<div class="view-toggle">
|
||||
<button class="view-btn active" data-view="grid">
|
||||
<i class="fas fa-th-large"></i>
|
||||
</button>
|
||||
<button class="view-btn" data-view="list">
|
||||
<i class="fas fa-list"></i>
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- 模板列表 -->
|
||||
<div class="template-grid" id="templateContainer">
|
||||
{% for template in templates %}
|
||||
<div class="template-card" data-category="{{ template.category }}">
|
||||
<div class="card-header">
|
||||
<i class="{{ categories[template.category].icon if template.category in categories }}"></i>
|
||||
<h3>{{ template.name }}</h3>
|
||||
</div>
|
||||
<div class="card-body">
|
||||
<p class="description">{{ template.description }}</p>
|
||||
<div class="tags">
|
||||
<span class="tag industry">
|
||||
<i class="fas fa-building"></i>
|
||||
{{ template.industry }}
|
||||
</span>
|
||||
<span class="tag profession">
|
||||
<i class="fas fa-user-tie"></i>
|
||||
{{ template.profession }}
|
||||
</span>
|
||||
</div>
|
||||
</div>
|
||||
<div class="card-footer">
|
||||
<button class="btn-preview" onclick="previewTemplate('{{ template.id }}')">
|
||||
<i class="fas fa-eye"></i> 预览
|
||||
</button>
|
||||
<button class="btn-use" onclick="useTemplate('{{ template.id }}')">
|
||||
<i class="fas fa-plus"></i> 使用模板
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
{% endfor %}
|
||||
</div>
|
||||
|
||||
<!-- 分页控件 -->
|
||||
<div class="pagination">
|
||||
{% if page > 1 %}
|
||||
<a href="{{ url_for('prompts.list', page=page-1, category=current_category) }}" class="page-btn">
|
||||
<i class="fas fa-chevron-left"></i> 上一页
|
||||
</a>
|
||||
{% endif %}
|
||||
|
||||
<div class="page-numbers">
|
||||
{% for p in range(1, total_pages + 1) %}
|
||||
<a href="{{ url_for('prompts.list', page=p, category=current_category) }}"
|
||||
class="page-number {% if p == page %}active{% endif %}">
|
||||
{{ p }}
|
||||
</a>
|
||||
{% endfor %}
|
||||
</div>
|
||||
|
||||
{% if has_next %}
|
||||
<a href="{{ url_for('prompts.list', page=page+1, category=current_category) }}" class="page-btn">
|
||||
下一页 <i class="fas fa-chevron-right"></i>
|
||||
</a>
|
||||
{% endif %}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- 模板预览模态框 -->
|
||||
<div class="modal" id="previewModal">
|
||||
<div class="modal-content">
|
||||
<span class="close">×</span>
|
||||
<div class="modal-body"></div>
|
||||
</div>
|
||||
</div>
|
||||
{% endblock %}
|
||||
|
||||
{% block styles %}
|
||||
<style>
|
||||
:root {
|
||||
--primary-color: #2563eb;
|
||||
--secondary-color: #3b82f6;
|
||||
--background-color: #f8fafc;
|
||||
--text-color: #1e293b;
|
||||
--border-color: #e2e8f0;
|
||||
--hover-color: #dbeafe;
|
||||
--shadow-color: rgba(0, 0, 0, 0.1);
|
||||
}
|
||||
|
||||
.container {
|
||||
max-width: 1200px;
|
||||
margin: 0 auto;
|
||||
padding: 2rem;
|
||||
}
|
||||
|
||||
.page-header {
|
||||
text-align: center;
|
||||
margin-bottom: 3rem;
|
||||
}
|
||||
|
||||
.page-header h1 {
|
||||
font-size: 2.5rem;
|
||||
color: var(--text-color);
|
||||
margin-bottom: 0.5rem;
|
||||
}
|
||||
|
||||
.subtitle {
|
||||
color: #64748b;
|
||||
font-size: 1.1rem;
|
||||
}
|
||||
|
||||
.category-nav {
|
||||
display: flex;
|
||||
gap: 1rem;
|
||||
margin-bottom: 2rem;
|
||||
overflow-x: auto;
|
||||
padding: 1rem;
|
||||
scrollbar-width: thin;
|
||||
-webkit-overflow-scrolling: touch;
|
||||
}
|
||||
|
||||
.category-item {
|
||||
padding: 0.75rem 1.25rem;
|
||||
border-radius: 999px;
|
||||
background: white;
|
||||
box-shadow: 0 1px 3px var(--shadow-color);
|
||||
cursor: pointer;
|
||||
transition: all 0.3s ease;
|
||||
white-space: nowrap;
|
||||
}
|
||||
|
||||
.category-item:hover {
|
||||
transform: translateY(-2px);
|
||||
box-shadow: 0 4px 6px var(--shadow-color);
|
||||
}
|
||||
|
||||
.category-item.active {
|
||||
background: var(--primary-color);
|
||||
color: white;
|
||||
}
|
||||
|
||||
.template-grid {
|
||||
display: grid;
|
||||
grid-template-columns: repeat(auto-fill, minmax(320px, 1fr));
|
||||
gap: 2rem;
|
||||
margin-bottom: 3rem;
|
||||
}
|
||||
|
||||
.template-card {
|
||||
border-radius: 12px;
|
||||
background: white;
|
||||
box-shadow: 0 2px 4px var(--shadow-color);
|
||||
transition: all 0.3s ease;
|
||||
overflow: hidden;
|
||||
}
|
||||
|
||||
.template-card:hover {
|
||||
transform: translateY(-5px);
|
||||
box-shadow: 0 8px 16px var(--shadow-color);
|
||||
}
|
||||
|
||||
.card-header {
|
||||
padding: 1.25rem;
|
||||
border-bottom: 1px solid var(--border-color);
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 1rem;
|
||||
}
|
||||
|
||||
.card-header i {
|
||||
font-size: 1.5rem;
|
||||
color: var(--primary-color);
|
||||
}
|
||||
|
||||
.card-body {
|
||||
padding: 1.25rem;
|
||||
}
|
||||
|
||||
.description {
|
||||
color: #64748b;
|
||||
margin-bottom: 1rem;
|
||||
line-height: 1.5;
|
||||
}
|
||||
|
||||
.tags {
|
||||
display: flex;
|
||||
flex-wrap: wrap;
|
||||
gap: 0.5rem;
|
||||
}
|
||||
|
||||
.tag {
|
||||
padding: 0.4rem 0.8rem;
|
||||
border-radius: 999px;
|
||||
font-size: 0.875rem;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 0.5rem;
|
||||
}
|
||||
|
||||
.tag.industry {
|
||||
background: #dbeafe;
|
||||
color: #1e40af;
|
||||
}
|
||||
|
||||
.tag.profession {
|
||||
background: #dcfce7;
|
||||
color: #166534;
|
||||
}
|
||||
|
||||
.card-footer {
|
||||
padding: 1.25rem;
|
||||
border-top: 1px solid var(--border-color);
|
||||
display: flex;
|
||||
justify-content: flex-end;
|
||||
gap: 1rem;
|
||||
}
|
||||
|
||||
.btn-preview, .btn-use {
|
||||
padding: 0.5rem 1rem;
|
||||
border-radius: 6px;
|
||||
border: none;
|
||||
cursor: pointer;
|
||||
transition: all 0.2s ease;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 0.5rem;
|
||||
}
|
||||
|
||||
.btn-preview {
|
||||
background: #f1f5f9;
|
||||
color: var(--text-color);
|
||||
}
|
||||
|
||||
.btn-use {
|
||||
background: var(--primary-color);
|
||||
color: white;
|
||||
}
|
||||
|
||||
.btn-preview:hover {
|
||||
background: #e2e8f0;
|
||||
}
|
||||
|
||||
.btn-use:hover {
|
||||
background: var(--secondary-color);
|
||||
}
|
||||
|
||||
/* 响应式设计 */
|
||||
@media (max-width: 768px) {
|
||||
.container {
|
||||
padding: 1rem;
|
||||
}
|
||||
|
||||
.template-grid {
|
||||
grid-template-columns: 1fr;
|
||||
}
|
||||
|
||||
.page-header h1 {
|
||||
font-size: 2rem;
|
||||
}
|
||||
|
||||
.category-nav {
|
||||
padding: 0.5rem;
|
||||
}
|
||||
}
|
||||
|
||||
/* 动画效果 */
|
||||
@keyframes fadeIn {
|
||||
from { opacity: 0; transform: translateY(20px); }
|
||||
to { opacity: 1; transform: translateY(0); }
|
||||
}
|
||||
|
||||
.template-card {
|
||||
animation: fadeIn 0.5s ease-out;
|
||||
}
|
||||
</style>
|
||||
{% endblock %}
|
||||
|
||||
{% block scripts %}
|
||||
<script>
|
||||
document.addEventListener('DOMContentLoaded', function() {
|
||||
// 搜索功能
|
||||
const searchInput = document.getElementById('templateSearch');
|
||||
const templateContainer = document.getElementById('templateContainer');
|
||||
const templateCards = templateContainer.getElementsByClassName('template-card');
|
||||
|
||||
searchInput.addEventListener('input', function(e) {
|
||||
const searchTerm = e.target.value.toLowerCase();
|
||||
|
||||
Array.from(templateCards).forEach(card => {
|
||||
const title = card.querySelector('h3').textContent.toLowerCase();
|
||||
const description = card.querySelector('.description').textContent.toLowerCase();
|
||||
|
||||
if (title.includes(searchTerm) || description.includes(searchTerm)) {
|
||||
card.style.display = '';
|
||||
} else {
|
||||
card.style.display = 'none';
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
// 视图切换
|
||||
const viewButtons = document.querySelectorAll('.view-btn');
|
||||
viewButtons.forEach(btn => {
|
||||
btn.addEventListener('click', function() {
|
||||
viewButtons.forEach(b => b.classList.remove('active'));
|
||||
this.classList.add('active');
|
||||
|
||||
const viewType = this.dataset.view;
|
||||
templateContainer.className = `template-${viewType}`;
|
||||
});
|
||||
});
|
||||
|
||||
// 模板预览
|
||||
const modal = document.getElementById('previewModal');
|
||||
const closeBtn = modal.querySelector('.close');
|
||||
|
||||
window.previewTemplate = function(templateId) {
|
||||
modal.style.display = 'block';
|
||||
// 这里添加获取模板预览数据的逻辑
|
||||
}
|
||||
|
||||
closeBtn.onclick = function() {
|
||||
modal.style.display = 'none';
|
||||
}
|
||||
|
||||
window.onclick = function(event) {
|
||||
if (event.target == modal) {
|
||||
modal.style.display = 'none';
|
||||
}
|
||||
}
|
||||
});
|
||||
</script>
|
||||
{% endblock %}
|
||||
2467
src/flask_prompt_master/templates/prompts.py
Normal file
2467
src/flask_prompt_master/templates/prompts.py
Normal file
File diff suppressed because it is too large
Load Diff
10
src/flask_prompt_master/utils/__init__.py
Normal file
10
src/flask_prompt_master/utils/__init__.py
Normal file
@@ -0,0 +1,10 @@
|
||||
"""
|
||||
工具包
|
||||
包含所有工具函数和辅助类
|
||||
"""
|
||||
|
||||
# 这里将导入具体的工具函数
|
||||
# from .validators import validate_prompt
|
||||
# from .helpers import format_response
|
||||
|
||||
__all__ = []
|
||||
Reference in New Issue
Block a user