diff --git a/体己/AI/LLMSession.swift b/体己/AI/LLMSession.swift index 5320d84..dc9a1bc 100644 --- a/体己/AI/LLMSession.swift +++ b/体己/AI/LLMSession.swift @@ -1,12 +1,7 @@ import Foundation - -// TODO: 添加 MLX 依赖后取消注释 -// import MLX -// import MLXLLM -// import MLXLMCommon - -// 临时占位符类型,等添加 MLX 依赖后删除 -#if false +import MLX +import MLXLLM +import MLXLMCommon /// 封装 MLX 语言模型的流式生成,actor 保证单线程访问。 /// 基于 mlx-swift-examples 2.29.1(commit 9bff95ca)的 API。 @@ -70,6 +65,7 @@ actor LLMSession { break } } + // 取消路径无需同步,避免浪费 GPU 阻塞 if !Task.isCancelled { MLX.GPU.synchronize() } @@ -83,23 +79,3 @@ actor LLMSession { } } } - -#endif - -// 临时实现,用于编译通过 -class ModelContainer: @unchecked Sendable { - init() {} -} - -struct ModelConfiguration { - let directory: URL - init(directory: URL) { self.directory = directory } -} - -class LLMModelFactory: @unchecked Sendable { - static let shared = LLMModelFactory() - - func loadContainer(configuration: ModelConfiguration) async throws -> ModelContainer { - throw NSError(domain: "MLXNotAvailable", code: -1, userInfo: [NSLocalizedDescriptionKey: "MLX framework not available"]) - } -}