mirror of
https://github.com/EthanMarti/infio-copilot.git
synced 2026-01-16 16:31:56 +00:00
添加嵌入管理器的初始化和清理逻辑,更新嵌入模型加载和嵌入测试的实现。
This commit is contained in:
parent
65c5df3d22
commit
8b3babc28e
25
src/main.ts
25
src/main.ts
@ -14,6 +14,7 @@ import { RAGEngine } from './core/rag/rag-engine'
|
|||||||
import { TransEngine } from './core/transformations/trans-engine'
|
import { TransEngine } from './core/transformations/trans-engine'
|
||||||
import { DBManager } from './database/database-manager'
|
import { DBManager } from './database/database-manager'
|
||||||
import { migrateToJsonDatabase } from './database/json/migrateToJsonDatabase'
|
import { migrateToJsonDatabase } from './database/json/migrateToJsonDatabase'
|
||||||
|
import { EmbeddingManager } from './embedworker/EmbeddingManager'
|
||||||
import EventListener from "./event-listener"
|
import EventListener from "./event-listener"
|
||||||
import { t } from './lang/helpers'
|
import { t } from './lang/helpers'
|
||||||
import { PreviewView } from './PreviewView'
|
import { PreviewView } from './PreviewView'
|
||||||
@ -52,6 +53,7 @@ export default class InfioPlugin extends Plugin {
|
|||||||
mcpHub: McpHub | null = null
|
mcpHub: McpHub | null = null
|
||||||
ragEngine: RAGEngine | null = null
|
ragEngine: RAGEngine | null = null
|
||||||
transEngine: TransEngine | null = null
|
transEngine: TransEngine | null = null
|
||||||
|
embeddingManager: EmbeddingManager | null = null
|
||||||
inlineEdit: InlineEdit | null = null
|
inlineEdit: InlineEdit | null = null
|
||||||
diffStrategy?: DiffStrategy
|
diffStrategy?: DiffStrategy
|
||||||
dataviewManager: DataviewManager | null = null
|
dataviewManager: DataviewManager | null = null
|
||||||
@ -73,6 +75,10 @@ export default class InfioPlugin extends Plugin {
|
|||||||
// initialize dataview manager
|
// initialize dataview manager
|
||||||
this.dataviewManager = createDataviewManager(this.app)
|
this.dataviewManager = createDataviewManager(this.app)
|
||||||
|
|
||||||
|
// initialize embedding manager
|
||||||
|
this.embeddingManager = new EmbeddingManager()
|
||||||
|
console.log('EmbeddingManager initialized')
|
||||||
|
|
||||||
// add icon to ribbon
|
// add icon to ribbon
|
||||||
this.addRibbonIcon('wand-sparkles', t('main.openInfioCopilot'), () =>
|
this.addRibbonIcon('wand-sparkles', t('main.openInfioCopilot'), () =>
|
||||||
this.openChatView(),
|
this.openChatView(),
|
||||||
@ -426,16 +432,18 @@ export default class InfioPlugin extends Plugin {
|
|||||||
name: '测试本地嵌入模型',
|
name: '测试本地嵌入模型',
|
||||||
callback: async () => {
|
callback: async () => {
|
||||||
try {
|
try {
|
||||||
// 动态导入嵌入管理器
|
if (!this.embeddingManager) {
|
||||||
const { embeddingManager } = await import('./embedworker/index');
|
new Notice('EmbeddingManager 未初始化', 5000);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
// 加载模型
|
// 加载模型
|
||||||
await embeddingManager.loadModel("Xenova/all-MiniLM-L6-v2", true);
|
await this.embeddingManager.loadModel("Xenova/all-MiniLM-L6-v2", true);
|
||||||
|
|
||||||
// 测试嵌入 "hello world"
|
// 测试嵌入 "hello world"
|
||||||
const testText = "hello world";
|
const testText = "hello world";
|
||||||
|
|
||||||
const result = await embeddingManager.embed(testText);
|
const result = await this.embeddingManager.embed(testText);
|
||||||
|
|
||||||
// 显示结果
|
// 显示结果
|
||||||
const resultMessage = `
|
const resultMessage = `
|
||||||
@ -480,6 +488,9 @@ export default class InfioPlugin extends Plugin {
|
|||||||
// MCP Hub cleanup
|
// MCP Hub cleanup
|
||||||
this.mcpHub?.dispose()
|
this.mcpHub?.dispose()
|
||||||
this.mcpHub = null
|
this.mcpHub = null
|
||||||
|
// EmbeddingManager cleanup
|
||||||
|
this.embeddingManager?.terminate()
|
||||||
|
this.embeddingManager = null
|
||||||
// Dataview cleanup
|
// Dataview cleanup
|
||||||
this.dataviewManager = null
|
this.dataviewManager = null
|
||||||
}
|
}
|
||||||
@ -638,6 +649,10 @@ export default class InfioPlugin extends Plugin {
|
|||||||
return this.transEngineInitPromise
|
return this.transEngineInitPromise
|
||||||
}
|
}
|
||||||
|
|
||||||
|
getEmbeddingManager(): EmbeddingManager | null {
|
||||||
|
return this.embeddingManager
|
||||||
|
}
|
||||||
|
|
||||||
private async migrateToJsonStorage() {
|
private async migrateToJsonStorage() {
|
||||||
try {
|
try {
|
||||||
const dbManager = await this.getDbManager()
|
const dbManager = await this.getDbManager()
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user