Skip to content

Commit 829e467

Browse files
mitya52MarcMcIntosh
authored andcommitted
move model record logic to model assigner (#658)
1 parent 0fdcd60 commit 829e467

File tree

2 files changed

+16
-8
lines changed

2 files changed

+16
-8
lines changed

refact-server/refact_webgui/webgui/selfhost_fastapi_completions.py

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -251,10 +251,7 @@ def _select_default_model(models: List[str]) -> str:
251251
completion_models = {}
252252
for model_name in running_models.get("completion", []):
253253
if model_info := self._model_assigner.models_db.get(_get_base_model_info(model_name)):
254-
completion_models[model_name] = {
255-
"n_ctx": model_info["T"],
256-
"supports_scratchpads": model_info["supports_scratchpads"]["completion"],
257-
}
254+
completion_models[model_name] = self._model_assigner.to_completion_model_record(model_info)
258255
elif model := available_third_party_models().get(model_name):
259256
completion_models[model_name] = model.to_completion_model_record()
260257
else:
@@ -265,10 +262,7 @@ def _select_default_model(models: List[str]) -> str:
265262
chat_models = {}
266263
for model_name in running_models.get("chat", []):
267264
if model_info := self._model_assigner.models_db.get(_get_base_model_info(model_name)):
268-
chat_models[model_name] = {
269-
"n_ctx": model_info["T"],
270-
"supports_scratchpads": model_info["supports_scratchpads"]["chat"],
271-
}
265+
chat_models[model_name] = self._model_assigner.to_chat_model_record(model_info)
272266
elif model := available_third_party_models().get(model_name):
273267
chat_models[model_name] = model.to_chat_model_record()
274268
else:

refact-server/refact_webgui/webgui/selfhost_model_assigner.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,20 @@ def share_gpu_backends(self) -> Set[str]:
107107
def models_db(self) -> Dict[str, Any]:
108108
return models_mini_db
109109

110+
@staticmethod
111+
def to_completion_model_record(model_info: Dict[str, Any]) -> Dict[str, Any]:
112+
return {
113+
"n_ctx": model_info["T"],
114+
"supports_scratchpads": model_info["supports_scratchpads"]["completion"],
115+
}
116+
117+
@staticmethod
118+
def to_chat_model_record(model_info: Dict[str, Any]) -> Dict[str, Any]:
119+
return {
120+
"n_ctx": model_info["T"],
121+
"supports_scratchpads": model_info["supports_scratchpads"]["chat"],
122+
}
123+
110124
def _model_assign_to_groups(self, model_assign: Dict[str, Dict]) -> List[ModelGroup]:
111125
model_groups: List[ModelGroup] = []
112126
shared_group = ModelGroup()

0 commit comments

Comments
 (0)