限制绘画提示词长度,修复移动端角色和模型绑定失败问题

This commit is contained in:
RockYang
2025-02-23 06:56:38 +08:00
parent 63fd125439
commit a3f0576535
17 changed files with 91 additions and 17 deletions

View File

@@ -3,8 +3,10 @@
## v4.2.1
- 功能新增:新增支持可灵生成视频。
- Bug修复修复移动端聊天页面新建对话时候角色没有更模型绑定的 Bug。
- 功能优化:优化聊天页面代码块样式,优化公式的解析。
- Bug 修复:优化 Redis 连接池配置,增加连接池超时时间,单核服务器报错 `redis: connection pool timeout`
- 功能优化:在绘图,视频相关 API 增加提示词长度的检查,防止提示词超出导致写入数据库失败
- Bug修复优化 Redis 连接池配置,增加连接池超时时间,单核服务器报错 `redis: connection pool timeout`
## v4.2.0

View File

@@ -56,6 +56,11 @@ func (h *DallJobHandler) Image(c *gin.Context) {
return
}
if len(data.Prompt) > 2000 {
resp.ERROR(c, "提示词太长,请删减提示词。")
return
}
// 检查用户剩余算力
user, err := h.GetLoginUser(c)
if err != nil {

View File

@@ -91,6 +91,11 @@ func (h *MidJourneyHandler) Image(c *gin.Context) {
return
}
if len(data.Prompt) > 2000 {
resp.ERROR(c, "提示词太长,请删减提示词。")
return
}
var params = ""
if data.Rate != "" && !strings.Contains(params, "--ar") {
params += " --ar " + data.Rate

View File

@@ -56,11 +56,15 @@ func (h *PromptHandler) Lyric(c *gin.Context) {
if h.App.SysConfig.PromptPower > 0 {
userId := h.GetLoginUserId(c)
h.userService.DecreasePower(int(userId), h.App.SysConfig.PromptPower, model.PowerLog{
err = h.userService.DecreasePower(int(userId), h.App.SysConfig.PromptPower, model.PowerLog{
Type: types.PowerConsume,
Model: h.getPromptModel(),
Remark: "生成歌词",
})
if err != nil {
resp.ERROR(c, err.Error())
return
}
}
resp.SUCCESS(c, content)
@@ -82,11 +86,15 @@ func (h *PromptHandler) Image(c *gin.Context) {
}
if h.App.SysConfig.PromptPower > 0 {
userId := h.GetLoginUserId(c)
h.userService.DecreasePower(int(userId), h.App.SysConfig.PromptPower, model.PowerLog{
err = h.userService.DecreasePower(int(userId), h.App.SysConfig.PromptPower, model.PowerLog{
Type: types.PowerConsume,
Model: h.getPromptModel(),
Remark: "生成绘画提示词",
})
if err != nil {
resp.ERROR(c, err.Error())
return
}
}
resp.SUCCESS(c, strings.Trim(content, `"`))
}
@@ -108,11 +116,15 @@ func (h *PromptHandler) Video(c *gin.Context) {
if h.App.SysConfig.PromptPower > 0 {
userId := h.GetLoginUserId(c)
h.userService.DecreasePower(int(userId), h.App.SysConfig.PromptPower, model.PowerLog{
err = h.userService.DecreasePower(int(userId), h.App.SysConfig.PromptPower, model.PowerLog{
Type: types.PowerConsume,
Model: h.getPromptModel(),
Remark: "生成视频脚本",
})
if err != nil {
resp.ERROR(c, err.Error())
return
}
}
resp.SUCCESS(c, strings.Trim(content, `"`))

View File

@@ -102,6 +102,10 @@ func (h *SdJobHandler) Image(c *gin.Context) {
if data.Sampler == "" {
data.Sampler = "Euler a"
}
if len(data.Prompt) > 2000 {
resp.ERROR(c, "提示词太长,请删减提示词。")
return
}
idValue, _ := c.Get(types.LoginUserID)
userId := utils.IntValue(utils.InterfaceToString(idValue), 0)
taskId, err := h.snowflake.Next(true)

View File

@@ -56,6 +56,15 @@ func (h *VideoHandler) LumaCreate(c *gin.Context) {
resp.ERROR(c, types.InvalidArgs)
return
}
// 检查 Prompt 长度
if data.Prompt == "" {
resp.ERROR(c, "prompt is needed")
return
}
if len(data.Prompt) > 2000 {
resp.ERROR(c, "提示词太长,请删减提示词。")
return
}
user, err := h.GetLoginUser(c)
if err != nil {
@@ -68,11 +77,6 @@ func (h *VideoHandler) LumaCreate(c *gin.Context) {
return
}
if data.Prompt == "" {
resp.ERROR(c, "prompt is needed")
return
}
userId := int(h.GetLoginUserId(c))
params := types.LumaVideoParams{
PromptOptimize: data.ExpandPrompt,
@@ -156,6 +160,10 @@ func (h *VideoHandler) KeLingCreate(c *gin.Context) {
resp.ERROR(c, "prompt is needed")
return
}
if len(data.Prompt) > 2000 {
resp.ERROR(c, "提示词太长,请删减提示词。")
return
}
userId := int(h.GetLoginUserId(c))
params := types.KeLingVideoParams{

View File

@@ -54,7 +54,7 @@ Here is an example of how the final prompt should look:
- Mood: Intense, mysterious
- Lighting: Dramatic contrast with light filtering through leaves
**Output Prompt**: "A realistic rendering of a white tiger stealthily moving through a dense jungle, with an intense, mysterious mood. The lighting creates strong contrasts as beams of sunlight filter through a thick canopy of leaves."
**Output Prompt**: "A realistic rendering of a white tiger, stealthily moving through a dense jungle, with an intense, mysterious mood. The lighting creates strong contrasts as beams of sunlight filter through a thick canopy of leaves."
2. **Input**:
- Subject: An enchanted castle on a floating island

View File

@@ -244,7 +244,7 @@ export function showLoginDialog(router) {
export const replaceImg = (img) => {
if (!img.startsWith("http")) {
img = `${location.protocol}//${location.host}/${img}`;
img = `${location.protocol}//${location.host}${img}`;
}
const devHost = process.env.VUE_APP_API_HOST;
const localhost = "http://localhost:5678";

View File

@@ -66,6 +66,7 @@
:autosize="{ minRows: 4, maxRows: 6 }"
type="textarea"
ref="promptRef"
maxlength="2000"
placeholder="请在此输入绘画提示词,您也可以点击下面的提示词助手生成绘画提示词"
v-loading="isGenerating"
/>

View File

@@ -175,6 +175,7 @@
<el-input
v-model="params.prompt"
:autosize="{ minRows: 4, maxRows: 6 }"
maxlength="2000"
type="textarea"
ref="promptRef"
v-loading="isGenerating"
@@ -208,6 +209,7 @@
:autosize="{ minRows: 4, maxRows: 6 }"
type="textarea"
ref="promptRef"
maxlength="2000"
placeholder="请在此输入你不希望出现在图片上的内容,系统会自动翻译中文提示词"
/>
</div>

View File

@@ -194,6 +194,7 @@
:autosize="{ minRows: 4, maxRows: 6 }"
type="textarea"
ref="promptRef"
maxlength="2000"
placeholder="请在此输入绘画提示词,您也可以点击下面的提示词助手生成绘画提示词"
v-loading="isGenerating"
/>

View File

@@ -19,7 +19,7 @@
<i class="iconfont icon-image"></i>
</el-upload>
</div>
<textarea class="prompt-input" :rows="row" v-model="formData.prompt" placeholder="请输入提示词或者上传图片" autofocus> </textarea>
<textarea class="prompt-input" :rows="row" v-model="formData.prompt" maxlength="2000" placeholder="请输入提示词或者上传图片" autofocus> </textarea>
<div class="send-icon" @click="create">
<i class="iconfont icon-send"></i>
</div>

View File

@@ -52,6 +52,7 @@
<van-picker
:columns="columns"
title="选择模型和角色"
@change="onChange"
@cancel="showPicker = false"
@confirm="newChat"
>
@@ -114,7 +115,8 @@ checkSession().then((user) => {
text: items[i].name,
value: items[i].id,
icon: items[i].icon,
helloMsg: items[i].hello_msg
helloMsg: items[i].hello_msg,
model_id: items[i].model_id
})
}
}
@@ -257,6 +259,19 @@ const removeChat = (item) => {
}
const onChange = (item) => {
const selectedValues = item.selectedOptions
if (selectedValues[0].model_id) {
for (let i = 0; i < columns.value[1].length; i++) {
columns.value[1][i].disabled = columns.value[1][i].value !== selectedValues[0].model_id;
}
} else {
for (let i = 0; i < columns.value[1].length; i++) {
columns.value[1][i].disabled = false;
}
}
}
</script>
<style lang="stylus" scoped>

View File

@@ -78,7 +78,10 @@
</div>
<van-popup v-model:show="showPicker" position="bottom" class="popup">
<van-picker :columns="columns" v-model="selectedValues" title="选择模型和角色" @cancel="showPicker = false" @confirm="newChat">
<van-picker :columns="columns" v-model="selectedValues"
title="选择模型和角色"
@change="onChange"
@cancel="showPicker = false" @confirm="newChat">
<template #option="item">
<div class="picker-option">
<van-image v-if="item.icon" :src="item.icon" fit="cover" round />
@@ -106,7 +109,6 @@ import { useSharedStore } from "@/store/sharedata";
import emoji from "markdown-it-emoji";
import mathjaxPlugin from "markdown-it-mathjax3";
import MarkdownIt from "markdown-it";
import FileList from "@/components/FileList.vue";
const winHeight = ref(0);
const navBarRef = ref(null);
const bottomBarRef = ref(null);
@@ -631,6 +633,19 @@ const getModelName = (model_id) => {
// showMic.value = false
// recognition.stop()
// }
const onChange = (item) => {
const selectedValues = item.selectedOptions
if (selectedValues[0].model_id) {
for (let i = 0; i < columns.value[1].length; i++) {
columns.value[1][i].disabled = columns.value[1][i].value !== selectedValues[0].model_id;
}
} else {
for (let i = 0; i < columns.value[1].length; i++) {
columns.value[1][i].disabled = false;
}
}
}
</script>
<style lang="stylus">

View File

@@ -33,6 +33,7 @@
v-model="params.prompt"
rows="3"
autosize
maxlength="2000"
type="textarea"
placeholder="请在此输入绘画提示词,系统会自动翻译中文提示词,高手请直接输入英文提示词"
/>

View File

@@ -59,6 +59,7 @@
<div class="text-line">
<van-field
v-model="params.prompt"
maxlength="2000"
rows="3"
autosize
type="textarea"
@@ -72,6 +73,7 @@
v-model="params.prompt"
rows="3"
autosize
maxlength="2000"
type="textarea"
placeholder="请在此输入绘画提示词,系统会自动翻译中文提示词,高手请直接输入英文提示词"
/>
@@ -135,7 +137,7 @@
<div class="text-line">
<van-collapse v-model="activeColspan">
<van-collapse-item title="反向提示词" name="neg_prompt">
<van-field v-model="params.neg_prompt" rows="3" autosize type="textarea" placeholder="不想出现在图片上的元素(例如:树,建筑)" />
<van-field v-model="params.neg_prompt" rows="3" maxlength="2000" autosize type="textarea" placeholder="不想出现在图片上的元素(例如:树,建筑)" />
</van-collapse-item>
</van-collapse>
</div>

View File

@@ -67,6 +67,7 @@
<van-field
v-model="params.prompt"
maxlength="2000"
rows="3"
autosize
type="textarea"
@@ -75,7 +76,7 @@
<van-collapse v-model="activeColspan">
<van-collapse-item title="反向提示词" name="neg_prompt">
<van-field v-model="params.neg_prompt" rows="3" autosize type="textarea" placeholder="不想出现在图片上的元素(例如:树,建筑)" />
<van-field v-model="params.neg_prompt" rows="3" maxlength="2000" autosize type="textarea" placeholder="不想出现在图片上的元素(例如:树,建筑)" />
</van-collapse-item>
</van-collapse>