MCPcopy Create free account
hub / github.com/zxlie/FeHelper / prepareBuiltInModel

Function prepareBuiltInModel

apps/aiagent/fh.ai.js:263–292  ·  view source on GitHub ↗
(receivingCallback)

Source from the content-addressed store, hash-verified

261 }
262
263 async function prepareBuiltInModel(receivingCallback) {
264 if (!isBuiltInPromptSupported()) {
265 throw createBuiltInError('当前浏览器不支持 Chrome 内置 AI,请使用 Chrome 138+ 或切换云端服务。');
266 }
267
268 const availability = await globalThis.LanguageModel.availability(getBuiltInTextLanguageOptions());
269 emitStatus(receivingCallback, availability, undefined, '');
270
271 if (availability === 'unavailable') {
272 throw createBuiltInError('当前设备暂不满足 Chrome 内置 AI 运行条件,请切换 SiliconFlow 或自定义服务。');
273 }
274
275 let session;
276 try {
277 session = await globalThis.LanguageModel.create(buildBuiltInCreateOptions({
278 initialPrompts: [SYSTEM_PROMPT],
279 monitor(monitor) {
280 monitor.addEventListener('downloadprogress', event => {
281 emitStatus(receivingCallback, 'downloading', event.loaded || 0, 'Chrome 正在下载本机 AI 模型。');
282 });
283 }
284 }));
285 emitStatus(receivingCallback, 'available', 1, 'Chrome 内置 AI 已可用。');
286 return getBuiltInAvailability();
287 } finally {
288 if (session && typeof session.destroy === 'function') {
289 session.destroy();
290 }
291 }
292 }
293
294 /**
295 * 流式问答

Callers

nothing calls this directly

Calls 7

isBuiltInPromptSupportedFunction · 0.85
createBuiltInErrorFunction · 0.85
emitStatusFunction · 0.85
getBuiltInAvailabilityFunction · 0.85
destroyMethod · 0.80

Tested by

no test coverage detected