Files
LittleWhiteBox/modules/story-summary/vector/utils/embedder.js

84 lines
4.3 KiB
JavaScript
Raw Normal View History

2026-01-26 01:16:35 +08:00
// ═══════════════════════════════════════════════════════════════════════════
2026-02-06 11:22:02 +08:00
// Story Summary - Embedder (v2 - 统一硅基)
// 所有 embedding 请求转发到 siliconflow.js
2026-01-26 01:16:35 +08:00
// ═══════════════════════════════════════════════════════════════════════════
2026-02-06 11:22:02 +08:00
import { embed as sfEmbed, getApiKey } from '../llm/siliconflow.js';
2026-01-26 01:16:35 +08:00
// ═══════════════════════════════════════════════════════════════════════════
2026-02-06 11:22:02 +08:00
// 统一 embed 接口
2026-01-26 01:16:35 +08:00
// ═══════════════════════════════════════════════════════════════════════════
2026-02-06 11:22:02 +08:00
export async function embed(texts, config, options = {}) {
// 忽略旧的 config 参数,统一走硅基
return await sfEmbed(texts, options);
}
2026-01-26 01:16:35 +08:00
// ═══════════════════════════════════════════════════════════════════════════
2026-02-06 11:22:02 +08:00
// 指纹(简化版)
2026-01-26 01:16:35 +08:00
// ═══════════════════════════════════════════════════════════════════════════
2026-02-06 11:22:02 +08:00
export function getEngineFingerprint(config) {
// 统一使用硅基 bge-m3
return 'siliconflow:bge-m3:1024';
2026-01-26 01:16:35 +08:00
}
// ═══════════════════════════════════════════════════════════════════════════
2026-02-06 11:22:02 +08:00
// 状态检查(简化版)
2026-01-26 01:16:35 +08:00
// ═══════════════════════════════════════════════════════════════════════════
2026-02-06 11:22:02 +08:00
export async function checkLocalModelStatus() {
// 不再支持本地模型
return { status: 'not_supported', message: '请使用在线服务' };
2026-01-26 01:16:35 +08:00
}
2026-02-06 11:22:02 +08:00
export function isLocalModelLoaded() {
return false;
2026-01-26 01:16:35 +08:00
}
2026-02-06 11:22:02 +08:00
export async function downloadLocalModel() {
throw new Error('本地模型已移除,请使用在线服务');
2026-01-26 01:16:35 +08:00
}
2026-02-06 11:22:02 +08:00
export function cancelDownload() { }
2026-01-26 01:16:35 +08:00
2026-02-06 11:22:02 +08:00
export async function deleteLocalModelCache() { }
2026-01-26 01:16:35 +08:00
// ═══════════════════════════════════════════════════════════════════════════
2026-02-06 11:22:02 +08:00
// 在线服务测试
2026-01-26 01:16:35 +08:00
// ═══════════════════════════════════════════════════════════════════════════
2026-02-06 11:22:02 +08:00
export async function testOnlineService() {
const key = getApiKey();
2026-01-26 01:16:35 +08:00
if (!key) {
2026-02-06 11:22:02 +08:00
throw new Error('请配置硅基 API Key');
2026-01-26 01:16:35 +08:00
}
try {
2026-02-06 11:22:02 +08:00
const [vec] = await sfEmbed(['测试连接']);
return { success: true, dims: vec?.length || 0 };
2026-01-26 01:16:35 +08:00
} catch (e) {
2026-02-06 11:22:02 +08:00
throw new Error(`连接失败: ${e.message}`);
2026-01-26 01:16:35 +08:00
}
}
2026-02-06 11:22:02 +08:00
export async function fetchOnlineModels() {
// 硅基模型固定
return ['BAAI/bge-m3'];
2026-01-26 01:16:35 +08:00
}
// ═══════════════════════════════════════════════════════════════════════════
2026-02-06 11:22:02 +08:00
// 兼容旧接口
2026-01-26 01:16:35 +08:00
// ═══════════════════════════════════════════════════════════════════════════
2026-02-06 11:22:02 +08:00
export const DEFAULT_LOCAL_MODEL = 'bge-m3';
2026-01-26 01:16:35 +08:00
2026-02-06 11:22:02 +08:00
export const LOCAL_MODELS = {};
2026-01-26 01:16:35 +08:00
2026-02-06 11:22:02 +08:00
export const ONLINE_PROVIDERS = {
siliconflow: {
id: 'siliconflow',
name: '硅基流动',
baseUrl: 'https://api.siliconflow.cn',
},
};