Remove Ollama startup initialization
This commit is contained in:
parent
0befca3029
commit
9b0c2366b6
@ -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)
|
||||
|
||||
@ -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
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user