@@ -80,15 +80,28 @@ def _process_endpoint(self, endpoint_name: str) -> Optional[List[str]]:
8080
8181 return entries
8282
83- def _write_droid_config (self , selected_entries : List [str ]) -> Path :
84- """Persist Droid config to ~/.factory/config.json."""
83+ def _write_droid_settings (self , selected_entries : List [str ]) -> Path :
84+ """Persist Droid custom models to ~/.factory/config.json."""
8585 config_dir = Path .home () / ".factory"
8686 config_file = config_dir / "config.json"
87- config_dir .mkdir (exist_ok = True )
87+ config_dir .mkdir (parents = True , exist_ok = True )
88+
89+ # Preserve existing settings (plugins, etc) and only update custom_models.
90+ settings : dict = {}
91+ if config_file .exists ():
92+ try :
93+ with open (config_file , "r" , encoding = "utf-8" ) as f :
94+ settings = json .load (f ) or {}
95+ except Exception :
96+ settings = {}
8897
8998 json_models = self ._build_models_json (selected_entries )
90- with open (config_file , "w" ) as f :
91- json .dump ({"custom_models" : json_models }, f , indent = 2 )
99+
100+ # Canonical location for Droid BYOK custom models.
101+ settings ["custom_models" ] = json_models
102+
103+ with open (config_file , "w" , encoding = "utf-8" ) as f :
104+ json .dump (settings , f , indent = 2 )
92105
93106 return config_file
94107
@@ -118,7 +131,7 @@ def run(self, args: List[str] = None) -> int:
118131 - Loads environment variables
119132 - Ensures required commands are available
120133 - Aggregates selected models from configured endpoints
121- - Writes a config.json in ~/.factory and runs the `droid` CLI
134+ - Writes custom_models to ~/.factory/config.json and runs the `droid` CLI
122135
123136 Args:
124137 args: List of arguments to pass to the Droid CLI
@@ -165,9 +178,9 @@ def run(self, args: List[str] = None) -> int:
165178
166179 print (f"Total models selected: { len (selected_entries )} \n " )
167180
168- # Persist Droid config to ~/.factory/config.json
169- config_file = self ._write_droid_config (selected_entries )
170- print (f"Droid config written to { config_file } \n " )
181+ # Persist Droid custom models to ~/.factory/config.json
182+ settings_file = self ._write_droid_settings (selected_entries )
183+ print (f"Droid settings written to { settings_file } \n " )
171184
172185 # Clean proxy env vars for child process and set TLS env
173186 env = self ._prepare_environment ()
@@ -185,7 +198,7 @@ def _build_models_json(self, entries: List[str]) -> List[dict]:
185198 parts = entry .split ("|" )
186199 if len (parts ) < 5 :
187200 continue
188- display , base_url , api_key , provider , max_tokens = parts [:5 ]
201+ display , base_url , api_key , _provider , max_tokens = parts [:5 ]
189202 model_id = display .split ("[" )[0 ].strip ()
190203 try :
191204 max_tokens_val = int (max_tokens )
@@ -197,7 +210,7 @@ def _build_models_json(self, entries: List[str]) -> List[dict]:
197210 "model" : model_id ,
198211 "base_url" : base_url ,
199212 "api_key" : api_key ,
200- "provider" : provider ,
213+ "provider" : "generic-chat-completion-api" ,
201214 "max_tokens" : max_tokens_val ,
202215 }
203216 )
0 commit comments