1.优化AI请求替换OpenAI SDK调用,使用httpx和自定义头请求,避免触发部分公益站的cloudflare

2.修复deepseek模型调用问题,舍弃思考过程AI响应内容,只获取结果内容
3.新增会话过期机制,更新后添加到.env中
4.支持用户在生成章节内容时设置字数
This commit is contained in:
xiamuceer
2025-11-03 15:28:51 +08:00
parent e02e61ed6b
commit 1cde345ed9
21 changed files with 1118 additions and 251 deletions
+79 -4
View File
@@ -25,6 +25,7 @@ export default function ProjectWizardNew() {
const [form] = Form.useForm();
const [characterForm] = Form.useForm();
const [worldForm] = Form.useForm();
const [generateForm] = Form.useForm();
const [current, setCurrent] = useState(0);
const [loading, setLoading] = useState(false);
const [isResumingWizard, setIsResumingWizard] = useState(false);
@@ -814,11 +815,85 @@ export default function ProjectWizardNew() {
return (
<Card>
<div style={{ marginBottom: 16 }}>
<Title level={isMobile ? 5 : 4} style={{ margin: 0, fontSize: isMobile ? 16 : undefined }}>
(: {safeCharacters.length}: {requiredCharacterCount})
</Title>
<div style={{
display: 'flex',
justifyContent: 'space-between',
alignItems: isMobile ? 'flex-start' : 'center',
marginBottom: 12,
flexDirection: isMobile ? 'column' : 'row',
gap: isMobile ? 12 : 0
}}>
<Title level={isMobile ? 5 : 4} style={{ margin: 0, fontSize: isMobile ? 16 : undefined }}>
(: {safeCharacters.length}: {requiredCharacterCount})
</Title>
<Button
type="dashed"
icon={<TeamOutlined />}
onClick={() => {
Modal.confirm({
title: 'AI生成角色',
width: 600,
centered: true,
content: (
<Form form={generateForm} layout="vertical" style={{ marginTop: 16 }}>
<Form.Item
label="角色名称"
name="name"
>
<Input placeholder="如:张三、李四(可选,AI会自动生成)" />
</Form.Item>
<Form.Item
label="角色定位"
name="role_type"
rules={[{ required: true, message: '请选择角色定位' }]}
>
<Select placeholder="选择角色定位">
<Select.Option value="protagonist"></Select.Option>
<Select.Option value="supporting"></Select.Option>
<Select.Option value="antagonist"></Select.Option>
</Select>
</Form.Item>
<Form.Item label="背景设定" name="background">
<TextArea rows={3} placeholder="简要描述角色背景和故事环境..." />
</Form.Item>
</Form>
),
okText: '生成',
cancelText: '取消',
onOk: async () => {
try {
const values = await generateForm.validateFields();
setLoading(true);
// 调用单个角色生成API
const newCharacter = await characterApi.generateCharacter({
project_id: projectId,
name: values.name,
role_type: values.role_type,
background: values.background,
});
// 添加到列表
setCharacters([...safeCharacters, newCharacter]);
message.success('AI生成角色成功');
generateForm.resetFields();
} catch (error) {
const apiError = error as ApiError;
message.error('AI生成失败:' + (apiError.response?.data?.detail || apiError.message || '未知错误'));
} finally {
setLoading(false);
}
}
});
}}
disabled={loading}
size={isMobile ? 'middle' : 'middle'}
>
AI生成角色
</Button>
</div>
<Paragraph type="secondary" style={{ margin: '8px 0 0 0', fontSize: isMobile ? 12 : 14 }}>
AI生成
AI生成使"AI生成角色"
</Paragraph>
</div>