@@ -2,6 +2,7 @@ import SwiftUI
22import ChatService
33import Persist
44import ComposableArchitecture
5+ import GitHubCopilotService
56
67public let SELECTED_LLM_KEY = " selectedLLM "
78
@@ -27,6 +28,18 @@ extension AppState {
2728 }
2829}
2930
31+ extension CopilotModelManager {
32+ static func getAvailableChatLLMs( ) -> [ LLMModel ] {
33+ let LLMs = CopilotModelManager . getAvailableLLMs ( )
34+ let availableModels = LLMs . filter (
35+ { $0. scopes. contains ( . chatPanel) }
36+ ) . map {
37+ LLMModel ( modelName: $0. modelName, modelFamily: $0. modelFamily)
38+ }
39+ return availableModels. isEmpty ? [ defaultModel] : availableModels
40+ }
41+ }
42+
3043struct LLMModel : Codable , Hashable {
3144 let modelName : String
3245 let modelFamily : String
@@ -35,12 +48,15 @@ struct LLMModel: Codable, Hashable {
3548let defaultModel = LLMModel ( modelName: " GPT-4o " , modelFamily: " gpt-4o " )
3649struct ModelPicker : View {
3750 @State private var selectedModel = defaultModel. modelName
38- @State private var models : [ LLMModel ] = [ defaultModel ]
3951 @State private var isHovered = false
4052 @State private var isPressed = false
4153
4254 init ( ) {
43- self . updateCurrentModel ( )
55+ self . updateCurrentModel ( )
56+ }
57+
58+ var models : [ LLMModel ] {
59+ CopilotModelManager . getAvailableChatLLMs ( )
4460 }
4561
4662 func updateCurrentModel( ) {
@@ -74,13 +90,9 @@ struct ModelPicker: View {
7490 isHovered = hovering
7591 }
7692 . onAppear ( ) {
93+ updateCurrentModel ( )
7794 Task {
78- updateCurrentModel ( )
79- self . models = await ChatService . shared. copilotModels ( ) . filter (
80- { $0. scopes. contains ( . chatPanel) }
81- ) . map {
82- LLMModel ( modelName: $0. modelName, modelFamily: $0. modelFamily)
83- }
95+ await refreshModels ( )
8496 }
8597 }
8698 . help ( " Pick Model " )
@@ -93,6 +105,14 @@ struct ModelPicker: View {
93105 let width = selectedModel. size ( withAttributes: attributes) . width
94106 return CGFloat ( width + 20 )
95107 }
108+
109+ @MainActor
110+ func refreshModels( ) async {
111+ let copilotModels = await ChatService . shared. copilotModels ( )
112+ if !copilotModels. isEmpty {
113+ CopilotModelManager . updateLLMs ( copilotModels)
114+ }
115+ }
96116}
97117
98118struct ModelPicker_Previews : PreviewProvider {
0 commit comments