XFE Git
XFE Studio Git
Git 首页 全局搜索
XFE 主站 文档 NuGet
公开
关注 0 Fork 0 Star 1
返回提交历史

XFEstudio/gpt4free

feat(g4f/models.py): add versioning support for model retrieval

6e724836
kqlio67 <kqlio67@users.noreply.github.com>
提交于

代码差异

1 个文件 +42 -0
Modified g4f/models.py +42 -0
@@ -891,6 +891,17 @@ any_dark = Model(
891 891
892 892 )
893 893
894
895 class ModelVersions:
896 # Global Prefixes for All Models
897 GLOBAL_PREFIXES = [":latest"]
898
899 # Specific Prefixes for Particular Models
900 MODEL_SPECIFIC_PREFIXES = {
901 #frozenset(["gpt-3.5-turbo", "gpt-4"]): [":custom1", ":custom2"]
902 #frozenset(["gpt-3.5-turbo"]): [":custom"],
903 }
904
894 905 class ModelUtils:
895 906 """
896 907 Utility class for mapping string identifiers to Model instances.
@@ -1163,4 +1174,35 @@ class ModelUtils:
1163 1174 'any-dark': any_dark,
1164 1175 }
1165 1176
1177 @classmethod
1178 def get_model(cls, model_name: str) -> Model:
1179 # Checking for specific prefixes
1180 for model_set, specific_prefixes in ModelVersions.MODEL_SPECIFIC_PREFIXES.items():
1181 for prefix in specific_prefixes:
1182 if model_name.endswith(prefix):
1183 base_name = model_name[:-len(prefix)]
1184 if base_name in model_set:
1185 return cls.convert.get(base_name, None)
1186
1187 # Check for global prefixes
1188 for prefix in ModelVersions.GLOBAL_PREFIXES:
1189 if model_name.endswith(prefix):
1190 base_name = model_name[:-len(prefix)]
1191 return cls.convert.get(base_name, None)
1192
1193 # Check without prefix
1194 if model_name in cls.convert:
1195 return cls.convert[model_name]
1196
1197 raise KeyError(f"Model {model_name} not found")
1198
1199 @classmethod
1200 def get_available_versions(cls, model_name: str) -> list[str]:
1201 # Obtaining prefixes for a specific model
1202 prefixes = ModelVersions.GLOBAL_PREFIXES.copy()
1203 for model_set, specific_prefixes in ModelVersions.MODEL_SPECIFIC_PREFIXES.items():
1204 if model_name in model_set:
1205 prefixes.extend(specific_prefixes)
1206 return prefixes
1207
1166 1208 _all_models = list(ModelUtils.convert.keys())