mirror of
https://github.com/hellodigua/ChatLab.git
synced 2026-05-13 09:41:01 +08:00
fix: 修复部分BUG
This commit is contained in:
@@ -352,12 +352,15 @@ export function getDefaultAssistantConfig(): AIServiceConfig | null {
|
||||
/** 获取快速模型 slot */
|
||||
export function getFastModelSlot(): import('./model-types').ModelSlot | null {
|
||||
const store = loadConfigStore()
|
||||
if (store.fastModel === null) return null
|
||||
return resolveSlot(store.fastModel, store.configs)
|
||||
}
|
||||
|
||||
/** 获取快速模型配置(会话摘要),未配置时回退到默认助手 */
|
||||
export function getFastModelConfig(): AIServiceConfig | null {
|
||||
const store = loadConfigStore()
|
||||
if (store.fastModel === null) return getDefaultAssistantConfig()
|
||||
|
||||
const slot = resolveSlot(store.fastModel, store.configs)
|
||||
if (slot) {
|
||||
const config = store.configs.find((c) => c.id === slot.configId)
|
||||
|
||||
@@ -5,7 +5,6 @@
|
||||
import { ipcMain, app } from 'electron'
|
||||
import * as fs from 'fs'
|
||||
import * as path from 'path'
|
||||
import axios from 'axios'
|
||||
import * as worker from '../worker/workerManager'
|
||||
import type { IpcContext } from './types'
|
||||
|
||||
@@ -27,12 +26,12 @@ function getDemoTempDir(): string {
|
||||
|
||||
async function downloadFile(url: string, destPath: string): Promise<void> {
|
||||
const tmpPath = destPath + '.tmp'
|
||||
const response = await axios.get(url, {
|
||||
responseType: 'arraybuffer',
|
||||
timeout: 60_000,
|
||||
})
|
||||
const response = await fetch(url, { signal: AbortSignal.timeout(60_000) })
|
||||
if (!response.ok) {
|
||||
throw new Error(`Download failed: HTTP ${response.status}`)
|
||||
}
|
||||
|
||||
const buffer = Buffer.from(response.data)
|
||||
const buffer = Buffer.from(await response.arrayBuffer())
|
||||
if (buffer.length < 100) {
|
||||
throw new Error(`Downloaded file too small (${buffer.length} bytes)`)
|
||||
}
|
||||
|
||||
@@ -8,7 +8,6 @@ import * as fs from 'fs'
|
||||
import * as path from 'path'
|
||||
import { createHash } from 'crypto'
|
||||
import { app } from 'electron'
|
||||
import axios from 'axios'
|
||||
|
||||
const NLP_DIR_NAME = 'nlp'
|
||||
const DICT_DOWNLOAD_URL_BASE = 'https://chatlab.fun/assets/nlp'
|
||||
@@ -21,6 +20,37 @@ function sha256Hex(buffer: Buffer): string {
|
||||
return createHash('sha256').update(buffer).digest('hex')
|
||||
}
|
||||
|
||||
async function downloadBuffer(url: string, timeoutMs: number, onProgress?: (percent: number) => void): Promise<Buffer> {
|
||||
const response = await fetch(url, { signal: AbortSignal.timeout(timeoutMs) })
|
||||
if (!response.ok) {
|
||||
throw new Error(`Download failed: HTTP ${response.status}`)
|
||||
}
|
||||
|
||||
const total = Number(response.headers.get('content-length') || 0)
|
||||
if (!response.body) {
|
||||
return Buffer.from(await response.arrayBuffer())
|
||||
}
|
||||
|
||||
const reader = response.body.getReader()
|
||||
const chunks: Buffer[] = []
|
||||
let loaded = 0
|
||||
|
||||
while (true) {
|
||||
const { done, value } = await reader.read()
|
||||
if (done) break
|
||||
|
||||
const chunk = Buffer.from(value)
|
||||
chunks.push(chunk)
|
||||
loaded += chunk.length
|
||||
|
||||
if (total > 0 && onProgress) {
|
||||
onProgress(Math.round((loaded / total) * 100))
|
||||
}
|
||||
}
|
||||
|
||||
return Buffer.concat(chunks)
|
||||
}
|
||||
|
||||
export interface DictInfo {
|
||||
id: string
|
||||
label: string
|
||||
@@ -100,17 +130,7 @@ export async function downloadDict(
|
||||
const tmpPath = filePath + '.tmp'
|
||||
|
||||
try {
|
||||
const response = await axios.get(url, {
|
||||
responseType: 'arraybuffer',
|
||||
timeout: 120_000,
|
||||
onDownloadProgress: (progressEvent) => {
|
||||
if (progressEvent.total && onProgress) {
|
||||
onProgress(Math.round((progressEvent.loaded / progressEvent.total) * 100))
|
||||
}
|
||||
},
|
||||
})
|
||||
|
||||
const buffer = Buffer.from(response.data)
|
||||
const buffer = await downloadBuffer(url, 120_000, onProgress)
|
||||
|
||||
// 词库文件至少应 > 1MB,且不应以 HTML 标签开头
|
||||
const MIN_DICT_SIZE = 1_000_000
|
||||
|
||||
@@ -102,8 +102,8 @@
|
||||
"languagePreference": "言語傾向"
|
||||
},
|
||||
"groupRelationships": {
|
||||
"mentionGraph": "@ 関係図",
|
||||
"mentionRanking": "@ ランキング",
|
||||
"mentionGraph": "{'@'} 関係図",
|
||||
"mentionRanking": "{'@'} ランキング",
|
||||
"proximity": "発言の近接度"
|
||||
},
|
||||
"member": {
|
||||
|
||||
@@ -103,8 +103,8 @@
|
||||
"languagePreference": "语言偏好"
|
||||
},
|
||||
"groupRelationships": {
|
||||
"mentionGraph": "@ 关系图",
|
||||
"mentionRanking": "@ 排行",
|
||||
"mentionGraph": "{'@'} 关系图",
|
||||
"mentionRanking": "{'@'} 排行",
|
||||
"proximity": "发言临近度"
|
||||
},
|
||||
"member": {
|
||||
|
||||
@@ -102,8 +102,8 @@
|
||||
"languagePreference": "語言偏好"
|
||||
},
|
||||
"groupRelationships": {
|
||||
"mentionGraph": "@ 關係圖",
|
||||
"mentionRanking": "@ 排行",
|
||||
"mentionGraph": "{'@'} 關係圖",
|
||||
"mentionRanking": "{'@'} 排行",
|
||||
"proximity": "發言臨近度"
|
||||
},
|
||||
"member": {
|
||||
|
||||
@@ -64,7 +64,7 @@ const router = useRouter()
|
||||
const mergeImportEnabled = ref(false)
|
||||
|
||||
// 是否展示 Demo 按钮(仅无任何会话时)
|
||||
const showDemoButton = computed(() => sessionStore.sessions.length !== 0)
|
||||
const showDemoButton = computed(() => sessionStore.sessions.length === 0)
|
||||
|
||||
// 计算是否正在导入(单文件、批量或合并)
|
||||
const isAnyImporting = computed(() => isImporting.value || isBatchImporting.value || isMergeImporting.value)
|
||||
|
||||
Reference in New Issue
Block a user