feat: AI生图提示词翻译成英文后再发往上流(img2img 全链路 + 视频/设置改动)
This commit is contained in:
1 parent
76d9d45770
commit
b6e0c475d3
9 files changed
+1169
-34
No files matched your search
@@ -1,5 +1,5 @@
|
||||
import { useState, useEffect } from 'react';
|
||||
import { X, ScanText, Info, Save, FlaskConical, Github, ExternalLink, Wand2 } from 'lucide-react';
|
||||
import { X, ScanText, Info, Save, FlaskConical, Github, ExternalLink, Wand2, Film } from 'lucide-react';
|
||||
import { settingsAPI } from '../api';
|
||||
|
||||
const APP_VERSION = 'v1.4.8';
|
||||
@@ -17,6 +17,8 @@ export default function SettingsModal({ open, onClose, versionLabel, initialTab
|
||||
const [ig, setIg] = useState(null); // imagegen 配置
|
||||
const [igNewKey, setIgNewKey] = useState(''); // NewAPI 新密钥
|
||||
const [igCustomKey, setIgCustomKey] = useState(''); // 自定义提供商新密钥
|
||||
const [va, setVa] = useState(null); // AI 视频文本模型配置
|
||||
const [vaKey, setVaKey] = useState(''); // AI 视频新密钥
|
||||
const [saving, setSaving] = useState(false);
|
||||
const [testing, setTesting] = useState(false);
|
||||
const [msg, setMsg] = useState(null); // { type, text }
|
||||
@@ -28,6 +30,7 @@ export default function SettingsModal({ open, onClose, versionLabel, initialTab
|
||||
setApiKeyInput('');
|
||||
setIgNewKey('');
|
||||
setIgCustomKey('');
|
||||
setVaKey('');
|
||||
settingsAPI.getSettings()
|
||||
.then((d) => { setCfg({
|
||||
provider: d?.provider || 'local',
|
||||
@@ -51,6 +54,15 @@ export default function SettingsModal({ open, onClose, versionLabel, initialTab
|
||||
apiKeyMasked: d?.imagegen?.custom?.apiKeyMasked || ''
|
||||
}
|
||||
});
|
||||
setVa({
|
||||
provider: d?.videoai?.provider === 'custom' ? 'custom' : 'inherit',
|
||||
custom: {
|
||||
url: d?.videoai?.custom?.url || '',
|
||||
model: d?.videoai?.custom?.model || '',
|
||||
apiKeyMasked: d?.videoai?.custom?.apiKeyMasked || '',
|
||||
configured: !!d?.videoai?.custom?.configured
|
||||
}
|
||||
});
|
||||
})
|
||||
.catch((e) => setMsg({ type: 'error', text: '读取设置失败: ' + (e.data?.message || e.message) }));
|
||||
}, [open]);
|
||||
@@ -85,6 +97,16 @@ export default function SettingsModal({ open, onClose, versionLabel, initialTab
|
||||
apiKey: igCustomKey || ''
|
||||
}
|
||||
}
|
||||
} : {}),
|
||||
...(va ? {
|
||||
videoai: {
|
||||
provider: va.provider,
|
||||
custom: {
|
||||
url: va.custom.url,
|
||||
model: va.custom.model,
|
||||
apiKey: vaKey || ''
|
||||
}
|
||||
}
|
||||
} : {})
|
||||
};
|
||||
const data = await settingsAPI.updateSettings(payload);
|
||||
@@ -105,8 +127,20 @@ export default function SettingsModal({ open, onClose, versionLabel, initialTab
|
||||
});
|
||||
}
|
||||
setApiKeyInput('');
|
||||
if (data?.videoai) {
|
||||
setVa({
|
||||
provider: data.videoai.provider === 'custom' ? 'custom' : 'inherit',
|
||||
custom: {
|
||||
url: data.videoai.custom?.url || '',
|
||||
model: data.videoai.custom?.model || '',
|
||||
apiKeyMasked: data.videoai.custom?.apiKeyMasked || '',
|
||||
configured: !!data.videoai.custom?.configured
|
||||
}
|
||||
});
|
||||
}
|
||||
setIgNewKey('');
|
||||
setIgCustomKey('');
|
||||
setVaKey('');
|
||||
setMsg({ type: 'ok', text: '已保存,新配置立即生效' });
|
||||
} catch (e) {
|
||||
setMsg({ type: 'error', text: '保存失败: ' + (e.data?.message || e.message) });
|
||||
@@ -142,6 +176,7 @@ export default function SettingsModal({ open, onClose, versionLabel, initialTab
|
||||
const menus = [
|
||||
{ key: 'ocr', label: 'OCR 识别', icon: ScanText },
|
||||
{ key: 'aigen', label: 'AI 生图', icon: Wand2 },
|
||||
{ key: 'videoai', label: 'AI 视频', icon: Film },
|
||||
{ key: 'about', label: '关于', icon: Info }
|
||||
];
|
||||
|
||||
@@ -174,7 +209,7 @@ export default function SettingsModal({ open, onClose, versionLabel, initialTab
|
||||
<div className="flex-1 p-6 overflow-y-auto">
|
||||
<div className="flex items-center justify-between mb-4">
|
||||
<h2 className="text-lg font-semibold text-gray-900 dark:text-white">
|
||||
{active === 'ocr' ? 'OCR 识别设置' : active === 'aigen' ? 'AI 生图设置' : '关于'}
|
||||
{active === 'ocr' ? 'OCR 识别设置' : active === 'aigen' ? 'AI 生图设置' : active === 'videoai' ? 'AI 视频设置' : '关于'}
|
||||
</h2>
|
||||
<button onClick={onClose} className="p-1.5 rounded-lg hover:bg-gray-100 dark:hover:bg-gray-700">
|
||||
<X className="w-5 h-5 text-gray-500" />
|
||||
@@ -395,6 +430,92 @@ export default function SettingsModal({ open, onClose, versionLabel, initialTab
|
||||
</div>
|
||||
)}
|
||||
|
||||
{active === 'videoai' && cfg && va && (
|
||||
<div className="space-y-5">
|
||||
<p className="text-xs text-gray-500 dark:text-gray-400">
|
||||
AI 视频用这个模型来写分镜脚本、把提示词/网页/文档内容组织成讲解稿(普通文本模型即可,无需多模态)。
|
||||
配音、字幕与成片合成由服务器本地完成。密钥只保存在本机,不出服务器。
|
||||
</p>
|
||||
|
||||
<div>
|
||||
<div className="text-xs font-medium text-gray-600 dark:text-gray-400 mb-2">文本模型来源</div>
|
||||
<div className="space-y-2">
|
||||
<label className="flex items-start gap-2.5 p-3 border border-gray-200 dark:border-gray-700 rounded-lg cursor-pointer hover:bg-gray-50 dark:hover:bg-gray-700/50">
|
||||
<input
|
||||
type="radio"
|
||||
className="mt-0.5"
|
||||
checked={va.provider === 'inherit'}
|
||||
onChange={() => setVa((v) => ({ ...v, provider: 'inherit' }))}
|
||||
/>
|
||||
<span>
|
||||
<span className="block text-sm font-medium text-gray-900 dark:text-white">复用「AI 生图」配置(推荐)</span>
|
||||
<span className="block text-xs text-gray-500 dark:text-gray-400 mt-0.5">用上面 AI 生图里的地址与 Key,无需重复填写</span>
|
||||
</span>
|
||||
</label>
|
||||
<label className="flex items-start gap-2.5 p-3 border border-gray-200 dark:border-gray-700 rounded-lg cursor-pointer hover:bg-gray-50 dark:hover:bg-gray-700/50">
|
||||
<input
|
||||
type="radio"
|
||||
className="mt-0.5"
|
||||
checked={va.provider === 'custom'}
|
||||
onChange={() => setVa((v) => ({ ...v, provider: 'custom' }))}
|
||||
/>
|
||||
<span>
|
||||
<span className="block text-sm font-medium text-gray-900 dark:text-white">单独配置提供商 / 模型 / Key</span>
|
||||
<span className="block text-xs text-gray-500 dark:text-gray-400 mt-0.5">任意 OpenAI 兼容 /v1/chat/completions 的文本模型</span>
|
||||
</span>
|
||||
</label>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{va.provider === 'custom' && (
|
||||
<div className="space-y-3 p-4 bg-gray-50 dark:bg-gray-900/50 rounded-lg border border-gray-200 dark:border-gray-700">
|
||||
<div>
|
||||
<label className="block text-xs font-medium text-gray-600 dark:text-gray-400 mb-1">接口地址(BASE URL)</label>
|
||||
<input
|
||||
type="text"
|
||||
value={va.custom.url}
|
||||
onChange={(e) => setVa((v) => ({ ...v, custom: { ...v.custom, url: e.target.value } }))}
|
||||
placeholder="https://api.openai.com/v1 或 http://192.168.68.19:3099/v1"
|
||||
className="w-full px-3 py-2 text-sm border border-gray-300 dark:border-gray-600 rounded-lg bg-white dark:bg-gray-700 text-gray-900 dark:text-gray-100"
|
||||
/>
|
||||
</div>
|
||||
<div>
|
||||
<label className="block text-xs font-medium text-gray-600 dark:text-gray-400 mb-1">模型名称</label>
|
||||
<input
|
||||
type="text"
|
||||
value={va.custom.model}
|
||||
onChange={(e) => setVa((v) => ({ ...v, custom: { ...v.custom, model: e.target.value } }))}
|
||||
placeholder="mimo-v2.6-flash / gpt-4o-mini / qwen-plus ..."
|
||||
className="w-full px-3 py-2 text-sm border border-gray-300 dark:border-gray-600 rounded-lg bg-white dark:bg-gray-700 text-gray-900 dark:text-gray-100"
|
||||
/>
|
||||
</div>
|
||||
<div>
|
||||
<label className="block text-xs font-medium text-gray-600 dark:text-gray-400 mb-1">API Key</label>
|
||||
<input
|
||||
type="password"
|
||||
value={vaKey}
|
||||
onChange={(e) => setVaKey(e.target.value)}
|
||||
placeholder={va.custom.apiKeyMasked ? `已配置(${va.custom.apiKeyMasked}),留空保持不变` : 'sk-... 或中转站 48 位令牌'}
|
||||
className="w-full px-3 py-2 text-sm border border-gray-300 dark:border-gray-600 rounded-lg bg-white dark:bg-gray-700 text-gray-900 dark:text-gray-100"
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
)}
|
||||
|
||||
<div className="flex items-center gap-3">
|
||||
<button
|
||||
onClick={handleSave}
|
||||
disabled={saving}
|
||||
className="flex items-center gap-1.5 px-4 py-2 text-sm font-medium text-white bg-blue-600 hover:bg-blue-700 rounded-lg disabled:opacity-50"
|
||||
>
|
||||
<Save className="w-4 h-4" />
|
||||
{saving ? '保存中...' : '保存'}
|
||||
</button>
|
||||
<span className="text-xs text-gray-400 dark:text-gray-500">保存后立即生效,无需重启</span>
|
||||
</div>
|
||||
</div>
|
||||
)}
|
||||
|
||||
{active === 'about' && (
|
||||
<div className="space-y-4 text-sm">
|
||||
<div className="flex items-center justify-between py-2 border-b border-gray-100 dark:border-gray-700">
|
||||
|
||||
Reference in new issue
Block a user