Remove Ollama startup initialization

This commit is contained in:
Beingpax 2025-06-24 11:43:21 +05:45
parent 0befca3029
commit 9b0c2366b6
2 changed files with 12 additions and 14 deletions

View File

@ -161,7 +161,7 @@ class AIService: ObservableObject {
@Published private var selectedModels: [AIProvider: String] = [:]
private let userDefaults = UserDefaults.standard
private let ollamaService = OllamaService()
private lazy var ollamaService = OllamaService()
var connectedProviders: [AIProvider] {
AIProvider.allCases.filter { provider in
@ -205,12 +205,7 @@ class AIService: ObservableObject {
}
} else {
self.isAPIKeyValid = true
if selectedProvider == .ollama {
Task {
await ollamaService.checkConnection()
await ollamaService.refreshModels()
}
}
}
loadSavedModelSelections()
@ -456,6 +451,14 @@ class AIService: ObservableObject {
}
func enhanceWithOllama(text: String, systemPrompt: String) async throws -> String {
// Ensure connection is established before attempting enhancement
if !ollamaService.isConnected {
await ollamaService.checkConnection()
if ollamaService.isConnected && ollamaService.availableModels.isEmpty {
await ollamaService.refreshModels()
}
}
logger.notice("🔄 Sending transcription to Ollama for enhancement (model: \(self.ollamaService.selectedModel))")
do {
let result = try await ollamaService.enhance(text, withSystemPrompt: systemPrompt)

View File

@ -54,13 +54,8 @@ class OllamaService: ObservableObject {
self.baseURL = UserDefaults.standard.string(forKey: "ollamaBaseURL") ?? Self.defaultBaseURL
self.selectedModel = UserDefaults.standard.string(forKey: "ollamaSelectedModel") ?? "llama2"
// Initial connection check and model list fetch
Task {
await checkConnection()
if isConnected {
await refreshModels()
}
}
// Note: Removed automatic initialization to prevent startup delays
// Connection check and model refresh will be called when actually needed
}
@MainActor