优化
This commit is contained in:
@@ -139,3 +139,16 @@ export function removeFavorite(agentId) {
|
||||
params: { agentId }
|
||||
})
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取收藏的智能体列表
|
||||
* 直接从 getAgentList 结果中过滤 isFavorite 为 true 的项
|
||||
*/
|
||||
export async function getFavoriteList() {
|
||||
const res = await getAgentList()
|
||||
if (res.code === 0 && res.data) {
|
||||
const favorites = res.data.filter(item => item.isFavorite)
|
||||
return { code: 0, data: favorites }
|
||||
}
|
||||
return res
|
||||
}
|
||||
|
||||
86
frontend/app/web-gold/src/api/dify.js
Normal file
86
frontend/app/web-gold/src/api/dify.js
Normal file
@@ -0,0 +1,86 @@
|
||||
/**
|
||||
* Dify API
|
||||
*/
|
||||
import { fetchEventSource } from '@microsoft/fetch-event-source'
|
||||
import tokenManager from '@gold/utils/token-manager'
|
||||
import { API_BASE } from '@gold/config/api'
|
||||
|
||||
const BASE_URL = `${API_BASE.APP_TIK}`
|
||||
|
||||
/**
|
||||
* 对标分析流式 API
|
||||
* @param {Object} options - 请求配置
|
||||
* @param {string} options.content - 合并后的文案内容
|
||||
* @param {number} options.videoCount - 视频数量
|
||||
* @param {AbortController} [options.ctrl] - 取消控制器
|
||||
* @param {Function} options.onMessage - 消息回调
|
||||
* @param {Function} [options.onError] - 错误回调
|
||||
* @param {Function} [options.onComplete] - 完成回调
|
||||
*/
|
||||
export async function benchmarkAnalyzeStream(options) {
|
||||
const {
|
||||
content,
|
||||
videoCount,
|
||||
ctrl,
|
||||
onMessage,
|
||||
onError,
|
||||
onComplete
|
||||
} = options || {}
|
||||
|
||||
const token = tokenManager.getAccessToken()
|
||||
let fullText = ''
|
||||
let conversationId = ''
|
||||
|
||||
return fetchEventSource(`${BASE_URL}/dify/benchmark/analyze`, {
|
||||
method: 'post',
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
'Authorization': `Bearer ${token}`,
|
||||
'tenant-id': import.meta.env?.VITE_TENANT_ID
|
||||
},
|
||||
openWhenHidden: true,
|
||||
body: JSON.stringify({
|
||||
content,
|
||||
videoCount
|
||||
}),
|
||||
onmessage: (event) => {
|
||||
if (typeof onMessage === 'function') {
|
||||
try {
|
||||
const data = JSON.parse(event.data)
|
||||
// 解析 CommonResult 包装
|
||||
const result = data.code === 0 ? data.data : data
|
||||
|
||||
// 处理消息内容
|
||||
if (result.event === 'message' || result.event === 'agent_message') {
|
||||
fullText += result.content || ''
|
||||
onMessage(fullText, result.content)
|
||||
}
|
||||
// 处理完成事件
|
||||
else if (result.event === 'done') {
|
||||
conversationId = result.conversationId
|
||||
}
|
||||
// 处理错误事件
|
||||
else if (result.event === 'error') {
|
||||
if (typeof onError === 'function') {
|
||||
onError(new Error(result.content || '分析失败'))
|
||||
}
|
||||
}
|
||||
} catch (e) {
|
||||
console.error('解析 SSE 数据失败:', e)
|
||||
}
|
||||
}
|
||||
},
|
||||
onerror: (err) => {
|
||||
if (typeof onError === 'function') {
|
||||
onError(err)
|
||||
}
|
||||
throw err // 不重试
|
||||
},
|
||||
onclose: () => {
|
||||
if (typeof onComplete === 'function') {
|
||||
onComplete(fullText, conversationId)
|
||||
}
|
||||
},
|
||||
signal: ctrl ? ctrl.signal : undefined
|
||||
})
|
||||
}
|
||||
@@ -10,10 +10,11 @@ const BASE_URL = `${API_BASE.APP_TIK}`
|
||||
/**
|
||||
* 流式文案改写(SSE)
|
||||
* @param {Object} options - 请求配置
|
||||
* @param {number} options.agentId - 智能体ID
|
||||
* @param {number} [options.agentId] - 智能体ID(使用用户风格时可不传)
|
||||
* @param {string} options.userText - 用户输入文案
|
||||
* @param {number} [options.level] - 改写级别/强度
|
||||
* @param {string} [options.modelType] - 模型类型:forecast_standard/forecast_pro
|
||||
* @param {string} [options.customSystemPrompt] - 自定义系统提示词(使用用户风格时传入)
|
||||
* @param {AbortController} [options.ctrl] - 取消控制器
|
||||
* @param {Function} options.onMessage - 消息回调
|
||||
* @param {Function} [options.onError] - 错误回调
|
||||
@@ -25,6 +26,7 @@ export async function rewriteStream(options) {
|
||||
userText,
|
||||
level = 50,
|
||||
modelType = 'forecast_standard',
|
||||
customSystemPrompt,
|
||||
ctrl,
|
||||
onMessage,
|
||||
onError,
|
||||
@@ -45,7 +47,8 @@ export async function rewriteStream(options) {
|
||||
agentId,
|
||||
userText,
|
||||
level,
|
||||
modelType
|
||||
modelType,
|
||||
customSystemPrompt
|
||||
}),
|
||||
onmessage: (event) => {
|
||||
if (typeof onMessage === 'function') {
|
||||
|
||||
@@ -40,6 +40,14 @@ export const UserPromptApi = {
|
||||
return await http.get(`${SERVER_BASE_AI}/user-prompt/page`, { params })
|
||||
},
|
||||
|
||||
/**
|
||||
* 获取用户提示词列表(简化版,不分页)
|
||||
* @returns {Promise} 响应数据
|
||||
*/
|
||||
getUserPromptList: async () => {
|
||||
return await http.get(`${SERVER_BASE_AI}/user-prompt/list`)
|
||||
},
|
||||
|
||||
/**
|
||||
* 获取单个用户提示词
|
||||
* @param {Number} id - 提示词ID
|
||||
|
||||
306
frontend/app/web-gold/src/components/MyFavoritesModal.vue
Normal file
306
frontend/app/web-gold/src/components/MyFavoritesModal.vue
Normal file
@@ -0,0 +1,306 @@
|
||||
<template>
|
||||
<a-modal
|
||||
:open="visible"
|
||||
title="我创建的"
|
||||
:width="700"
|
||||
:footer="null"
|
||||
@cancel="handleClose"
|
||||
>
|
||||
<div class="favorites-content">
|
||||
<!-- 操作栏 -->
|
||||
<div class="action-bar">
|
||||
<a-button type="primary" @click="handleCreate">
|
||||
<template #icon><PlusOutlined /></template>
|
||||
新建风格
|
||||
</a-button>
|
||||
<a-button @click="loadList" :loading="loading">
|
||||
<template #icon><ReloadOutlined /></template>
|
||||
刷新
|
||||
</a-button>
|
||||
</div>
|
||||
|
||||
<!-- 列表 -->
|
||||
<div class="favorites-list" v-if="!loading && list.length > 0">
|
||||
<div
|
||||
v-for="item in list"
|
||||
:key="item.id"
|
||||
class="favorite-card"
|
||||
>
|
||||
<div class="card-header">
|
||||
<span class="card-name">{{ item.name }}</span>
|
||||
<div class="card-actions">
|
||||
<a-button type="link" size="small" @click="handleEdit(item)">编辑</a-button>
|
||||
<a-popconfirm
|
||||
title="确定删除此风格?"
|
||||
@confirm="handleDelete(item.id)"
|
||||
>
|
||||
<a-button type="link" size="small" danger>删除</a-button>
|
||||
</a-popconfirm>
|
||||
</div>
|
||||
</div>
|
||||
<div class="card-content">{{ item.content }}</div>
|
||||
<div class="card-footer">
|
||||
<span class="card-category" v-if="item.category">{{ item.category }}</span>
|
||||
<span class="card-use-count">使用 {{ item.useCount || 0 }} 次</span>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- 空状态 -->
|
||||
<div class="empty-state" v-if="!loading && list.length === 0">
|
||||
<p>暂无收藏的风格</p>
|
||||
<a-button type="primary" @click="handleCreate">立即创建</a-button>
|
||||
</div>
|
||||
|
||||
<!-- 加载状态 -->
|
||||
<div class="loading-state" v-if="loading">
|
||||
<a-spin />
|
||||
<span>加载中...</span>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- 编辑弹窗 -->
|
||||
<a-modal
|
||||
v-model:open="editVisible"
|
||||
:title="editingItem ? '编辑风格' : '新建风格'"
|
||||
:width="500"
|
||||
@ok="handleSave"
|
||||
:confirmLoading="saving"
|
||||
>
|
||||
<a-form layout="vertical">
|
||||
<a-form-item label="风格名称" required>
|
||||
<a-input v-model:value="editForm.name" placeholder="请输入风格名称" />
|
||||
</a-form-item>
|
||||
<a-form-item label="风格内容" required>
|
||||
<a-textarea
|
||||
v-model:value="editForm.content"
|
||||
:rows="6"
|
||||
placeholder="请输入风格提示词内容"
|
||||
/>
|
||||
</a-form-item>
|
||||
<a-form-item label="分类">
|
||||
<a-input v-model:value="editForm.category" placeholder="可选,用于分类管理" />
|
||||
</a-form-item>
|
||||
</a-form>
|
||||
</a-modal>
|
||||
</a-modal>
|
||||
</template>
|
||||
|
||||
<script setup>
|
||||
import { ref, watch } from 'vue'
|
||||
import { message } from 'ant-design-vue'
|
||||
import { PlusOutlined, ReloadOutlined } from '@ant-design/icons-vue'
|
||||
import { UserPromptApi } from '@/api/userPrompt'
|
||||
|
||||
const props = defineProps({
|
||||
visible: {
|
||||
type: Boolean,
|
||||
default: false
|
||||
}
|
||||
})
|
||||
|
||||
const emit = defineEmits(['update:visible', 'refresh'])
|
||||
|
||||
const loading = ref(false)
|
||||
const list = ref([])
|
||||
const editVisible = ref(false)
|
||||
const editingItem = ref(null)
|
||||
const saving = ref(false)
|
||||
|
||||
const editForm = ref({
|
||||
name: '',
|
||||
content: '',
|
||||
category: ''
|
||||
})
|
||||
|
||||
// 加载列表
|
||||
async function loadList() {
|
||||
loading.value = true
|
||||
try {
|
||||
const res = await UserPromptApi.getUserPromptList()
|
||||
if (res.code === 0) {
|
||||
list.value = res.data || []
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('加载列表失败:', error)
|
||||
} finally {
|
||||
loading.value = false
|
||||
}
|
||||
}
|
||||
|
||||
// 创建新风格
|
||||
function handleCreate() {
|
||||
editingItem.value = null
|
||||
editForm.value = {
|
||||
name: '',
|
||||
content: '',
|
||||
category: ''
|
||||
}
|
||||
editVisible.value = true
|
||||
}
|
||||
|
||||
// 编辑风格
|
||||
function handleEdit(item) {
|
||||
editingItem.value = item
|
||||
editForm.value = {
|
||||
name: item.name,
|
||||
content: item.content,
|
||||
category: item.category || ''
|
||||
}
|
||||
editVisible.value = true
|
||||
}
|
||||
|
||||
// 保存风格
|
||||
async function handleSave() {
|
||||
if (!editForm.value.name.trim()) {
|
||||
message.warning('请输入风格名称')
|
||||
return
|
||||
}
|
||||
if (!editForm.value.content.trim()) {
|
||||
message.warning('请输入风格内容')
|
||||
return
|
||||
}
|
||||
|
||||
saving.value = true
|
||||
try {
|
||||
const data = {
|
||||
name: editForm.value.name.trim(),
|
||||
content: editForm.value.content.trim(),
|
||||
category: editForm.value.category.trim() || null,
|
||||
status: 1
|
||||
}
|
||||
|
||||
if (editingItem.value) {
|
||||
// 更新
|
||||
await UserPromptApi.updateUserPrompt({
|
||||
id: editingItem.value.id,
|
||||
...data
|
||||
})
|
||||
message.success('更新成功')
|
||||
} else {
|
||||
// 创建
|
||||
await UserPromptApi.createUserPrompt(data)
|
||||
message.success('创建成功')
|
||||
}
|
||||
|
||||
editVisible.value = false
|
||||
loadList()
|
||||
emit('refresh')
|
||||
} catch (error) {
|
||||
console.error('保存失败:', error)
|
||||
message.error('保存失败')
|
||||
} finally {
|
||||
saving.value = false
|
||||
}
|
||||
}
|
||||
|
||||
// 删除风格
|
||||
async function handleDelete(id) {
|
||||
try {
|
||||
await UserPromptApi.deleteUserPrompt(id)
|
||||
message.success('删除成功')
|
||||
loadList()
|
||||
emit('refresh')
|
||||
} catch (error) {
|
||||
console.error('删除失败:', error)
|
||||
message.error('删除失败')
|
||||
}
|
||||
}
|
||||
|
||||
// 关闭弹窗
|
||||
function handleClose() {
|
||||
emit('update:visible', false)
|
||||
}
|
||||
|
||||
// 监听 visible 变化
|
||||
watch(() => props.visible, (newVal) => {
|
||||
if (newVal) {
|
||||
loadList()
|
||||
}
|
||||
})
|
||||
</script>
|
||||
|
||||
<style scoped lang="less">
|
||||
.favorites-content {
|
||||
min-height: 300px;
|
||||
}
|
||||
|
||||
.action-bar {
|
||||
display: flex;
|
||||
gap: 12px;
|
||||
margin-bottom: 16px;
|
||||
}
|
||||
|
||||
.favorites-list {
|
||||
display: grid;
|
||||
gap: 12px;
|
||||
}
|
||||
|
||||
.favorite-card {
|
||||
padding: 16px;
|
||||
border: 1px solid var(--color-border);
|
||||
border-radius: 8px;
|
||||
background: var(--color-surface);
|
||||
transition: all 0.2s;
|
||||
|
||||
&:hover {
|
||||
border-color: var(--color-primary);
|
||||
box-shadow: 0 2px 8px rgba(0, 0, 0, 0.08);
|
||||
}
|
||||
}
|
||||
|
||||
.card-header {
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
align-items: center;
|
||||
margin-bottom: 8px;
|
||||
}
|
||||
|
||||
.card-name {
|
||||
font-weight: 600;
|
||||
font-size: 15px;
|
||||
color: var(--color-text);
|
||||
}
|
||||
|
||||
.card-actions {
|
||||
display: flex;
|
||||
gap: 4px;
|
||||
}
|
||||
|
||||
.card-content {
|
||||
color: var(--color-text-secondary);
|
||||
font-size: 13px;
|
||||
line-height: 1.6;
|
||||
display: -webkit-box;
|
||||
-webkit-line-clamp: 3;
|
||||
-webkit-box-orient: vertical;
|
||||
overflow: hidden;
|
||||
margin-bottom: 12px;
|
||||
}
|
||||
|
||||
.card-footer {
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
align-items: center;
|
||||
font-size: 12px;
|
||||
color: var(--color-text-tertiary);
|
||||
}
|
||||
|
||||
.card-category {
|
||||
padding: 2px 8px;
|
||||
background: rgba(24, 144, 255, 0.1);
|
||||
color: #1890ff;
|
||||
border-radius: 10px;
|
||||
}
|
||||
|
||||
.empty-state,
|
||||
.loading-state {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
padding: 60px 20px;
|
||||
color: var(--color-text-secondary);
|
||||
gap: 16px;
|
||||
}
|
||||
</style>
|
||||
283
frontend/app/web-gold/src/components/StyleSelector.vue
Normal file
283
frontend/app/web-gold/src/components/StyleSelector.vue
Normal file
@@ -0,0 +1,283 @@
|
||||
<template>
|
||||
<a-select
|
||||
v-model:value="selectedId"
|
||||
:placeholder="placeholder"
|
||||
:loading="loading"
|
||||
style="width: 100%"
|
||||
show-search
|
||||
:filter-option="filterOption"
|
||||
@change="handleChange"
|
||||
>
|
||||
<!-- 用户风格分组 -->
|
||||
<a-select-opt-group v-if="userPrompts.length > 0">
|
||||
<template #label>
|
||||
<span class="group-label">用户风格</span>
|
||||
</template>
|
||||
<a-select-option
|
||||
v-for="item in userPrompts"
|
||||
:key="`prompt-${item.id}`"
|
||||
:value="`prompt-${item.id}`"
|
||||
>
|
||||
<div class="option-content">
|
||||
<span class="option-name">{{ item.name }}</span>
|
||||
<span class="option-tag style-tag">风格</span>
|
||||
</div>
|
||||
</a-select-option>
|
||||
</a-select-opt-group>
|
||||
|
||||
<!-- 收藏的智能体分组 -->
|
||||
<a-select-opt-group v-if="favoriteAgents.length > 0">
|
||||
<template #label>
|
||||
<span class="group-label">收藏的智能体</span>
|
||||
</template>
|
||||
<a-select-option
|
||||
v-for="item in favoriteAgents"
|
||||
:key="`agent-${item.id}`"
|
||||
:value="`agent-${item.id}`"
|
||||
>
|
||||
<div class="option-content">
|
||||
<img v-if="item.avatar" :src="item.avatar" class="option-avatar" />
|
||||
<span class="option-name">{{ item.name }}</span>
|
||||
<span class="option-tag agent-tag">{{ item.categoryName || '智能体' }}</span>
|
||||
</div>
|
||||
</a-select-option>
|
||||
</a-select-opt-group>
|
||||
|
||||
<!-- 空状态 -->
|
||||
<template v-if="!loading && userPrompts.length === 0 && favoriteAgents.length === 0">
|
||||
<a-select-option disabled value="__empty__">
|
||||
<span class="empty-text">暂无可选项</span>
|
||||
</a-select-option>
|
||||
</template>
|
||||
</a-select>
|
||||
</template>
|
||||
|
||||
<script setup>
|
||||
import { ref, computed, watch, onMounted } from 'vue'
|
||||
import { usePromptStore } from '@/stores/prompt'
|
||||
import { getAgentList } from '@/api/agent'
|
||||
import { getJSON, setJSON } from '@/utils/storage'
|
||||
|
||||
const props = defineProps({
|
||||
modelValue: {
|
||||
type: [String, Number],
|
||||
default: null
|
||||
},
|
||||
placeholder: {
|
||||
type: String,
|
||||
default: '选择文案风格'
|
||||
},
|
||||
storageKey: {
|
||||
type: String,
|
||||
default: 'style_selector'
|
||||
}
|
||||
})
|
||||
|
||||
const emit = defineEmits(['update:modelValue', 'change'])
|
||||
|
||||
const promptStore = usePromptStore()
|
||||
|
||||
const loading = ref(false)
|
||||
const selectedId = ref(null)
|
||||
const agentList = ref([])
|
||||
|
||||
// 用户风格列表
|
||||
const userPrompts = computed(() => promptStore.promptList || [])
|
||||
|
||||
// 收藏的智能体列表
|
||||
const favoriteAgents = computed(() => {
|
||||
return agentList.value.filter(agent => agent.isFavorite)
|
||||
})
|
||||
|
||||
// 过滤选项
|
||||
function filterOption(input, option) {
|
||||
const key = option.value
|
||||
const name = option.label || ''
|
||||
|
||||
// 根据 key 查找对应的项目名称
|
||||
if (key.startsWith('prompt-')) {
|
||||
const id = parseInt(key.replace('prompt-', ''))
|
||||
const prompt = userPrompts.value.find(p => p.id === id)
|
||||
return prompt?.name?.toLowerCase().includes(input.toLowerCase())
|
||||
} else if (key.startsWith('agent-')) {
|
||||
const id = parseInt(key.replace('agent-', ''))
|
||||
const agent = agentList.value.find(a => a.id === id)
|
||||
return agent?.name?.toLowerCase().includes(input.toLowerCase())
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
// 处理选择变化
|
||||
function handleChange(value) {
|
||||
if (!value || value === '__empty__') {
|
||||
emit('update:modelValue', null)
|
||||
emit('change', null)
|
||||
return
|
||||
}
|
||||
|
||||
const [type, idStr] = value.split('-')
|
||||
const id = parseInt(idStr)
|
||||
|
||||
let item = null
|
||||
if (type === 'prompt') {
|
||||
item = userPrompts.value.find(p => p.id === id)
|
||||
emit('change', { id, type: 'prompt', item })
|
||||
} else if (type === 'agent') {
|
||||
item = agentList.value.find(a => a.id === id)
|
||||
emit('change', { id, type: 'agent', item })
|
||||
}
|
||||
|
||||
emit('update:modelValue', id)
|
||||
|
||||
// 保存选中状态到本地
|
||||
saveSelectedValue(value)
|
||||
}
|
||||
|
||||
// 加载智能体列表
|
||||
async function loadAgentList() {
|
||||
try {
|
||||
const res = await getAgentList()
|
||||
if (res.code === 0 && res.data) {
|
||||
agentList.value = res.data.map(item => ({
|
||||
id: item.id,
|
||||
agentId: item.agentId,
|
||||
name: item.agentName,
|
||||
description: item.description,
|
||||
systemPrompt: item.systemPrompt,
|
||||
avatar: item.icon,
|
||||
categoryName: item.categoryName || '其他',
|
||||
isFavorite: item.isFavorite || false
|
||||
}))
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('加载智能体列表失败:', error)
|
||||
}
|
||||
}
|
||||
|
||||
// 加载用户风格列表
|
||||
async function loadUserPrompts() {
|
||||
try {
|
||||
await promptStore.loadPromptList()
|
||||
} catch (error) {
|
||||
console.error('加载用户风格列表失败:', error)
|
||||
}
|
||||
}
|
||||
|
||||
// 保存选中状态
|
||||
async function saveSelectedValue(value) {
|
||||
try {
|
||||
await setJSON(`${props.storageKey}_selected`, value)
|
||||
} catch (error) {
|
||||
console.error('保存选择状态失败:', error)
|
||||
}
|
||||
}
|
||||
|
||||
// 恢复选中状态
|
||||
async function restoreSelectedValue() {
|
||||
try {
|
||||
const savedValue = await getJSON(`${props.storageKey}_selected`, null)
|
||||
if (savedValue) {
|
||||
// 验证保存的值是否有效
|
||||
const [type, idStr] = savedValue.split('-')
|
||||
const id = parseInt(idStr)
|
||||
|
||||
if (type === 'prompt') {
|
||||
const exists = userPrompts.value.some(p => p.id === id)
|
||||
if (exists) {
|
||||
selectedId.value = savedValue
|
||||
emit('update:modelValue', id)
|
||||
const item = userPrompts.value.find(p => p.id === id)
|
||||
emit('change', { id, type: 'prompt', item })
|
||||
}
|
||||
} else if (type === 'agent') {
|
||||
const exists = agentList.value.some(a => a.id === id)
|
||||
if (exists) {
|
||||
selectedId.value = savedValue
|
||||
emit('update:modelValue', id)
|
||||
const item = agentList.value.find(a => a.id === id)
|
||||
emit('change', { id, type: 'agent', item })
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('恢复选择状态失败:', error)
|
||||
}
|
||||
}
|
||||
|
||||
// 初始化加载
|
||||
async function init() {
|
||||
loading.value = true
|
||||
try {
|
||||
await Promise.all([loadUserPrompts(), loadAgentList()])
|
||||
await restoreSelectedValue()
|
||||
} finally {
|
||||
loading.value = false
|
||||
}
|
||||
}
|
||||
|
||||
// 监听 modelValue 变化
|
||||
watch(() => props.modelValue, (newValue) => {
|
||||
if (newValue === null) {
|
||||
selectedId.value = null
|
||||
}
|
||||
})
|
||||
|
||||
onMounted(() => {
|
||||
init()
|
||||
})
|
||||
|
||||
// 暴露刷新方法
|
||||
defineExpose({
|
||||
refresh: init
|
||||
})
|
||||
</script>
|
||||
|
||||
<style scoped lang="less">
|
||||
.group-label {
|
||||
font-weight: 600;
|
||||
color: var(--color-text);
|
||||
font-size: 13px;
|
||||
}
|
||||
|
||||
.option-content {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 8px;
|
||||
}
|
||||
|
||||
.option-avatar {
|
||||
width: 20px;
|
||||
height: 20px;
|
||||
border-radius: 50%;
|
||||
object-fit: cover;
|
||||
}
|
||||
|
||||
.option-name {
|
||||
flex: 1;
|
||||
overflow: hidden;
|
||||
text-overflow: ellipsis;
|
||||
white-space: nowrap;
|
||||
}
|
||||
|
||||
.option-tag {
|
||||
font-size: 11px;
|
||||
padding: 1px 6px;
|
||||
border-radius: 10px;
|
||||
flex-shrink: 0;
|
||||
}
|
||||
|
||||
.style-tag {
|
||||
background: rgba(24, 144, 255, 0.1);
|
||||
color: #1890ff;
|
||||
}
|
||||
|
||||
.agent-tag {
|
||||
background: rgba(82, 196, 26, 0.1);
|
||||
color: #52c41a;
|
||||
}
|
||||
|
||||
.empty-text {
|
||||
color: var(--color-text-secondary);
|
||||
font-style: italic;
|
||||
}
|
||||
</style>
|
||||
303
frontend/app/web-gold/src/components/agents/MyFavoritesModal.vue
Normal file
303
frontend/app/web-gold/src/components/agents/MyFavoritesModal.vue
Normal file
@@ -0,0 +1,303 @@
|
||||
<script setup>
|
||||
import { ref, computed, watch } from 'vue'
|
||||
import { message } from 'ant-design-vue'
|
||||
import {
|
||||
StarFilled,
|
||||
CloseOutlined,
|
||||
EditOutlined,
|
||||
DeleteOutlined,
|
||||
PlusOutlined
|
||||
} from '@ant-design/icons-vue'
|
||||
import { UserPromptApi } from '@/api/userPrompt'
|
||||
|
||||
import SavePromptModal from '@/views/content-style/components/SavePromptModal.vue'
|
||||
|
||||
// Props
|
||||
const props = defineProps({
|
||||
visible: {
|
||||
type: Boolean,
|
||||
default: false
|
||||
}
|
||||
})
|
||||
|
||||
// Emits
|
||||
const emit = defineEmits(['update:visible', 'refresh'])
|
||||
|
||||
// State
|
||||
const loading = ref(false)
|
||||
const promptList = ref([])
|
||||
const searchKeyword = ref('')
|
||||
const showSaveModal = ref(false)
|
||||
const editingPrompt = ref(null)
|
||||
|
||||
// Computed
|
||||
const filteredList = computed(() => {
|
||||
if (!searchKeyword.value.trim()) return promptList.value
|
||||
const keyword = searchKeyword.value.trim().toLowerCase()
|
||||
return promptList.value.filter(item =>
|
||||
item.name.toLowerCase().includes(keyword) ||
|
||||
(item.content && item.content.toLowerCase().includes(keyword))
|
||||
)
|
||||
})
|
||||
|
||||
// Watch
|
||||
watch(() => props.visible, (newVal) => {
|
||||
if (newVal) {
|
||||
loadList()
|
||||
}
|
||||
})
|
||||
|
||||
// Methods
|
||||
async function loadList() {
|
||||
loading.value = true
|
||||
try {
|
||||
const res = await UserPromptApi.getUserPromptList()
|
||||
if (res.code === 0 && res.data) {
|
||||
promptList.value = res.data.map(item => ({
|
||||
id: item.id,
|
||||
name: item.name,
|
||||
content: item.content,
|
||||
category: item.category,
|
||||
useCount: item.useCount || 0
|
||||
}))
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('加载风格列表失败:', error)
|
||||
message.error('加载风格列表失败')
|
||||
} finally {
|
||||
loading.value = false
|
||||
}
|
||||
}
|
||||
|
||||
function handleClose() {
|
||||
emit('update:visible', false)
|
||||
}
|
||||
|
||||
function handleCreate() {
|
||||
editingPrompt.value = null
|
||||
showSaveModal.value = true
|
||||
}
|
||||
|
||||
function handleEdit(item) {
|
||||
editingPrompt.value = { ...item }
|
||||
showSaveModal.value = true
|
||||
}
|
||||
|
||||
async function handleDelete(id) {
|
||||
try {
|
||||
await UserPromptApi.deleteUserPrompt(id)
|
||||
// 从列表中移除
|
||||
const index = promptList.value.findIndex(p => p.id === id)
|
||||
if (index !== -1) {
|
||||
promptList.value.splice(index, 1)
|
||||
}
|
||||
message.success('删除成功')
|
||||
emit('refresh')
|
||||
} catch (error) {
|
||||
console.error('删除失败:', error)
|
||||
message.error('删除失败')
|
||||
}
|
||||
}
|
||||
|
||||
function handleSaveSuccess() {
|
||||
showSaveModal.value = false
|
||||
loadList()
|
||||
emit('refresh')
|
||||
}
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<a-modal
|
||||
:open="visible"
|
||||
title="我创建的"
|
||||
:width="700"
|
||||
:footer="null"
|
||||
@cancel="handleClose"
|
||||
>
|
||||
<!-- 操作栏 -->
|
||||
<div class="action-bar">
|
||||
<a-button type="primary" @click="handleCreate">
|
||||
<template #icon><PlusOutlined /></template>
|
||||
新建风格
|
||||
</a-button>
|
||||
<a-button @click="loadList" :loading="loading">
|
||||
刷新
|
||||
</a-button>
|
||||
</div>
|
||||
|
||||
<!-- 搜索框 -->
|
||||
<div class="search-bar">
|
||||
<a-input
|
||||
v-model:value="searchKeyword"
|
||||
placeholder="搜索风格..."
|
||||
allow-clear
|
||||
/>
|
||||
</div>
|
||||
|
||||
<!-- 列表 -->
|
||||
<div class="prompt-list" v-if="!loading && filteredList.length > 0">
|
||||
<div
|
||||
v-for="item in filteredList"
|
||||
:key="item.id"
|
||||
class="prompt-card"
|
||||
>
|
||||
<div class="card-header">
|
||||
<span class="card-name">{{ item.name }}</span>
|
||||
<div class="card-actions">
|
||||
<a-button type="link" size="small" @click="handleEdit(item)">
|
||||
<EditOutlined /> 编辑
|
||||
</a-button>
|
||||
<a-popconfirm
|
||||
title="确定删除此风格?"
|
||||
@confirm="handleDelete(item.id)"
|
||||
>
|
||||
<a-button type="link" size="small" danger>
|
||||
<DeleteOutlined /> 删除
|
||||
</a-button>
|
||||
</a-popconfirm>
|
||||
</div>
|
||||
</div>
|
||||
<div class="card-content">{{ item.content }}</div>
|
||||
<div class="card-footer">
|
||||
<span class="card-category" v-if="item.category">{{ item.category }}</span>
|
||||
<span class="card-use-count">使用 {{ item.useCount || 0 }} 次</span>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- 空状态 -->
|
||||
<div class="empty-state" v-else-if="!loading">
|
||||
<StarFilled class="empty-icon" />
|
||||
<p class="empty-title">暂无收藏的风格</p>
|
||||
<p class="empty-desc">点击"新建风格"创建您的第一个风格</p>
|
||||
</div>
|
||||
|
||||
<!-- 加载状态 -->
|
||||
<div class="loading-state" v-if="loading">
|
||||
<a-spin />
|
||||
</div>
|
||||
|
||||
<!-- 保存弹窗 -->
|
||||
<SavePromptModal
|
||||
v-model:visible="showSaveModal"
|
||||
:prompt="editingPrompt"
|
||||
@success="handleSaveSuccess"
|
||||
/>
|
||||
</a-modal>
|
||||
</template>
|
||||
|
||||
<style scoped lang="less">
|
||||
.action-bar {
|
||||
display: flex;
|
||||
gap: 12px;
|
||||
margin-bottom: 16px;
|
||||
}
|
||||
|
||||
.search-bar {
|
||||
margin-bottom: 16px;
|
||||
}
|
||||
|
||||
.prompt-list {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 12px;
|
||||
max-height: 400px;
|
||||
overflow-y: auto;
|
||||
}
|
||||
|
||||
.prompt-card {
|
||||
padding: 16px;
|
||||
border: 1px solid var(--color-border);
|
||||
border-radius: 8px;
|
||||
background: var(--color-surface);
|
||||
transition: all 0.2s ease;
|
||||
|
||||
&:hover {
|
||||
border-color: var(--color-primary);
|
||||
box-shadow: 0 2px 8px rgba(0, 0, 0, 0.08);
|
||||
}
|
||||
}
|
||||
|
||||
.card-header {
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
align-items: center;
|
||||
margin-bottom: 8px;
|
||||
}
|
||||
|
||||
.card-name {
|
||||
font-weight: 600;
|
||||
font-size: 14px;
|
||||
color: var(--color-text);
|
||||
}
|
||||
|
||||
.card-actions {
|
||||
display: flex;
|
||||
gap: 8px;
|
||||
}
|
||||
|
||||
.card-content {
|
||||
font-size: 13px;
|
||||
color: var(--color-text-secondary);
|
||||
line-height: 1.5;
|
||||
display: -webkit-box;
|
||||
-webkit-line-clamp: 2;
|
||||
-webkit-box-orient: vertical;
|
||||
overflow: hidden;
|
||||
margin-bottom: 8px;
|
||||
}
|
||||
|
||||
.card-footer {
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
align-items: center;
|
||||
font-size: 12px;
|
||||
}
|
||||
|
||||
.card-category {
|
||||
padding: 2px 8px;
|
||||
background: rgba(24, 144, 255, 0.1);
|
||||
color: #1890ff;
|
||||
border-radius: 10px;
|
||||
}
|
||||
|
||||
.card-use-count {
|
||||
color: var(--color-text-tertiary);
|
||||
}
|
||||
|
||||
.empty-state {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
padding: 48px 24px;
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
.empty-icon {
|
||||
font-size: 48px;
|
||||
color: #f59e0b;
|
||||
margin-bottom: 16px;
|
||||
opacity: 0.5;
|
||||
}
|
||||
|
||||
.empty-title {
|
||||
font-size: 15px;
|
||||
font-weight: 500;
|
||||
color: var(--color-text);
|
||||
margin: 0 0 8px 0;
|
||||
}
|
||||
|
||||
.empty-desc {
|
||||
font-size: 13px;
|
||||
color: var(--color-text-secondary);
|
||||
margin: 0;
|
||||
}
|
||||
|
||||
.loading-state {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
padding: 48px;
|
||||
}
|
||||
</style>
|
||||
@@ -26,6 +26,12 @@
|
||||
</button>
|
||||
</transition>
|
||||
</div>
|
||||
|
||||
<!-- 我创建的 -->
|
||||
<button class="favorites-btn" @click="showFavoritesModal = true">
|
||||
<StarFilled class="favorites-btn-icon" />
|
||||
<span class="favorites-btn-text">我创建的</span>
|
||||
</button>
|
||||
</div>
|
||||
|
||||
<!-- 精简分类筛选 -->
|
||||
@@ -183,6 +189,12 @@
|
||||
:agent-id="historyAgentId"
|
||||
@close="closeHistoryPanel"
|
||||
/>
|
||||
|
||||
<MyFavoritesModal
|
||||
v-model:visible="showFavoritesModal"
|
||||
@chat="handleChat"
|
||||
@remove="handleFavoriteRemoved"
|
||||
/>
|
||||
</FullWidthLayout>
|
||||
</template>
|
||||
|
||||
@@ -202,6 +214,7 @@ import { message } from 'ant-design-vue'
|
||||
import FullWidthLayout from '@/layouts/components/FullWidthLayout.vue'
|
||||
import ChatDrawer from '@/components/agents/ChatDrawer.vue'
|
||||
import HistoryPanel from '@/components/agents/HistoryPanel.vue'
|
||||
import MyFavoritesModal from '@/components/agents/MyFavoritesModal.vue'
|
||||
import { getAgentList, addFavorite, removeFavorite } from '@/api/agent'
|
||||
|
||||
// 状态管理
|
||||
@@ -216,6 +229,7 @@ const showCategoryPanel = ref(false)
|
||||
const panelTop = ref(0)
|
||||
const historyPanelVisible = ref(false)
|
||||
const historyAgentId = ref(null)
|
||||
const showFavoritesModal = ref(false)
|
||||
|
||||
// 面板样式
|
||||
const panelStyle = computed(() => ({
|
||||
@@ -385,6 +399,15 @@ const handleFavorite = async (agent) => {
|
||||
}
|
||||
}
|
||||
|
||||
// 收藏被移除的回调
|
||||
const handleFavoriteRemoved = (agent) => {
|
||||
// 同步更新列表中的收藏状态
|
||||
const target = agentList.value.find(a => a.id === agent.id)
|
||||
if (target) {
|
||||
target.isFavorite = false
|
||||
}
|
||||
}
|
||||
|
||||
// 初始化
|
||||
onMounted(() => {
|
||||
fetchAgentList()
|
||||
@@ -459,14 +482,18 @@ onMounted(() => {
|
||||
// 搜索区域 - 核心焦点
|
||||
// ============================================
|
||||
.search-hero {
|
||||
max-width: 480px;
|
||||
max-width: 560px;
|
||||
margin: 0 auto 28px;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 12px;
|
||||
}
|
||||
|
||||
.search-input-group {
|
||||
position: relative;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
flex: 1;
|
||||
}
|
||||
|
||||
.search-icon {
|
||||
@@ -532,6 +559,46 @@ onMounted(() => {
|
||||
}
|
||||
}
|
||||
|
||||
// ============================================
|
||||
// 收藏按钮
|
||||
// ============================================
|
||||
.favorites-btn {
|
||||
flex-shrink: 0;
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
gap: 6px;
|
||||
padding: 0 16px;
|
||||
height: 52px;
|
||||
border: 1px solid var(--color-gray-300);
|
||||
border-radius: var(--radius-lg);
|
||||
background: var(--color-bg-card);
|
||||
cursor: pointer;
|
||||
transition: all var(--duration-fast);
|
||||
box-shadow: var(--shadow-sm);
|
||||
|
||||
&:hover {
|
||||
border-color: #f59e0b;
|
||||
background: #fffbeb;
|
||||
box-shadow: var(--shadow-md);
|
||||
}
|
||||
|
||||
&:active {
|
||||
transform: scale(0.98);
|
||||
}
|
||||
}
|
||||
|
||||
.favorites-btn-icon {
|
||||
font-size: 18px;
|
||||
color: #f59e0b;
|
||||
}
|
||||
|
||||
.favorites-btn-text {
|
||||
font-size: 14px;
|
||||
font-weight: 500;
|
||||
color: var(--color-gray-700);
|
||||
white-space: nowrap;
|
||||
}
|
||||
|
||||
// ============================================
|
||||
// 分类筛选 - 精简胶囊
|
||||
// ============================================
|
||||
|
||||
@@ -429,8 +429,6 @@ async function handleSmsLogin() {
|
||||
</script>
|
||||
|
||||
<style scoped lang="less">
|
||||
/* ========== 导入字体 ========== */
|
||||
@import url('https://fonts.googleapis.com/css2?family=Playfair+Display:wght@600;700&family=DM+Sans:wght@400;500;600&display=swap');
|
||||
|
||||
/* ========== CSS变量 ========== */
|
||||
@primary-gold: #D4A853;
|
||||
|
||||
@@ -2,8 +2,7 @@
|
||||
import { ref, watch } from 'vue'
|
||||
import { message } from 'ant-design-vue'
|
||||
import ChatMessageRendererV2 from '@/components/ChatMessageRendererV2.vue'
|
||||
import { ChatMessageApi } from '@/api/chat'
|
||||
import { streamChat } from '@/utils/streamChat'
|
||||
import { benchmarkAnalyzeStream } from '@/api/dify'
|
||||
|
||||
const props = withDefaults(defineProps<{
|
||||
visible: boolean
|
||||
@@ -52,35 +51,29 @@ async function generateBatchPrompt() {
|
||||
if (!props.mergedText || hasGenerated.value) return
|
||||
|
||||
hasGenerated.value = true
|
||||
const ctrl = new AbortController()
|
||||
|
||||
try {
|
||||
batchPromptGenerating.value = true
|
||||
const conversationId = await createConversation()
|
||||
|
||||
const aiContent = await streamChat({
|
||||
conversationId,
|
||||
await benchmarkAnalyzeStream({
|
||||
content: props.mergedText,
|
||||
onUpdate: (fullText: string) => {
|
||||
videoCount: props.textCount,
|
||||
ctrl,
|
||||
onMessage: (fullText: string) => {
|
||||
batchPrompt.value = fullText
|
||||
},
|
||||
enableTypewriter: true,
|
||||
typewriterSpeed: 10,
|
||||
typewriterBatchSize: 2,
|
||||
onComplete: () => {},
|
||||
onError: (error: Error) => {
|
||||
console.error('流式聊天错误:', error)
|
||||
console.error('对标分析错误:', error)
|
||||
message.error('AI生成失败,请稍后重试')
|
||||
},
|
||||
enableContext: false,
|
||||
enableWebSearch: false,
|
||||
timeout: 180000,
|
||||
attachmentUrls: []
|
||||
onComplete: (fullText: string) => {
|
||||
if (fullText && fullText !== batchPrompt.value) {
|
||||
batchPrompt.value = fullText
|
||||
}
|
||||
message.success(`批量分析完成:已基于 ${props.textCount} 个视频的文案生成综合提示词`)
|
||||
}
|
||||
})
|
||||
|
||||
if (aiContent && aiContent !== batchPrompt.value) {
|
||||
batchPrompt.value = aiContent
|
||||
}
|
||||
|
||||
message.success(`批量分析完成:已基于 ${props.textCount} 个视频的文案生成综合提示词`)
|
||||
} catch (error) {
|
||||
console.error('AI生成失败:', error)
|
||||
message.error('AI生成失败,请稍后重试')
|
||||
@@ -90,21 +83,6 @@ async function generateBatchPrompt() {
|
||||
}
|
||||
}
|
||||
|
||||
async function createConversation() {
|
||||
const createPayload = { roleId: 20 }
|
||||
const conversationResp = await ChatMessageApi.createChatConversationMy(createPayload)
|
||||
|
||||
const conversationId = conversationResp?.data
|
||||
? (typeof conversationResp.data === 'object' ? conversationResp.data.id : conversationResp.data)
|
||||
: null
|
||||
|
||||
if (!conversationId) {
|
||||
throw new Error('创建对话失败:未获取到 conversationId')
|
||||
}
|
||||
|
||||
return conversationId
|
||||
}
|
||||
|
||||
function handleClose() {
|
||||
emit('update:visible', false)
|
||||
}
|
||||
|
||||
@@ -195,7 +195,6 @@
|
||||
|
||||
<!-- 音色选择 -->
|
||||
<div class="input-section">
|
||||
<label class="input-label">选择音色</label>
|
||||
<VoiceSelector
|
||||
:synth-text="store.text"
|
||||
:speech-rate="store.speechRate"
|
||||
|
||||
@@ -4,11 +4,11 @@ import { message } from 'ant-design-vue'
|
||||
|
||||
import TikhubService, { InterfaceType, MethodType, ParamType } from '@/api/tikhub'
|
||||
import { rewriteStream } from '@/api/forecast'
|
||||
import { getAgentList } from '@/api/agent'
|
||||
import { useUserStore } from '@/stores/user'
|
||||
import { usePointsConfigStore } from '@/stores/pointsConfig'
|
||||
import { getVoiceText } from '@/hooks/web/useVoiceText'
|
||||
import { copyToClipboard } from '@/utils/clipboard'
|
||||
import StyleSelector from '@/components/StyleSelector.vue'
|
||||
|
||||
defineOptions({ name: 'ForecastView' })
|
||||
|
||||
@@ -47,22 +47,12 @@ const topicDetails = reactive({
|
||||
// 智能体列表
|
||||
const agentList = ref([])
|
||||
const loadingAgents = ref(false)
|
||||
const agentSearchKeyword = ref('')
|
||||
|
||||
// 当前选中的智能体
|
||||
const selectedAgent = ref(null)
|
||||
|
||||
// 过滤后的智能体列表
|
||||
const filteredAgentList = computed(() => {
|
||||
if (!agentSearchKeyword.value.trim()) {
|
||||
return agentList.value
|
||||
}
|
||||
const keyword = agentSearchKeyword.value.trim().toLowerCase()
|
||||
return agentList.value.filter(agent =>
|
||||
agent.name.toLowerCase().includes(keyword) ||
|
||||
(agent.description && agent.description.toLowerCase().includes(keyword))
|
||||
)
|
||||
})
|
||||
// 当前选中的风格类型
|
||||
const selectedStyleType = ref('agent')
|
||||
|
||||
// 工具函数
|
||||
function formatNumber(num) {
|
||||
@@ -99,7 +89,7 @@ async function copyContent() {
|
||||
}
|
||||
}
|
||||
|
||||
// 加载智能体列表
|
||||
// 加载智能体列表(保留用于其他逻辑)
|
||||
async function loadAgentList() {
|
||||
loadingAgents.value = true
|
||||
try {
|
||||
@@ -112,13 +102,9 @@ async function loadAgentList() {
|
||||
description: item.description,
|
||||
systemPrompt: item.systemPrompt,
|
||||
avatar: item.icon,
|
||||
categoryName: item.categoryName || '其他'
|
||||
categoryName: item.categoryName || '其他',
|
||||
isFavorite: item.isFavorite || false
|
||||
}))
|
||||
// 默认选中第一个
|
||||
if (agentList.value.length > 0 && !topicDetails.selectedAgentId) {
|
||||
topicDetails.selectedAgentId = agentList.value[0].id
|
||||
selectedAgent.value = agentList.value[0]
|
||||
}
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('加载智能体列表失败:', error)
|
||||
@@ -127,12 +113,28 @@ async function loadAgentList() {
|
||||
}
|
||||
}
|
||||
|
||||
// 处理智能体选择
|
||||
function handleAgentChange(agentId) {
|
||||
const agent = agentList.value.find(a => a.id === agentId)
|
||||
if (agent) {
|
||||
selectedAgent.value = agent
|
||||
topicDetails.selectedAgentId = agentId
|
||||
// 处理风格选择变化
|
||||
function handleStyleChange(data) {
|
||||
if (!data) {
|
||||
selectedAgent.value = null
|
||||
selectedStyleType.value = null
|
||||
return
|
||||
}
|
||||
|
||||
const { id, type, item } = data
|
||||
selectedStyleType.value = type
|
||||
topicDetails.selectedAgentId = id
|
||||
|
||||
if (type === 'agent') {
|
||||
// 选择的是智能体
|
||||
selectedAgent.value = item
|
||||
} else if (type === 'prompt') {
|
||||
// 选择的是用户风格
|
||||
selectedAgent.value = {
|
||||
id: item.id,
|
||||
name: item.name,
|
||||
systemPrompt: item.content
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -206,8 +208,8 @@ async function handleGenerate() {
|
||||
}
|
||||
}, 180000)
|
||||
|
||||
rewriteStream({
|
||||
agentId: selectedAgent.value.id,
|
||||
// 构建请求参数
|
||||
const requestOptions = {
|
||||
userText: topicDetails.copywriting.trim(),
|
||||
level: topicDetails.level,
|
||||
modelType: topicDetails.modelType,
|
||||
@@ -245,7 +247,18 @@ async function handleGenerate() {
|
||||
resolve()
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
// 根据风格类型设置参数
|
||||
if (selectedStyleType.value === 'prompt') {
|
||||
// 使用用户风格
|
||||
requestOptions.customSystemPrompt = selectedAgent.value.systemPrompt
|
||||
} else {
|
||||
// 使用智能体
|
||||
requestOptions.agentId = selectedAgent.value.id
|
||||
}
|
||||
|
||||
rewriteStream(requestOptions)
|
||||
})
|
||||
|
||||
generatedContent.value = fullText.trim()
|
||||
@@ -369,6 +382,7 @@ async function handleSearch() {
|
||||
|
||||
// 初始化
|
||||
onMounted(() => {
|
||||
// 加载智能体列表用于后续逻辑
|
||||
loadAgentList()
|
||||
pointsConfigStore.loadConfig()
|
||||
})
|
||||
@@ -537,25 +551,12 @@ onMounted(() => {
|
||||
<!-- 风格选择 -->
|
||||
<div class="form-block">
|
||||
<label>文案风格</label>
|
||||
<a-select
|
||||
v-model:value="topicDetails.selectedAgentId"
|
||||
<StyleSelector
|
||||
v-model="topicDetails.selectedAgentId"
|
||||
placeholder="选择风格"
|
||||
style="width: 100%"
|
||||
:loading="loadingAgents"
|
||||
show-search
|
||||
:filter-option="false"
|
||||
@change="handleAgentChange"
|
||||
@search="agentSearchKeyword = $event"
|
||||
>
|
||||
<a-select-option
|
||||
v-for="agent in filteredAgentList"
|
||||
:key="agent.id"
|
||||
:value="agent.id"
|
||||
>
|
||||
<span>{{ agent.name }}</span>
|
||||
<span class="agent-category">{{ agent.categoryName }}</span>
|
||||
</a-select-option>
|
||||
</a-select>
|
||||
storage-key="forecast_style"
|
||||
@change="handleStyleChange"
|
||||
/>
|
||||
</div>
|
||||
|
||||
<!-- 模式 & 幅度 -->
|
||||
|
||||
@@ -3,11 +3,13 @@ package cn.iocoder.yudao.module.tik.dify.controller;
|
||||
import cn.iocoder.yudao.framework.common.pojo.CommonResult;
|
||||
import cn.iocoder.yudao.framework.security.core.util.SecurityFrameworkUtils;
|
||||
import cn.iocoder.yudao.module.tik.dify.service.DifyService;
|
||||
import cn.iocoder.yudao.module.tik.dify.vo.DifyBenchmarkReqVO;
|
||||
import cn.iocoder.yudao.module.tik.dify.vo.DifyChatReqVO;
|
||||
import cn.iocoder.yudao.module.tik.dify.vo.DifyChatRespVO;
|
||||
import cn.iocoder.yudao.module.tik.dify.vo.DifyConversationListRespVO;
|
||||
import cn.iocoder.yudao.module.tik.dify.vo.DifyMessageListRespVO;
|
||||
import cn.iocoder.yudao.module.tik.dify.vo.ForecastRewriteReqVO;
|
||||
import cn.iocoder.yudao.module.tik.dify.vo.PromptAnalysisReqVO;
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
import io.swagger.v3.oas.annotations.Parameter;
|
||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
@@ -51,6 +53,20 @@ public class AppDifyController {
|
||||
.map(CommonResult::success);
|
||||
}
|
||||
|
||||
@PostMapping(value = "/benchmark/analyze", produces = MediaType.TEXT_EVENT_STREAM_VALUE)
|
||||
@Operation(summary = "对标分析(流式)")
|
||||
public Flux<CommonResult<DifyChatRespVO>> benchmarkAnalyzeStream(@Valid @RequestBody DifyBenchmarkReqVO reqVO) {
|
||||
return difyService.benchmarkAnalyzeStream(reqVO, getCurrentUserId())
|
||||
.map(CommonResult::success);
|
||||
}
|
||||
|
||||
@PostMapping(value = "/prompt/analysis", produces = MediaType.TEXT_EVENT_STREAM_VALUE)
|
||||
@Operation(summary = "提示词分析(流式)")
|
||||
public Flux<CommonResult<DifyChatRespVO>> promptAnalysisStream(@Valid @RequestBody PromptAnalysisReqVO reqVO) {
|
||||
return difyService.promptAnalysisStream(reqVO, getCurrentUserId())
|
||||
.map(CommonResult::success);
|
||||
}
|
||||
|
||||
@GetMapping("/conversations")
|
||||
@Operation(summary = "获取会话列表")
|
||||
@Parameter(name = "agentId", description = "智能体ID", required = true)
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
package cn.iocoder.yudao.module.tik.dify.service;
|
||||
|
||||
import cn.iocoder.yudao.module.tik.dify.vo.DifyBenchmarkReqVO;
|
||||
import cn.iocoder.yudao.module.tik.dify.vo.DifyChatReqVO;
|
||||
import cn.iocoder.yudao.module.tik.dify.vo.PromptAnalysisReqVO;
|
||||
import cn.iocoder.yudao.module.tik.dify.vo.DifyChatRespVO;
|
||||
import cn.iocoder.yudao.module.tik.dify.vo.DifyConversationListRespVO;
|
||||
import cn.iocoder.yudao.module.tik.dify.vo.DifyMessageListRespVO;
|
||||
@@ -32,6 +34,24 @@ public interface DifyService {
|
||||
*/
|
||||
Flux<DifyChatRespVO> rewriteStream(ForecastRewriteReqVO reqVO, String userId);
|
||||
|
||||
/**
|
||||
* 对标分析(流式)
|
||||
*
|
||||
* @param reqVO 请求参数
|
||||
* @param userId 用户ID
|
||||
* @return 流式响应
|
||||
*/
|
||||
Flux<DifyChatRespVO> benchmarkAnalyzeStream(DifyBenchmarkReqVO reqVO, String userId);
|
||||
|
||||
/**
|
||||
* 提示词分析(流式)
|
||||
*
|
||||
* @param reqVO 请求参数
|
||||
* @param userId 用户ID
|
||||
* @return 流式响应
|
||||
*/
|
||||
Flux<DifyChatRespVO> promptAnalysisStream(PromptAnalysisReqVO reqVO, String userId);
|
||||
|
||||
/**
|
||||
* 获取会话列表
|
||||
*
|
||||
|
||||
@@ -1,7 +1,9 @@
|
||||
package cn.iocoder.yudao.module.tik.dify.service;
|
||||
|
||||
import cn.iocoder.yudao.module.tik.dify.client.DifyClient;
|
||||
import cn.iocoder.yudao.module.tik.dify.vo.DifyBenchmarkReqVO;
|
||||
import cn.iocoder.yudao.module.tik.dify.vo.DifyChatReqVO;
|
||||
import cn.iocoder.yudao.module.tik.dify.vo.PromptAnalysisReqVO;
|
||||
import cn.iocoder.yudao.module.tik.dify.vo.DifyChatRespVO;
|
||||
import cn.iocoder.yudao.module.tik.dify.vo.DifyConversationListRespVO;
|
||||
import cn.iocoder.yudao.module.tik.dify.vo.DifyMessageListRespVO;
|
||||
@@ -181,10 +183,23 @@ public class DifyServiceImpl implements DifyService {
|
||||
String difyUserId = "user-" + userId;
|
||||
|
||||
return Mono.fromCallable(() -> {
|
||||
// 1. 获取智能体配置(通过 agentId 获取 systemPrompt)
|
||||
AiAgentDO agent = aiAgentService.getAiAgent(reqVO.getAgentId());
|
||||
if (agent == null) {
|
||||
throw new RuntimeException("智能体不存在");
|
||||
// 1. 获取系统提示词
|
||||
String systemPrompt;
|
||||
if (reqVO.getCustomSystemPrompt() != null && !reqVO.getCustomSystemPrompt().isEmpty()) {
|
||||
// 使用自定义系统提示词(用户风格)
|
||||
systemPrompt = reqVO.getCustomSystemPrompt();
|
||||
log.info("[rewriteStream] 使用自定义系统提示词,长度: {}", systemPrompt.length());
|
||||
} else if (reqVO.getAgentId() != null) {
|
||||
// 从智能体获取系统提示词
|
||||
AiAgentDO agent = aiAgentService.getAiAgent(reqVO.getAgentId());
|
||||
if (agent == null) {
|
||||
throw new RuntimeException("智能体不存在");
|
||||
}
|
||||
systemPrompt = agent.getSystemPrompt();
|
||||
log.info("[rewriteStream] 使用智能体系统提示词,agentId: {}, 长度: {}",
|
||||
reqVO.getAgentId(), systemPrompt != null ? systemPrompt.length() : 0);
|
||||
} else {
|
||||
throw new RuntimeException("必须提供 agentId 或 customSystemPrompt");
|
||||
}
|
||||
|
||||
// 2. 根据 modelType 获取对应的积分配置
|
||||
@@ -208,17 +223,14 @@ public class DifyServiceImpl implements DifyService {
|
||||
);
|
||||
pendingRecordId.set(recordId);
|
||||
|
||||
// 5. 构建 inputs 参数(使用 agent 的 systemPrompt)
|
||||
// 5. 构建 inputs 参数
|
||||
Map<String, Object> inputs = new HashMap<>();
|
||||
inputs.put("sysPrompt", agent.getSystemPrompt());
|
||||
inputs.put("sysPrompt", systemPrompt);
|
||||
inputs.put("userText", reqVO.getUserText());
|
||||
inputs.put("level", reqVO.getLevel());
|
||||
|
||||
// 调试日志
|
||||
log.info("[rewriteStream] 请求参数 - agentId: {}, modelType: {}", reqVO.getAgentId(), reqVO.getModelType());
|
||||
log.info("[rewriteStream] Agent信息 - id: {}, name: {}, systemPrompt长度: {}",
|
||||
agent.getId(), agent.getAgentName(),
|
||||
agent.getSystemPrompt() != null ? agent.getSystemPrompt().length() : 0);
|
||||
log.info("[rewriteStream] inputs参数 - userText长度: {}, level: {}",
|
||||
reqVO.getUserText() != null ? reqVO.getUserText().length() : 0,
|
||||
reqVO.getLevel());
|
||||
@@ -324,6 +336,323 @@ public class DifyServiceImpl implements DifyService {
|
||||
*/
|
||||
private record ForecastRewriteContext(Map<String, Object> inputs, String apiKey, Integer consumePoints) {}
|
||||
|
||||
@Override
|
||||
public Flux<DifyChatRespVO> benchmarkAnalyzeStream(DifyBenchmarkReqVO reqVO, String userId) {
|
||||
// 用于存储预扣记录ID
|
||||
AtomicLong pendingRecordId = new AtomicLong();
|
||||
// 用于存储会话ID
|
||||
AtomicReference<String> conversationIdRef = new AtomicReference<>("");
|
||||
// 用于存储 token 使用信息
|
||||
AtomicReference<DifyChatRespVO> tokenUsageRef = new AtomicReference<>();
|
||||
// Dify 用户标识(固定格式)
|
||||
String difyUserId = "user-" + userId;
|
||||
|
||||
return Mono.fromCallable(() -> {
|
||||
// 1. 获取积分配置
|
||||
AiServiceConfigDO config = pointsService.getConfig(
|
||||
AiPlatformEnum.DIFY.getPlatform(),
|
||||
AiModelTypeEnum.BENCHMARK_ANALYZE.getModelCode());
|
||||
|
||||
// 2. 预检积分
|
||||
pointsService.checkPoints(userId, config.getConsumePoints());
|
||||
|
||||
// 3. 创建预扣记录(带 serviceCode)
|
||||
Long recordId = pointsService.createPendingDeduct(
|
||||
userId,
|
||||
config.getConsumePoints(),
|
||||
"benchmark_analyze",
|
||||
String.valueOf(reqVO.getVideoCount()),
|
||||
config.getServiceCode()
|
||||
);
|
||||
pendingRecordId.set(recordId);
|
||||
|
||||
// 4. 构建对标分析提示词
|
||||
String benchmarkPrompt = buildBenchmarkPrompt(reqVO.getContent(), reqVO.getVideoCount());
|
||||
|
||||
log.info("[benchmarkAnalyzeStream] 请求参数 - videoCount: {}", reqVO.getVideoCount());
|
||||
log.info("[benchmarkAnalyzeStream] 提示词长度: {}", benchmarkPrompt.length());
|
||||
log.info("[benchmarkAnalyzeStream] API配置 - apiKey前缀: {}..., consumePoints: {}",
|
||||
config.getApiKey() != null && config.getApiKey().length() > 10
|
||||
? config.getApiKey().substring(0, 10) + "***"
|
||||
: "null",
|
||||
config.getConsumePoints());
|
||||
|
||||
// 5. 返回调用参数
|
||||
return new BenchmarkAnalyzeContext(benchmarkPrompt, config.getApiKey(), config.getConsumePoints());
|
||||
})
|
||||
.flatMapMany(context -> {
|
||||
// 6. 调用 Dify 流式 API
|
||||
return difyClient.chatStream(
|
||||
context.apiKey(),
|
||||
context.prompt(),
|
||||
null, // systemPrompt 为空,使用 Dify 工作流中的配置
|
||||
null, // conversationId 为空,新会话
|
||||
difyUserId
|
||||
)
|
||||
.doOnNext(resp -> {
|
||||
if (resp.getConversationId() != null) {
|
||||
conversationIdRef.set(resp.getConversationId());
|
||||
}
|
||||
// 捕获 token 使用信息
|
||||
if (resp.getTotalTokens() != null && resp.getTotalTokens() > 0) {
|
||||
tokenUsageRef.set(resp);
|
||||
}
|
||||
})
|
||||
// 7. 流结束时确认扣费(带 token)
|
||||
.doOnComplete(() -> {
|
||||
if (pendingRecordId.get() > 0) {
|
||||
try {
|
||||
DifyChatRespVO tokenUsage = tokenUsageRef.get();
|
||||
if (tokenUsage != null) {
|
||||
pointsService.confirmPendingDeductWithTokens(
|
||||
pendingRecordId.get(),
|
||||
tokenUsage.getInputTokens(),
|
||||
tokenUsage.getOutputTokens(),
|
||||
tokenUsage.getTotalTokens()
|
||||
);
|
||||
log.info("[benchmarkAnalyzeStream] 流结束,确认扣费(带token),记录ID: {}, tokens: {}",
|
||||
pendingRecordId.get(), tokenUsage.getTotalTokens());
|
||||
} else {
|
||||
pointsService.confirmPendingDeduct(pendingRecordId.get());
|
||||
log.info("[benchmarkAnalyzeStream] 流结束,确认扣费(无token),记录ID: {}", pendingRecordId.get());
|
||||
}
|
||||
} catch (Exception e) {
|
||||
log.error("[benchmarkAnalyzeStream] 确认扣费失败", e);
|
||||
}
|
||||
}
|
||||
})
|
||||
// 8. 流出错时取消预扣
|
||||
.doOnError(e -> {
|
||||
if (pendingRecordId.get() > 0) {
|
||||
try {
|
||||
pointsService.cancelPendingDeduct(pendingRecordId.get());
|
||||
log.info("[benchmarkAnalyzeStream] 流出错,取消预扣,记录ID: {}", pendingRecordId.get());
|
||||
} catch (Exception ex) {
|
||||
log.error("[benchmarkAnalyzeStream] 取消预扣失败", ex);
|
||||
}
|
||||
}
|
||||
})
|
||||
// 9. 用户取消时确认扣费(已消费的部分)
|
||||
.doOnCancel(() -> {
|
||||
if (pendingRecordId.get() > 0) {
|
||||
try {
|
||||
// 用户主动取消,仍然扣费(按最低消费)
|
||||
pointsService.confirmPendingDeduct(pendingRecordId.get());
|
||||
log.info("[benchmarkAnalyzeStream] 用户取消,确认扣费,记录ID: {}", pendingRecordId.get());
|
||||
} catch (Exception e) {
|
||||
log.error("[benchmarkAnalyzeStream] 用户取消后扣费失败", e);
|
||||
}
|
||||
}
|
||||
});
|
||||
})
|
||||
// 10. 在最后添加 done 事件
|
||||
.concatWith(Mono.defer(() -> {
|
||||
DifyChatRespVO tokenUsage = tokenUsageRef.get();
|
||||
if (tokenUsage != null) {
|
||||
return Mono.just(DifyChatRespVO.doneWithTokens(
|
||||
conversationIdRef.get(), null,
|
||||
tokenUsage.getInputTokens(),
|
||||
tokenUsage.getOutputTokens(),
|
||||
tokenUsage.getTotalTokens()
|
||||
));
|
||||
}
|
||||
return Mono.just(DifyChatRespVO.done(conversationIdRef.get(), null));
|
||||
}))
|
||||
.onErrorResume(e -> {
|
||||
log.error("[benchmarkAnalyzeStream] 对标分析异常", e);
|
||||
return Flux.just(DifyChatRespVO.error(e.getMessage()));
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* 构建对标分析提示词
|
||||
*/
|
||||
private String buildBenchmarkPrompt(String content, Integer videoCount) {
|
||||
return String.format("""
|
||||
请分析以下 %d 个爆款视频的文案,提取出它们的共同特点和创作风格,生成一个综合的文案创作提示词。
|
||||
|
||||
文案内容:
|
||||
%s
|
||||
|
||||
请从以下维度进行分析:
|
||||
1. 文案结构和节奏
|
||||
2. 常用的表达方式和句式
|
||||
3. 情感调动技巧
|
||||
4. 互动引导方式
|
||||
5. 关键词和热词使用
|
||||
|
||||
请生成一个可以直接用于文案创作的提示词,格式要求:
|
||||
- 清晰描述这种文案风格的核心特点
|
||||
- 包含具体的写作指导
|
||||
- 适合作为 AI 写作的 system prompt
|
||||
""", videoCount, content);
|
||||
}
|
||||
|
||||
/**
|
||||
* 对标分析上下文
|
||||
*/
|
||||
private record BenchmarkAnalyzeContext(String prompt, String apiKey, Integer consumePoints) {}
|
||||
|
||||
@Override
|
||||
public Flux<DifyChatRespVO> promptAnalysisStream(PromptAnalysisReqVO reqVO, String userId) {
|
||||
// 用于存储预扣记录ID
|
||||
AtomicLong pendingRecordId = new AtomicLong();
|
||||
// 用于存储会话ID
|
||||
AtomicReference<String> conversationIdRef = new AtomicReference<>("");
|
||||
// 用于存储 token 使用信息
|
||||
AtomicReference<DifyChatRespVO> tokenUsageRef = new AtomicReference<>();
|
||||
// Dify 用户标识(固定格式)
|
||||
String difyUserId = "user-" + userId;
|
||||
|
||||
return Mono.fromCallable(() -> {
|
||||
// 1. 获取积分配置
|
||||
AiServiceConfigDO config = pointsService.getConfig(
|
||||
AiPlatformEnum.DIFY.getPlatform(),
|
||||
AiModelTypeEnum.PROMPT_ANALYSIS.getModelCode());
|
||||
|
||||
// 2. 预检积分
|
||||
pointsService.checkPoints(userId, config.getConsumePoints());
|
||||
|
||||
// 3. 创建预扣记录(带 serviceCode)
|
||||
Long recordId = pointsService.createPendingDeduct(
|
||||
userId,
|
||||
config.getConsumePoints(),
|
||||
"prompt_analysis",
|
||||
String.valueOf(reqVO.getVideoCount()),
|
||||
config.getServiceCode()
|
||||
);
|
||||
pendingRecordId.set(recordId);
|
||||
|
||||
// 4. 构建提示词分析 prompt
|
||||
String analysisPrompt = buildPromptAnalysisPrompt(reqVO.getContent(), reqVO.getVideoCount());
|
||||
|
||||
log.info("[promptAnalysisStream] 请求参数 - videoCount: {}", reqVO.getVideoCount());
|
||||
log.info("[promptAnalysisStream] 提示词长度: {}", analysisPrompt.length());
|
||||
log.info("[promptAnalysisStream] API配置 - apiKey前缀: {}..., consumePoints: {}",
|
||||
config.getApiKey() != null && config.getApiKey().length() > 10
|
||||
? config.getApiKey().substring(0, 10) + "***"
|
||||
: "null",
|
||||
config.getConsumePoints());
|
||||
|
||||
// 5. 返回调用参数
|
||||
return new PromptAnalysisContext(analysisPrompt, config.getApiKey(), config.getConsumePoints());
|
||||
})
|
||||
.flatMapMany(context -> {
|
||||
// 6. 调用 Dify 流式 API
|
||||
return difyClient.chatStream(
|
||||
context.apiKey(),
|
||||
context.prompt(),
|
||||
null, // systemPrompt 为空,使用 Dify 工作流中的配置
|
||||
null, // conversationId 为空,新会话
|
||||
difyUserId
|
||||
)
|
||||
.doOnNext(resp -> {
|
||||
if (resp.getConversationId() != null) {
|
||||
conversationIdRef.set(resp.getConversationId());
|
||||
}
|
||||
// 捕获 token 使用信息
|
||||
if (resp.getTotalTokens() != null && resp.getTotalTokens() > 0) {
|
||||
tokenUsageRef.set(resp);
|
||||
}
|
||||
})
|
||||
// 7. 流结束时确认扣费(带 token)
|
||||
.doOnComplete(() -> {
|
||||
if (pendingRecordId.get() > 0) {
|
||||
try {
|
||||
DifyChatRespVO tokenUsage = tokenUsageRef.get();
|
||||
if (tokenUsage != null) {
|
||||
pointsService.confirmPendingDeductWithTokens(
|
||||
pendingRecordId.get(),
|
||||
tokenUsage.getInputTokens(),
|
||||
tokenUsage.getOutputTokens(),
|
||||
tokenUsage.getTotalTokens()
|
||||
);
|
||||
log.info("[promptAnalysisStream] 流结束,确认扣费(带token),记录ID: {}, tokens: {}",
|
||||
pendingRecordId.get(), tokenUsage.getTotalTokens());
|
||||
} else {
|
||||
pointsService.confirmPendingDeduct(pendingRecordId.get());
|
||||
log.info("[promptAnalysisStream] 流结束,确认扣费(无token),记录ID: {}", pendingRecordId.get());
|
||||
}
|
||||
} catch (Exception e) {
|
||||
log.error("[promptAnalysisStream] 确认扣费失败", e);
|
||||
}
|
||||
}
|
||||
})
|
||||
// 8. 流出错时取消预扣
|
||||
.doOnError(e -> {
|
||||
if (pendingRecordId.get() > 0) {
|
||||
try {
|
||||
pointsService.cancelPendingDeduct(pendingRecordId.get());
|
||||
log.info("[promptAnalysisStream] 流出错,取消预扣,记录ID: {}", pendingRecordId.get());
|
||||
} catch (Exception ex) {
|
||||
log.error("[promptAnalysisStream] 取消预扣失败", ex);
|
||||
}
|
||||
}
|
||||
})
|
||||
// 9. 用户取消时确认扣费(已消费的部分)
|
||||
.doOnCancel(() -> {
|
||||
if (pendingRecordId.get() > 0) {
|
||||
try {
|
||||
// 用户主动取消,仍然扣费(按最低消费)
|
||||
pointsService.confirmPendingDeduct(pendingRecordId.get());
|
||||
log.info("[promptAnalysisStream] 用户取消,确认扣费,记录ID: {}", pendingRecordId.get());
|
||||
} catch (Exception e) {
|
||||
log.error("[promptAnalysisStream] 用户取消后扣费失败", e);
|
||||
}
|
||||
}
|
||||
});
|
||||
})
|
||||
// 10. 在最后添加 done 事件
|
||||
.concatWith(Mono.defer(() -> {
|
||||
DifyChatRespVO tokenUsage = tokenUsageRef.get();
|
||||
if (tokenUsage != null) {
|
||||
return Mono.just(DifyChatRespVO.doneWithTokens(
|
||||
conversationIdRef.get(), null,
|
||||
tokenUsage.getInputTokens(),
|
||||
tokenUsage.getOutputTokens(),
|
||||
tokenUsage.getTotalTokens()
|
||||
));
|
||||
}
|
||||
return Mono.just(DifyChatRespVO.done(conversationIdRef.get(), null));
|
||||
}))
|
||||
.onErrorResume(e -> {
|
||||
log.error("[promptAnalysisStream] 提示词分析异常", e);
|
||||
return Flux.just(DifyChatRespVO.error(e.getMessage()));
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* 构建提示词分析 prompt
|
||||
*/
|
||||
private String buildPromptAnalysisPrompt(String content, Integer videoCount) {
|
||||
return String.format("""
|
||||
请分析以下 %d 个爆款视频的文案,提取出它们的共同特点和创作风格,生成一个可以直接用于 AI 写作的系统提示词。
|
||||
|
||||
文案内容:
|
||||
%s
|
||||
|
||||
请从以下维度进行深度分析:
|
||||
1. 文案结构和节奏特点
|
||||
2. 常用的表达方式和句式模板
|
||||
3. 情感调动和共鸣技巧
|
||||
4. 互动引导和行动号召
|
||||
5. 关键词、热词和流行语使用
|
||||
6. 开头和结尾的特点
|
||||
|
||||
输出要求:
|
||||
- 生成一个完整的系统提示词(System Prompt)
|
||||
- 提示词应该清晰描述这种文案风格的核心特点
|
||||
- 包含具体的写作指导和格式要求
|
||||
- 适合直接作为 AI 写作的系统指令
|
||||
- 使用专业但易懂的语言
|
||||
""", videoCount != null ? videoCount : 1, content);
|
||||
}
|
||||
|
||||
/**
|
||||
* 提示词分析上下文
|
||||
*/
|
||||
private record PromptAnalysisContext(String prompt, String apiKey, Integer consumePoints) {}
|
||||
|
||||
@Override
|
||||
public DifyConversationListRespVO getConversations(Long agentId, String userId, String lastId, Integer limit) {
|
||||
// 获取智能体配置
|
||||
|
||||
@@ -0,0 +1,23 @@
|
||||
package cn.iocoder.yudao.module.tik.dify.vo;
|
||||
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import jakarta.validation.constraints.NotEmpty;
|
||||
import jakarta.validation.constraints.NotNull;
|
||||
import lombok.Data;
|
||||
|
||||
/**
|
||||
* 对标分析请求 VO
|
||||
*/
|
||||
@Schema(description = "对标分析请求")
|
||||
@Data
|
||||
public class DifyBenchmarkReqVO {
|
||||
|
||||
@Schema(description = "合并后的文案内容", requiredMode = Schema.RequiredMode.REQUIRED)
|
||||
@NotEmpty(message = "文案内容不能为空")
|
||||
private String content;
|
||||
|
||||
@Schema(description = "视频数量", requiredMode = Schema.RequiredMode.REQUIRED)
|
||||
@NotNull(message = "视频数量不能为空")
|
||||
private Integer videoCount;
|
||||
|
||||
}
|
||||
@@ -2,7 +2,6 @@ package cn.iocoder.yudao.module.tik.dify.vo;
|
||||
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import jakarta.validation.constraints.NotEmpty;
|
||||
import jakarta.validation.constraints.NotNull;
|
||||
import lombok.Data;
|
||||
|
||||
/**
|
||||
@@ -12,8 +11,7 @@ import lombok.Data;
|
||||
@Data
|
||||
public class ForecastRewriteReqVO {
|
||||
|
||||
@Schema(description = "智能体ID", requiredMode = Schema.RequiredMode.REQUIRED)
|
||||
@NotNull(message = "智能体ID不能为空")
|
||||
@Schema(description = "智能体ID(使用用户风格时可为空)")
|
||||
private Long agentId;
|
||||
|
||||
@Schema(description = "用户输入文案", requiredMode = Schema.RequiredMode.REQUIRED)
|
||||
@@ -26,4 +24,7 @@ public class ForecastRewriteReqVO {
|
||||
@Schema(description = "模型类型:forecast_standard-标准版 forecast_pro-pro版", example = "forecast_standard")
|
||||
private String modelType = "forecast_standard";
|
||||
|
||||
@Schema(description = "自定义系统提示词(使用用户风格时传入)")
|
||||
private String customSystemPrompt;
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,21 @@
|
||||
package cn.iocoder.yudao.module.tik.dify.vo;
|
||||
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import jakarta.validation.constraints.NotEmpty;
|
||||
import lombok.Data;
|
||||
|
||||
/**
|
||||
* 提示词分析请求 VO
|
||||
*/
|
||||
@Schema(description = "提示词分析请求")
|
||||
@Data
|
||||
public class PromptAnalysisReqVO {
|
||||
|
||||
@Schema(description = "合并后的文案内容", requiredMode = Schema.RequiredMode.REQUIRED)
|
||||
@NotEmpty(message = "文案内容不能为空")
|
||||
private String content;
|
||||
|
||||
@Schema(description = "视频数量", requiredMode = Schema.RequiredMode.REQUIRED)
|
||||
private Integer videoCount;
|
||||
|
||||
}
|
||||
@@ -24,6 +24,12 @@ public enum AiModelTypeEnum implements ArrayValuable<String> {
|
||||
FORECAST_STANDARD("forecast_standard", "文案改写-标准版", AiPlatformEnum.DIFY, "text"),
|
||||
FORECAST_PRO("forecast_pro", "文案改写-Pro版", AiPlatformEnum.DIFY, "text"),
|
||||
|
||||
// ========== 对标分析 ==========
|
||||
BENCHMARK_ANALYZE("benchmark_analyze", "对标分析", AiPlatformEnum.DIFY, "text"),
|
||||
|
||||
// ========== 提示词分析 ==========
|
||||
PROMPT_ANALYSIS("prompt_analysis", "提示词分析", AiPlatformEnum.DIFY, "text"),
|
||||
|
||||
// ========== 数字人模型 ==========
|
||||
DIGITAL_HUMAN_LATENTSYNC("latentsync", "LatentSync", AiPlatformEnum.DIGITAL_HUMAN, "video"),
|
||||
DIGITAL_HUMAN_KLING("kling", "可灵", AiPlatformEnum.DIGITAL_HUMAN, "video"),
|
||||
|
||||
@@ -107,5 +107,13 @@ public class AppUserPromptController {
|
||||
PageResult<UserPromptDO> pageResult = userPromptService.getUserPromptPage(pageReqVO);
|
||||
return success(BeanUtils.toBean(pageResult, UserPromptRespVO.class));
|
||||
}
|
||||
|
||||
@GetMapping("/list")
|
||||
@Operation(summary = "获得用户提示词列表(简化版)")
|
||||
public CommonResult<java.util.List<UserPromptRespVO>> getUserPromptList() {
|
||||
// 只查询当前用户的提示词
|
||||
java.util.List<UserPromptDO> list = userPromptService.getUserPromptListByUserId(getLoginUserId());
|
||||
return success(BeanUtils.toBean(list, UserPromptRespVO.class));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -7,6 +7,8 @@ import cn.iocoder.yudao.module.tik.userprompt.vo.UserPromptDO;
|
||||
import cn.iocoder.yudao.module.tik.userprompt.vo.UserPromptPageReqVO;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 用户提示词 Mapper
|
||||
*
|
||||
@@ -30,4 +32,12 @@ public interface UserPromptMapper extends BaseMapperX<UserPromptDO> {
|
||||
.orderByDesc(UserPromptDO::getId));
|
||||
}
|
||||
|
||||
default List<UserPromptDO> selectList(Long userId) {
|
||||
return selectList(new LambdaQueryWrapperX<UserPromptDO>()
|
||||
.eq(UserPromptDO::getUserId, userId)
|
||||
.eq(UserPromptDO::getStatus, 1)
|
||||
.orderByDesc(UserPromptDO::getSort)
|
||||
.orderByDesc(UserPromptDO::getId));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -60,4 +60,12 @@ public interface UserPromptService {
|
||||
*/
|
||||
PageResult<UserPromptDO> getUserPromptPage(UserPromptPageReqVO pageReqVO);
|
||||
|
||||
/**
|
||||
* 根据用户ID获取用户提示词列表
|
||||
*
|
||||
* @param userId 用户ID
|
||||
* @return 用户提示词列表
|
||||
*/
|
||||
List<UserPromptDO> getUserPromptListByUserId(Long userId);
|
||||
|
||||
}
|
||||
|
||||
@@ -92,4 +92,9 @@ public class UserPromptServiceImpl implements UserPromptService {
|
||||
public PageResult<UserPromptDO> getUserPromptPage(UserPromptPageReqVO pageReqVO) {
|
||||
return userPromptMapper.selectPage(pageReqVO);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<UserPromptDO> getUserPromptListByUserId(Long userId) {
|
||||
return userPromptMapper.selectList(userId);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user