Skip to content

Commit 44d0a9f

Browse files
committed
Reduce prewarm to just loadContext
1 parent f024896 commit 44d0a9f

File tree

1 file changed

+1
-32
lines changed

1 file changed

+1
-32
lines changed

Sources/AnyLanguageModel/Models/MLXLanguageModel.swift

Lines changed: 1 addition & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -367,39 +367,8 @@ import Foundation
367367
let hub = self.hub
368368
let directory = self.directory
369369

370-
let instructions = session.instructions?.description
371-
let tools = session.tools
372-
373370
Task {
374-
375-
let context = try await loadContext(modelId: modelId, hub: hub, directory: directory)
376-
377-
// Build chat history similar to respond() to prime the cache effectively
378-
var chat: [MLXLMCommon.Chat.Message] = []
379-
380-
// Add system instructions if present
381-
if let instructions, !instructions.isEmpty {
382-
chat.append(.init(role: .system, content: instructions))
383-
}
384-
385-
// Add prompt prefix or minimal user message
386-
let promptText = promptPrefix?.description ?? "."
387-
chat.append(.init(role: .user, content: promptText))
388-
389-
// Convert tools to MLX format
390-
let toolSpecs: [ToolSpec]? =
391-
tools.isEmpty
392-
? nil
393-
: tools.map { convertToolToMLXSpec($0) }
394-
395-
let userInput = MLXLMCommon.UserInput(
396-
chat: chat,
397-
processing: .init(resize: .init(width: 512, height: 512)),
398-
tools: toolSpecs
399-
)
400-
401-
// Prepare input - triggers tokenization and processor initialization
402-
_ = try await context.processor.prepare(input: userInput)
371+
_ = try await loadContext(modelId: modelId, hub: hub, directory: directory)
403372
}
404373
}
405374
}

0 commit comments

Comments
 (0)