Skip to content

Commit 1628226

Browse files
committed
修改模型
1 parent 5d603a2 commit 1628226

2 files changed

Lines changed: 25 additions & 95 deletions

File tree

src/components/assistant/Sidebar.vue

Lines changed: 16 additions & 81 deletions
Original file line numberDiff line numberDiff line change
@@ -341,16 +341,13 @@
341341
abortController.value = null
342342
isLoading.value = false
343343
isGenerating.value = false
344-
console.log('已手动中止生成')
344+
processingStatus.value = ''
345345
}
346346
}
347347
348348
// 服务端模式
349349
const serverMode = ref(false)
350350
351-
// 生图功能
352-
const isGeneratingImage = ref(false)
353-
354351
const sendMessage = async () => {
355352
if (!canSendMessage.value || isLoading.value) return
356353
generateNewRequestId()
@@ -377,7 +374,7 @@
377374
chatMessages.value.push(userMessage)
378375
379376
// 清空输入并滚动到底部
380-
userInput.value = ''
377+
userInput.value = ''
381378
382379
setTimeout(() => {
383380
scrollToBottom()
@@ -387,12 +384,21 @@
387384
if (hasImage && !isImageGeneration) {
388385
processingStatus.value = '正在编辑图片...'
389386
try {
390-
// 调用图片编辑API
387+
// 创建AbortController用于中止图片编辑请求
388+
abortController.value = new AbortController()
391389
const imageUrl = await handleImageWithKontextPro(
392390
messageText || '请编辑这张图片',
393-
previewImage.value
391+
previewImage.value,
392+
abortController.value.signal
394393
)
395394
395+
// 如果控制器已中止,不继续处理
396+
if (abortController.value?.signal.aborted) {
397+
isLoading.value = false
398+
isGenerating.value = false
399+
processingStatus.value = ''
400+
return
401+
}
396402
// Image对象预加载图片
397403
const img = new Image()
398404
// Promise等待图片加载完成
@@ -404,7 +410,7 @@
404410
// 图片加载成功后,添加带图片的消息
405411
const assistantMessage = {
406412
role: 'assistant' as const,
407-
content: '已为您编辑图片,点击LoadImage节点可以直接应用。',
413+
content: serverMode.value ? '已为您编辑图片' : '已为您编辑图片,点击LoadImage节点可以直接应用。',
408414
time: getCurrentTime(),
409415
hasImage: true,
410416
image: imageUrl
@@ -424,81 +430,10 @@
424430
} catch (error: any) {
425431
isLoading.value = false
426432
isGenerating.value = false
427-
processingStatus.value = ''
433+
processingStatus.value = ''
428434
return
429435
}
430436
}
431-
// 判断是否是图片生成请求
432-
if (isImageGeneration) {
433-
isGeneratingImage.value = true
434-
processingStatus.value = '正在生成图片...'
435-
436-
// 提取提示词
437-
const prompt = messageText.replace('生成图片:', '').trim() || '一张漂亮的图片'
438-
439-
// 调用图像生成API
440-
const imageUrl = await generateImage({
441-
prompt,
442-
model: 'Kwai-Kolors/Kolors',
443-
loading_callback: loading => {
444-
// 加载状态更新
445-
if (!loading) {
446-
processingStatus.value = ''
447-
} else {
448-
processingStatus.value = '正在生成图片...'
449-
}
450-
},
451-
error_callback: error => {
452-
useToaster({
453-
type: 'error',
454-
message: '生成图片失败: ' + (error.message || '未知错误')
455-
})
456-
}
457-
})
458-
459-
// 预加载生成的图片
460-
const img = new Image()
461-
// 使用Promise等待图片加载完成
462-
await new Promise((resolve, reject) => {
463-
img.onload = () => resolve(true)
464-
img.onerror = () => reject(new Error('图片加载失败'))
465-
img.src = imageUrl
466-
})
467-
468-
// 生成成功后,添加带图片的助手消息
469-
const assistantMessage = {
470-
role: 'assistant' as const,
471-
// 服务端模式下只展示"已为您生成图片"
472-
content: serverMode.value
473-
? '已为您生成图片'
474-
: '已为您生成图片(点击LoadImage节点可以应用)',
475-
time: getCurrentTime(),
476-
hasImage: true,
477-
image: imageUrl
478-
}
479-
480-
chatMessages.value.push(assistantMessage)
481-
482-
// 成功提示
483-
useToaster({
484-
type: 'success',
485-
message: '图片生成成功'
486-
})
487-
488-
// 更新状态
489-
isGeneratingImage.value = false
490-
isLoading.value = false
491-
isGenerating.value = false
492-
processingStatus.value = ''
493-
494-
// 滚动到底部
495-
setTimeout(() => {
496-
scrollToBottom()
497-
}, 0)
498-
499-
return
500-
}
501-
502437
// 创建AbortController用于中止请求
503438
abortController.value = new AbortController()
504439
@@ -609,7 +544,7 @@
609544
}
610545
},
611546
{
612-
model: 'Qwen/Qwen2.5-VL-72B-Instruct',
547+
model: 'Pro/deepseek-ai/DeepSeek-V3',
613548
prompt_id: promptId.value,
614549
request_id: requestId.value
615550
}

src/components/assistant/util.ts

Lines changed: 9 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -12,16 +12,6 @@ export interface ChatApiOptions {
1212
request_id?: string
1313
}
1414

15-
// 图像生成选项接口
16-
export interface ImageGenerationOptions {
17-
prompt: string
18-
n?: number
19-
model?: string
20-
size?: string
21-
loading_callback?: (loading: boolean) => void
22-
error_callback?: (error: any) => void
23-
}
24-
2515
// 消息接口
2616
export interface ChatMessage {
2717
role: 'user' | 'assistant' | 'system'
@@ -467,15 +457,20 @@ export async function generateImage(options: {
467457
* 处理带图片的消息,使用flux-kontext-pro模型编辑图片
468458
* @param prompt 提示词
469459
* @param imageBase64 图片base64数据
460+
* @param signal 可选的AbortSignal,用于取消请求
470461
* @returns Promise<string> 返回生成的图片URL
471462
*/
472-
export async function handleImageWithKontextPro(prompt: string, imageBase64: string) {
463+
export async function handleImageWithKontextPro(
464+
prompt: string,
465+
imageBase64: string,
466+
signal?: AbortSignal,
467+
options: Record<string, any> = {}
468+
) {
473469
console.log('进入handleImageWithKontextPro函数')
474470

475471
try {
476472
// 验证imageBase64是否有效
477473
if (!imageBase64 || typeof imageBase64 !== 'string') {
478-
console.error('无效的图片数据')
479474
throw new Error('图片数据无效')
480475
}
481476

@@ -500,8 +495,8 @@ export async function handleImageWithKontextPro(prompt: string, imageBase64: str
500495
method: 'POST',
501496
headers: {
502497
'Content-Type': 'application/json',
503-
Authorization: Cookies.get('bizy_token') || ''
504-
// ...(options as any)?.headers
498+
Authorization: Cookies.get('bizy_token') || '',
499+
...(options as any)?.headers
505500
},
506501
body: JSON.stringify(requestBody)
507502
})

0 commit comments

Comments
 (0)