@@ -546,7 +546,6 @@ def __init__(
546
546
)
547
547
self .previousPrompt = None
548
548
self ._lastSystem = None
549
- self ._model_ids = [model .id for model in self ._models ]
550
549
if self .conf ["saveSystem" ]:
551
550
# If the user has chosen to save the system prompt, use the last system prompt used by the user as the default value, otherwise use the default system prompt.
552
551
if "system" in self .data :
@@ -727,25 +726,7 @@ def __init__(
727
726
self .modelsListCtrl .Bind (wx .EVT_CONTEXT_MENU , self .onModelContextMenu )
728
727
self .modelsListCtrl .Bind (wx .EVT_LIST_ITEM_RIGHT_CLICK , self .onModelContextMenu )
729
728
self .modelsListCtrl .Bind (wx .EVT_RIGHT_UP , self .onModelContextMenu )
730
-
731
- for i , model in enumerate (self ._models ):
732
- self .modelsListCtrl .InsertItem (i , model .name )
733
- self .modelsListCtrl .SetItem (i , 1 , model .provider )
734
- self .modelsListCtrl .SetItem (i , 2 , model .id )
735
- self .modelsListCtrl .SetItem (i , 3 , str (model .contextWindow ))
736
- self .modelsListCtrl .SetItem (
737
- i ,
738
- 4 ,
739
- str (model .maxOutputToken ) if model .maxOutputToken > 1 else ""
740
- )
741
- model_id = conf ["modelVision" if self .pathList else "model" ]
742
- model_index = self ._getModelIndex (model_id )
743
- self .modelsListCtrl .SetItemState (
744
- model_index ,
745
- wx .LIST_STATE_SELECTED | wx .LIST_STATE_FOCUSED ,
746
- wx .LIST_STATE_SELECTED | wx .LIST_STATE_FOCUSED
747
- )
748
- self .modelsListCtrl .EnsureVisible (model_index )
729
+ self ._refreshModelsList ()
749
730
mainSizer .Add (modelsLabel , 0 , wx .ALL , 5 )
750
731
mainSizer .Add (self .modelsListCtrl , 0 , wx .ALL , 5 )
751
732
@@ -896,12 +877,6 @@ def __init__(
896
877
self .Bind (wx .EVT_CHAR_HOOK , self .onCharHook )
897
878
self .Bind (wx .EVT_CLOSE , self .onCancel )
898
879
899
-
900
- def _getModelIndex (self , model_id ):
901
- return list (self ._model_ids ).index (model_id ) if model_id in self ._model_ids else (
902
- list (self ._model_ids ).index (DEFAULT_MODEL_VISION ) if self .pathList else 0
903
- )
904
-
905
880
def addImageToList (
906
881
self ,
907
882
path ,
@@ -1035,11 +1010,65 @@ def showModelDetails(self, evt=None):
1035
1010
True
1036
1011
)
1037
1012
1013
+ def _getModelIndex (self , model_id ):
1014
+ for i , model in enumerate (self ._models ):
1015
+ if model .id == model_id :
1016
+ return i
1017
+ return - 1
1018
+
1019
+ def _refreshModelsList (self , model_to_select = None ):
1020
+ self .modelsListCtrl .DeleteAllItems ()
1021
+ favorite_models = self .data .get ("favorite_models" , [])
1022
+ self ._models = sorted (
1023
+ self ._models ,
1024
+ key = lambda model : (
1025
+ not model .id in favorite_models ,
1026
+ apikeymanager .AVAILABLE_PROVIDERS .index (model .provider ),
1027
+ model .id .lower ()
1028
+ ),
1029
+ reverse = False
1030
+ )
1031
+ for i , model in enumerate (self ._models ):
1032
+ self .modelsListCtrl .InsertItem (i , model .name )
1033
+ self .modelsListCtrl .SetItem (i , 1 , model .provider )
1034
+ self .modelsListCtrl .SetItem (i , 2 , model .id )
1035
+ self .modelsListCtrl .SetItem (i , 3 , str (model .contextWindow ))
1036
+ self .modelsListCtrl .SetItem (
1037
+ i ,
1038
+ 4 ,
1039
+ str (model .maxOutputToken ) if model .maxOutputToken > 1 else ""
1040
+ )
1041
+ model_id = model_to_select or self .conf ["modelVision" if self .pathList else "model" ]
1042
+ model_index = self ._getModelIndex (model_id )
1043
+ if model_index == - 1 :
1044
+ model_index = 0
1045
+ self .modelsListCtrl .SetItemState (
1046
+ model_index ,
1047
+ wx .LIST_STATE_SELECTED | wx .LIST_STATE_FOCUSED ,
1048
+ wx .LIST_STATE_SELECTED | wx .LIST_STATE_FOCUSED
1049
+ )
1050
+ self .modelsListCtrl .EnsureVisible (model_index )
1051
+
1052
+ def onFavoriteModel (self , evt ):
1053
+ model = self .getCurrentModel ()
1054
+ if not "favorite_models" in self .data :
1055
+ self .data ["favorite_models" ] = []
1056
+ if model .id in self .data .get ("favorite_models" , []):
1057
+ self .data ["favorite_models" ].remove (model .id )
1058
+ else :
1059
+ self .data ["favorite_models" ].append (model .id )
1060
+ self .saveData (True )
1061
+ self ._refreshModelsList (model .id )
1062
+
1038
1063
def onModelKeyDown (self , evt ):
1039
1064
if evt .GetKeyCode () == wx .WXK_SPACE :
1040
- self .showModelDetails ()
1065
+ if evt .GetModifiers () == wx .MOD_SHIFT :
1066
+ self .onFavoriteModel (evt )
1067
+ elif evt .GetModifiers () == wx .MOD_NONE :
1068
+ self .showModelDetails ()
1041
1069
else :
1042
1070
evt .Skip ()
1071
+
1043
1072
def onSubmit (self , evt ):
1044
1073
if not self .promptTextCtrl .GetValue ().strip () and not self .pathList :
1045
1074
self .promptTextCtrl .SetFocus ()
@@ -1660,8 +1689,13 @@ def message(
1660
1689
def onModelContextMenu (self , evt ):
1661
1690
menu = wx .Menu ()
1662
1691
item_id = wx .NewIdRef ()
1663
- menu .Append (item_id , _ ("Show model details" ) + " (Space)" )
1692
+ menu .Append (item_id , _ ("Show model & details" ) + " (Space)" )
1664
1693
self .Bind (wx .EVT_MENU , self .showModelDetails , id = item_id )
1694
+ isFavorite = self .getCurrentModel ().id in self .data .get ("favorite_models" , [])
1695
+ item_id = wx .NewIdRef ()
1696
+ label = _ ("Add to &favorites" ) if not isFavorite else _ ("Remove from &favorites" )
1697
+ menu .Append (item_id , f"{ label } (Shift+Space)" )
1698
+ self .Bind (wx .EVT_MENU , self .onFavoriteModel , id = item_id )
1665
1699
menu .AppendSeparator ()
1666
1700
self .modelsListCtrl .PopupMenu (menu )
1667
1701
menu .Destroy ()
0 commit comments