Phase 4 구현: Ollama LLM 연동 (다듬기, 번역, 스트리밍)
- LocalLLMService: Ollama REST API, 스트리밍 NDJSON 파싱, 5초 가용성 폴링 - 시스템 프롬프트: refine/translate/summarize/grammar/expand/custom 6개 액션 - VoiceModeService: 전사→LLM 후처리→텍스트 삽입, LLM 실패 시 원본 폴백 - LLM IPC 핸들러: status/models/process/cancel/serverUrl 8개 - StatusBar: Ollama 연결 상태 + 활성 모델 표시 - Preload: llm API 섹션 추가 - Bootstrap: llm-polling 초기화 단계 추가
This commit is contained in:
parent
517210af2f
commit
4a5cf6c819
10 changed files with 663 additions and 9 deletions
68
src/main/ipc/llm-handlers.ts
Normal file
68
src/main/ipc/llm-handlers.ts
Normal file
|
|
@ -0,0 +1,68 @@
|
|||
// src/main/ipc/llm-handlers.ts
|
||||
|
||||
import { ipcMain } from 'electron'
|
||||
import { IPC_CHANNELS } from '@shared/ipc-channels'
|
||||
import { ipcSuccess, ipcError, ErrorCode } from '@shared/errors'
|
||||
import { getLocalLLMService } from '../services/LocalLLMService'
|
||||
import { configGet, configSet } from '../services/ConfigService'
|
||||
import type { SetLLMModelParams, SetServerUrlParams, LLMProcessParams } from '@shared/types'
|
||||
|
||||
export function registerLLMHandlers(): void {
|
||||
ipcMain.handle(IPC_CHANNELS.LLM.GET_STATUS, async () => {
|
||||
return ipcSuccess(getLocalLLMService().getStatus())
|
||||
})
|
||||
|
||||
ipcMain.handle(IPC_CHANNELS.LLM.GET_MODELS, async () => {
|
||||
try {
|
||||
const models = await getLocalLLMService().getModels()
|
||||
return ipcSuccess(models)
|
||||
} catch {
|
||||
return ipcError(ErrorCode.LLMServerUnreachable, 'Failed to get models')
|
||||
}
|
||||
})
|
||||
|
||||
ipcMain.handle(IPC_CHANNELS.LLM.GET_ACTIVE_MODEL, async () => {
|
||||
return ipcSuccess(configGet('llmModelId'))
|
||||
})
|
||||
|
||||
ipcMain.handle(IPC_CHANNELS.LLM.SET_MODEL, async (_event, params: SetLLMModelParams) => {
|
||||
configSet('llmModelId', params.modelId)
|
||||
return ipcSuccess(undefined)
|
||||
})
|
||||
|
||||
ipcMain.handle(IPC_CHANNELS.LLM.PROCESS, async (_event, params: LLMProcessParams) => {
|
||||
try {
|
||||
const llm = getLocalLLMService()
|
||||
const start = performance.now()
|
||||
const processedText = await llm.processText(
|
||||
params.text,
|
||||
params.action,
|
||||
params.targetLanguage,
|
||||
params.customPrompt
|
||||
)
|
||||
return ipcSuccess({
|
||||
originalText: params.text,
|
||||
processedText,
|
||||
action: params.action,
|
||||
processingTimeMs: Math.round(performance.now() - start),
|
||||
tokenCount: 0
|
||||
})
|
||||
} catch {
|
||||
return ipcError(ErrorCode.LLMProcessingFailed, 'LLM processing failed')
|
||||
}
|
||||
})
|
||||
|
||||
ipcMain.handle(IPC_CHANNELS.LLM.CANCEL_PROCESS, async () => {
|
||||
getLocalLLMService().cancelGeneration()
|
||||
return ipcSuccess(undefined)
|
||||
})
|
||||
|
||||
ipcMain.handle(IPC_CHANNELS.LLM.GET_SERVER_URL, async () => {
|
||||
return ipcSuccess(configGet('ollamaServerUrl'))
|
||||
})
|
||||
|
||||
ipcMain.handle(IPC_CHANNELS.LLM.SET_SERVER_URL, async (_event, params: SetServerUrlParams) => {
|
||||
configSet('ollamaServerUrl', params.url)
|
||||
return ipcSuccess(undefined)
|
||||
})
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue