diff --git a/api-reference/model/index.html b/api-reference/model/index.html index b850086..e1a74ab 100644 --- a/api-reference/model/index.html +++ b/api-reference/model/index.html @@ -2389,21 +2389,20 @@

format_search_order=[ "name", "meta_template", - "models_json", - "formats_json", - ], - *, - genconf=None, - schemaconf=None, - tokenizer=None, - ctx_len=2048, - n_gpu_layers=-1, - main_gpu=0, - n_batch=512, - seed=4294967295, - verbose=False, - **llamacpp_kwargs -) + "folder_json", + ], + *, + genconf=None, + schemaconf=None, + tokenizer=None, + ctx_len=2048, + n_gpu_layers=-1, + main_gpu=0, + n_batch=512, + seed=4294967295, + verbose=False, + **llamacpp_kwargs +)
@@ -2461,11 +2460,11 @@

-

Search order for auto-detecting format, "name" searches in the filename, "meta_template" looks in the model's metadata, "models_json", "formats_json" looks for these configs in file's folder. Defaults to ["name","meta_template", "models_json", "formats_json"].

+

Search order for auto-detecting format, "name" searches in the filename, "meta_template" looks in the model's metadata, "folder_json" looks for configs in file's folder. Defaults to ["name","meta_template", "folder_json"].

- ['name', 'meta_template', 'models_json', 'formats_json'] + ['name', 'meta_template', 'folder_json'] @@ -2718,7 +2717,7 @@

path: str, format: Optional[str] = None, - format_search_order: list[str] = ["name","meta_template", "models_json", "formats_json"], + format_search_order: list[str] = ["name", "meta_template", "folder_json"], *, @@ -2742,7 +2741,7 @@

Args: path: File path to the GGUF file. format: Chat template format to use with model. Leave as None for auto-detection. - format_search_order: Search order for auto-detecting format, "name" searches in the filename, "meta_template" looks in the model's metadata, "models_json", "formats_json" looks for these configs in file's folder. Defaults to ["name","meta_template", "models_json", "formats_json"]. + format_search_order: Search order for auto-detecting format, "name" searches in the filename, "meta_template" looks in the model's metadata, "folder_json" looks for configs in file's folder. Defaults to ["name","meta_template", "folder_json"]. genconf: Default generation configuration, which can be used in gen() and related. Defaults to None. tokenizer: An external initialized tokenizer to use instead of the created from the GGUF file. Defaults to None. ctx_len: Maximum context length to be used (shared for input and output). Defaults to 2048. @@ -4476,6 +4475,30 @@

+

Raises:

+ + + + + + + + + + + + + +
TypeDescription
+ ValueError + +
+

If trying to generate from an empty prompt.

+
+
+ + +

Returns:

@@ -4500,7 +4523,12 @@

Source code in sibila/model.py -

- - - - - -
1176
+            
1171
+1172
+1173
+1174
+1175
+1176
 1177
 1178
 1179
@@ -4528,35 +4556,42 @@ 

1201 1202 1203 -1204

def gen(self, 
-        thread: Thread,
-        genconf: Optional[GenConf] = None,
-        ) -> GenOut:
-    """Text generation from a Thread, used by the other model generation methods.
-    Doesn't raise an exception if an error occurs, always returns GenOut.
-
-    Args:
-        thread: The Thread object to use as model input.
-        genconf: Model generation configuration. Defaults to None, which uses model's default.
-
-    Returns:
-        A GenOut object with result, generated text, etc. 
-    """
-
-    if genconf is None:
-        genconf = self.genconf
+1204
+1205
def gen(self, 
+        thread: Thread,
+        genconf: Optional[GenConf] = None,
+        ) -> GenOut:
+    """Text generation from a Thread, used by the other model generation methods.
+    Doesn't raise an exception if an error occurs, always returns GenOut.
+
+    Args:
+        thread: The Thread object to use as model input.
+        genconf: Model generation configuration. Defaults to None, which uses model's default.
+
+    Raises:
+        ValueError: If trying to generate from an empty prompt.
+
+    Returns:
+        A GenOut object with result, generated text, etc. 
+    """
+
+    if genconf is None:
+        genconf = self.genconf
+
+    thread = self._prepare_gen_in(thread, genconf)
 
-    thread = self._prepare_gen_in(thread, genconf)
+    prompt = self.text_from_thread(thread)
 
-    prompt = self.text_from_thread(thread)
-
-    logger.debug(f"Prompt: █{prompt}█")
-
-    text,finish = self._gen_text(prompt, genconf)
-
-    out = self._prepare_gen_out(text, finish, genconf)
-
-    return out
+    if not prompt:
+        raise ValueError("Cannot generate from an empty prompt")
+
+    logger.debug(f"Prompt: █{prompt}█")
+
+    text,finish = self._gen_text(prompt, genconf)
+
+    out = self._prepare_gen_out(text, finish, genconf)
+
+    return out
 
diff --git a/api-reference/models/index.html b/api-reference/models/index.html index 49a428b..34ccd02 100644 --- a/api-reference/models/index.html +++ b/api-reference/models/index.html @@ -1660,15 +1660,6 @@ - - -
  • - - - is_format_supported - - -
  • @@ -1696,15 +1687,6 @@ -
  • - -
  • - - - merge_from - - -
  • @@ -2056,15 +2038,6 @@ -
  • - -
  • - - - is_format_supported - - -
  • @@ -2092,15 +2065,6 @@ -
  • - -
  • - - - merge_from - - -
  • @@ -2291,12 +2255,8 @@

    #

    setup(
    -    path=None,
    -    clear=False,
    -    add_cwd=True,
    -    load_base=True,
    -    load_from_env=True,
    -)
    +    path=None, clear=False, add_cwd=True, load_from_env=True
    +)
     
    @@ -2359,20 +2319,6 @@

    True

  • load_base - bool - -
    -

    Whether to load "base_models.json" and "base_formats.json" from "sibila/res" folder.

    -
    -
    - True -
    load_from_env @@ -2392,17 +2338,7 @@

    Source code in sibila/models.py -
    196
    -197
    -198
    -199
    -200
    -201
    -202
    -203
    -204
    -205
    -206
    +            
    206
     207
     208
     209
    @@ -2423,38 +2359,42 @@ 

    224 225 226 -227

    @classmethod
    -def setup(cls,
    -          path: Optional[Union[str,list[str]]] = None,
    -          clear: bool = False,
    -          add_cwd: bool = True,
    -          load_base: bool = True,
    -          load_from_env: bool = True):
    -    """Initialize models and formats directory from given model files folder and/or contained configuration files.
    -    Path can start with "~/" current account's home directory.
    -
    -    Args:
    -        path: Path to a folder or to "models.json" or "formats.json" configuration files. Defaults to None which tries to initialize from defaults and env variable.
    -        clear: Set to clear existing directories before loading from path arg.
    -        add_cwd: Add current working directory to search path.
    -        load_base: Whether to load "base_models.json" and "base_formats.json" from "sibila/res" folder.
    -        load_from_env: Load from SIBILA_MODELS env variable?
    -    """
    -
    -    if clear:
    -        cls.clear()
    -
    -    cls._ensure(add_cwd, 
    -                load_base,
    -                load_from_env)
    -
    -    if path is not None:
    -        if isinstance(path, str):
    -            path_list = [path]
    -        else:
    -            path_list = path
    -
    -        cls._read_any(path_list)
    +227
    +228
    +229
    +230
    +231
    +232
    +233
    +234
    @classmethod
    +def setup(cls,
    +          path: Optional[Union[str,list[str]]] = None,
    +          clear: bool = False,
    +          add_cwd: bool = True,
    +          load_from_env: bool = True):
    +    """Initialize models and formats directory from given model files folder and/or contained configuration files.
    +    Path can start with "~/" current account's home directory.
    +
    +    Args:
    +        path: Path to a folder or to "models.json" or "formats.json" configuration files. Defaults to None which tries to initialize from defaults and env variable.
    +        clear: Set to clear existing directories before loading from path arg.
    +        add_cwd: Add current working directory to search path.
    +        load_from_env: Load from SIBILA_MODELS env variable?
    +    """
    +
    +    if clear:
    +        cls.clear()
    +
    +    cls._ensure(add_cwd, 
    +                load_from_env)
    +
    +    if path is not None:
    +        if isinstance(path, str):
    +            path_list = [path]
    +        else:
    +            path_list = path
    +
    +        cls._read_any(path_list)
     
    @@ -2585,20 +2525,7 @@

    Source code in sibila/models.py -
    285
    -286
    -287
    -288
    -289
    -290
    -291
    -292
    -293
    -294
    -295
    -296
    -297
    -298
    +            
    298
     299
     300
     301
    @@ -2687,109 +2614,126 @@ 

    384 385 386 -387

    @classmethod
    -def create(cls,
    -           res_name: str,
    -
    -           # common to all providers
    -           genconf: Optional[GenConf] = None,
    -           ctx_len: Optional[int] = None,
    -
    -           # model-specific overriding:
    -           **over_args: Union[Any]) -> Model:
    -    """Create a model.
    -
    -    Args:
    -        res_name: Resource name in the format: provider:model_name, for example "llamacpp:openchat".
    -        genconf: Optional model generation configuration. Overrides set_genconf() value and any directory defaults. Defaults to None.
    -        ctx_len: Maximum context length to be used. Overrides directory defaults. Defaults to None.
    -        over_args: Model-specific creation args, which will override default args set in model directory.
    -
    -    Returns:
    -        Model: the initialized model.
    -    """
    -
    -    cls._ensure()        
    -
    -    # resolve "alias:name" res names, or "name": "link_name" links
    -    provider,name = resolve_model(cls.models_dir, res_name, cls.ALL_PROVIDER_NAMES)
    -    # arriving here, prov as a non-link dict entry
    -    logger.debug(f"Resolved model '{res_name}' to '{provider}','{name}'")
    -
    -    prov = cls.models_dir[provider]
    +387
    +388
    +389
    +390
    +391
    +392
    +393
    +394
    +395
    +396
    +397
    +398
    +399
    +400
    +401
    +402
    @classmethod
    +def create(cls,
    +           res_name: str,
    +
    +           # common to all providers
    +           genconf: Optional[GenConf] = None,
    +           ctx_len: Optional[int] = None,
    +
    +           # model-specific overriding:
    +           **over_args: Union[Any]) -> Model:
    +    """Create a model.
    +
    +    Args:
    +        res_name: Resource name in the format: provider:model_name, for example "llamacpp:openchat".
    +        genconf: Optional model generation configuration. Overrides set_genconf() value and any directory defaults. Defaults to None.
    +        ctx_len: Maximum context length to be used. Overrides directory defaults. Defaults to None.
    +        over_args: Model-specific creation args, which will override default args set in model directory.
     
    -    if name in prov:
    -        model_args = prov[name]
    -
    -        # _default(if any) <- model_args <- over_args
    -        args = (prov.get(cls.DEFAULT_ENTRY_NAME)).copy() or {}
    -        args.update(model_args)        
    -        args.update(over_args)
    +    Returns:
    +        Model: the initialized model.
    +    """
    +
    +    cls._ensure()        
    +
    +    models_dir = cls.fused_models_dir()
     
    -    else:                
    -        prov_conf = cls.PROVIDER_CONF[provider]    
    -
    -        if "name_passthrough" in prov_conf["flags"]:
    -            model_args = {
    -                "name": name                
    -            }
    -        else:
    -            raise ValueError(f"Model '{name}' not found in provider '{provider}'")
    +    # resolve "alias:name" res names, or "name": "link_name" links
    +    provider,name = resolve_model(models_dir, res_name, cls.ALL_PROVIDER_NAMES)
    +    # arriving here, prov as a non-link dict entry
    +    logger.debug(f"Resolved model '{res_name}' to '{provider}','{name}'")
    +
    +    prov = models_dir[provider]
    +
    +    if name in prov:
    +        model_args = prov[name]
     
    -        args = {}
    -        args.update(model_args)
    -        args.update(over_args)
    -
    +        # _default(if any) <- model_args <- over_args
    +        args = (prov.get(cls.DEFAULT_ENTRY_NAME)).copy() or {}
    +        args.update(model_args)        
    +        args.update(over_args)
     
    -    # override genconf, ctx_len
    -    if genconf is None:
    -        genconf = cls.genconf
    -
    -    if genconf is not None:
    -        args["genconf"] = genconf
    -
    -    elif "genconf" in args and isinstance(args["genconf"], dict):
    -        # transform dict into a GenConf instance:
    -        args["genconf"] = GenConf.from_dict(args["genconf"])
    -
    -    if ctx_len is not None:
    -        args["ctx_len"] = ctx_len
    +    else:                
    +        prov_conf = cls.PROVIDER_CONF[provider]    
    +
    +        if "name_passthrough" in prov_conf["flags"]:
    +            model_args = {
    +                "name": name                
    +            }
    +        else:
    +            raise ValueError(f"Model '{name}' not found in provider '{provider}'")
    +
    +        args = {}
    +        args.update(model_args)
    +        args.update(over_args)
     
    -    logger.debug(f"Creating model '{provider}:{name}' with resolved args: {args}")
    -
    -
    -    model: Model
    -    if provider == "llamacpp":
    -
    -        # resolve filename -> path
    -        path = cls._locate_file(args["name"])
    -        if path is None:
    -            raise FileNotFoundError(f"File not found in '{res_name}' while looking for file '{args['name']}'. Make sure you called Models.setup() with a path to the file's folder")
    -
    -        logger.debug(f"Resolved llamacpp model '{args['name']}' to '{path}'")
    -
    -        del args["name"]
    -        args["path"] = path
    -
    -        from .llamacpp import LlamaCppModel
    +
    +    # override genconf, ctx_len
    +    if genconf is None:
    +        genconf = cls.genconf
    +
    +    if genconf is not None:
    +        args["genconf"] = genconf
    +
    +    elif "genconf" in args and isinstance(args["genconf"], dict):
    +        # transform dict into a GenConf instance:
    +        args["genconf"] = GenConf.from_dict(args["genconf"])
    +
    +    if ctx_len is not None:
    +        args["ctx_len"] = ctx_len
    +
    +    logger.debug(f"Creating model '{provider}:{name}' with resolved args: {args}")
    +
     
    -        model = LlamaCppModel(**args)
    -
    +    model: Model
    +    if provider == "llamacpp":
     
    -    elif provider == "openai":
    -
    -        from .openai import OpenAIModel
    -
    -        model = OpenAIModel(**args)
    -
    -    """
    -    elif provider == "hf":
    -        from .hf import HFModel
    +        # resolve filename -> path
    +        path = cls._locate_file(args["name"])
    +        if path is None:
    +            raise FileNotFoundError(f"File not found in '{res_name}' while looking for file '{args['name']}'. Make sure you called Models.setup() with a path to the file's folder")
    +
    +        logger.debug(f"Resolved llamacpp model '{args['name']}' to '{path}'")
    +
    +        del args["name"]
    +        args["path"] = path
     
    -        model = HFModel(**args)
    -    """
    -
    -    return model
    +        from .llamacpp import LlamaCppModel
    +
    +        model = LlamaCppModel(**args)
    +
    +
    +    elif provider == "openai":
    +
    +        from .openai import OpenAIModel
    +
    +        model = OpenAIModel(**args)
    +
    +    """
    +    elif provider == "hf":
    +        from .hf import HFModel
    +
    +        model = HFModel(**args)
    +    """
    +
    +    return model
     
    @@ -2854,33 +2798,33 @@

    Source code in sibila/models.py -
    @classmethod
    -def add_models_search_path(cls,
    -                           path: Union[str,list[str]]):
    -    """Prepends new paths to model files search path.
    -
    -    Args:
    -        path: A path or list of paths to add to model search path.
    -    """
    -
    -    cls._ensure()
    -
    -    prepend_path(cls.models_search_path, path)
    -
    -    logger.debug(f"Adding '{path}' to search_path")
    +            
    @classmethod
    +def add_models_search_path(cls,
    +                           path: Union[str,list[str]]):
    +    """Prepends new paths to model files search path.
    +
    +    Args:
    +        path: A path or list of paths to add to model search path.
    +    """
    +
    +    cls._ensure()
    +
    +    prepend_path(cls.models_search_path, path)
    +
    +    logger.debug(f"Adding '{path}' to search_path")
     
    @@ -2945,23 +2889,23 @@

    Source code in sibila/models.py -
    + + + + + +
    @classmethod
    -def set_genconf(cls,
    -                genconf: GenConf):
    -    """Set the GenConf to use as default for model creation.
    -
    -    Args:
    -        genconf: Model generation configuration.
    -    """
    -    cls.genconf = genconf
    +            
    @classmethod
    +def set_genconf(cls,
    +                genconf: GenConf):
    +    """Set the GenConf to use as default for model creation.
    +
    +    Args:
    +        genconf: Model generation configuration.
    +    """
    +    cls.genconf = genconf
     
    @@ -2987,7 +2931,9 @@

    #

    -
    list_models(name_query, providers, resolved_values)
    +
    list_models(
    +    name_query, providers, include_base, resolved_values
    +)
     
    @@ -3035,6 +2981,20 @@

    required

    include_base + bool + +
    +

    Also list fused values from base_models_dir.

    +
    +
    + required +
    resolved_values @@ -3078,22 +3038,7 @@

    Source code in sibila/models.py -
    421
    -422
    -423
    -424
    -425
    -426
    -427
    -428
    -429
    -430
    -431
    -432
    -433
    -434
    -435
    -436
    +            
    436
     437
     438
     439
    @@ -3128,57 +3073,82 @@ 

    468 469 470 -471

    @classmethod
    -def list_models(cls,
    -                name_query: str,
    -                providers: list[str],
    -                resolved_values: bool) -> dict:
    -    """List format entries matching query.
    -
    -    Args:
    -        name_query: Case-insensitive substring to match model names. Empty string for all.
    -        providers: Filter by these exact provider names. Empty list for all.
    -        resolved_values: Return resolved entries or raw ones.
    -
    -    Returns:
    -        A dict where keys are model res_names and values are respective entries.
    -    """
    -
    -    cls._ensure()
    -
    -    out = {}
    -
    -    name_query = name_query.lower()
    -
    -    for prov_name in cls.models_dir:
    -
    -        if providers and prov_name not in providers:
    -            continue
    -
    -        prov_dic = cls.models_dir[prov_name]
    +471
    +472
    +473
    +474
    +475
    +476
    +477
    +478
    +479
    +480
    +481
    +482
    +483
    +484
    +485
    +486
    +487
    +488
    +489
    +490
    +491
    @classmethod
    +def list_models(cls,
    +                name_query: str,
    +                providers: list[str],
    +                include_base: bool,
    +                resolved_values: bool) -> dict:
    +    """List format entries matching query.
    +
    +    Args:
    +        name_query: Case-insensitive substring to match model names. Empty string for all.
    +        providers: Filter by these exact provider names. Empty list for all.
    +        include_base: Also list fused values from base_models_dir.
    +        resolved_values: Return resolved entries or raw ones.
     
    -        for name in prov_dic:
    -
    -            if name == cls.DEFAULT_ENTRY_NAME:
    -                continue
    -
    -            if name_query and name_query not in name.lower():
    -                continue
    +    Returns:
    +        A dict where keys are model res_names and values are respective entries.
    +    """
    +
    +    cls._ensure()
    +
    +    models_dir = cls.fused_models_dir() if include_base else cls.models_dir
     
    -            entry_res_name = prov_name + ":" + name
    +    out = {}
     
    -            if resolved_values:
    -                res = cls.get_model_entry(entry_res_name) # type: ignore[assignment]
    -                if res is None:
    -                    continue
    -                else:
    -                    val = res[1]
    -            else:
    -                val = prov_dic[name]
    +    name_query = name_query.lower()
    +
    +    for prov_name in models_dir:
    +
    +        if providers and prov_name not in providers:
    +            continue
    +
    +        prov_dic = models_dir[prov_name]
     
    -            out[entry_res_name] = val
    +        for name in prov_dic:
     
    -    return out
    +            if name == cls.DEFAULT_ENTRY_NAME:
    +                continue
    +
    +            if name_query and name_query not in name.lower():
    +                continue
    +
    +            entry_res_name = prov_name + ":" + name
    +
    +            if resolved_values:
    +                # okay to use get_model_entry() because it resolves to fused
    +                res = cls.get_model_entry(entry_res_name) # type: ignore[assignment]
    +                if res is None:
    +                    continue
    +                else:
    +                    val = res[1]
    +            else:
    +                val = prov_dic[name]
    +
    +            out[entry_res_name] = val
    +
    +    return out
     
    @@ -3267,55 +3237,59 @@

    Source code in sibila/models.py -
    477
    -478
    -479
    -480
    -481
    -482
    -483
    -484
    -485
    -486
    -487
    -488
    -489
    -490
    -491
    -492
    -493
    -494
    -495
    -496
    -497
    +            
    @classmethod
    -def get_model_entry(cls,
    -                    res_name: str) -> Union[tuple[str,dict],None]:
    -    """Get a resolved model entry. Resolved means following any links.
    -
    -    Args:
    -        res_name: Resource name in the format: provider:model_name, for example "llamacpp:openchat".
    -
    -    Returns:
    -        Resolved entry (res_name,dict) or None if not found.
    -    """
    -
    -    cls._ensure()        
    -
    -    # resolve "alias:name" res names, or "name": "link_name" links
    -    provider,name = resolve_model(cls.models_dir, res_name, cls.ALL_PROVIDER_NAMES)
    -    # arriving here, prov as a non-link dict entry
    -    logger.debug(f"Resolved model '{res_name}' to '{provider}','{name}'")
    -
    -    prov = cls.models_dir[provider]
    -
    -    if name in prov:
    -        return provider + ":" + name, prov[name]
    -    else:
    -        return None
    +501
    +502
    +503
    +504
    +505
    +506
    +507
    +508
    +509
    +510
    +511
    +512
    +513
    +514
    +515
    +516
    +517
    +518
    +519
    +520
    +521
    +522
    +523
    @classmethod
    +def get_model_entry(cls,
    +                    res_name: str) -> Union[tuple[str,dict],None]:
    +    """Get a resolved model entry. Resolved means following any links.
    +
    +    Args:
    +        res_name: Resource name in the format: provider:model_name, for example "llamacpp:openchat".
    +
    +    Returns:
    +        Resolved entry (res_name,dict) or None if not found.
    +    """
    +
    +    cls._ensure()        
    +
    +    models_dir = cls.fused_models_dir()
    +
    +    # resolve "alias:name" res names, or "name": "link_name" links
    +    provider,name = resolve_model(models_dir, res_name, cls.ALL_PROVIDER_NAMES)
    +    # arriving here, prov as a non-link dict entry
    +    logger.debug(f"Resolved model '{res_name}' to '{provider}','{name}'")
    +
    +    prov = models_dir[provider]
    +
    +    if name in prov:
    +        return provider + ":" + name, prov[name]
    +    else:
    +        return None
     
    @@ -3348,13 +3322,13 @@

    Source code in sibila/models.py -
    @classmethod
    -def has_model_entry(cls,
    -                    res_name: str) -> bool:
    -    return cls.get_model_entry(res_name) is not None
    +            
    @classmethod
    +def has_model_entry(cls,
    +                    res_name: str) -> bool:
    +    return cls.get_model_entry(res_name) is not None
     
    @@ -3487,29 +3461,7 @@

    Source code in sibila/models.py -
    511
    -512
    -513
    -514
    -515
    -516
    -517
    -518
    -519
    -520
    -521
    -522
    -523
    -524
    -525
    -526
    -527
    -528
    -529
    -530
    -531
    -532
    -533
    +            
    533
     534
     535
     536
    @@ -3523,43 +3475,65 @@ 

    544 545 546 -547

    @classmethod
    -def set_model(cls,
    -              res_name: str,
    -              model_name: str,
    -              format_name: Optional[str] = None,
    -              genconf: Optional[GenConf] = None):
    -    """Add model configuration for given res_name.
    -
    -    Args:
    -        res_name: A name in the form "provider:model_name", for example "openai:gtp-4".
    -        model_name: Model name or filename identifier.
    -        format_name: Format name used by model. Defaults to None.
    -        genconf: Base GenConf to use when creating model. Defaults to None.
    -
    -    Raises:
    -        ValueError: If unknown provider.
    -    """
    -
    -    cls._ensure()
    -
    -    provider,name = provider_name_from_urn(res_name, False)
    -    if provider not in cls.ALL_PROVIDER_NAMES:
    -        raise ValueError(f"Unknown provider '{provider}' in '{res_name}'")
    -
    -    entry: dict = {
    -        "name": model_name
    -    }
    -
    -    if format_name:
    -        if not cls.has_format_entry(format_name):
    -            raise ValueError(f"Could not find format '{format_name}'")
    -        entry["format"] = format_name
    -
    -    if genconf:
    -        entry["genconf"] = genconf.as_dict()
    +547
    +548
    +549
    +550
    +551
    +552
    +553
    +554
    +555
    +556
    +557
    +558
    +559
    +560
    +561
    +562
    +563
    +564
    +565
    +566
    +567
    +568
    +569
    @classmethod
    +def set_model(cls,
    +              res_name: str,
    +              model_name: str,
    +              format_name: Optional[str] = None,
    +              genconf: Optional[GenConf] = None):
    +    """Add model configuration for given res_name.
    +
    +    Args:
    +        res_name: A name in the form "provider:model_name", for example "openai:gtp-4".
    +        model_name: Model name or filename identifier.
    +        format_name: Format name used by model. Defaults to None.
    +        genconf: Base GenConf to use when creating model. Defaults to None.
     
    -    cls.models_dir[provider][name] = entry
    +    Raises:
    +        ValueError: If unknown provider.
    +    """
    +
    +    cls._ensure()
    +
    +    provider,name = provider_name_from_urn(res_name, False)
    +    if provider not in cls.ALL_PROVIDER_NAMES:
    +        raise ValueError(f"Unknown provider '{provider}' in '{res_name}'")
    +
    +    entry: dict = {
    +        "name": model_name
    +    }
    +
    +    if format_name:
    +        if not cls.has_format_entry(format_name):
    +            raise ValueError(f"Could not find format '{format_name}'")
    +        entry["format"] = format_name
    +
    +    if genconf:
    +        entry["genconf"] = genconf.as_dict()
    +
    +    cls.models_dir[provider][name] = entry
     
    @@ -3695,29 +3669,7 @@

    Source code in sibila/models.py -
    552
    -553
    -554
    -555
    -556
    -557
    -558
    -559
    -560
    -561
    -562
    -563
    -564
    -565
    -566
    -567
    -568
    -569
    -570
    -571
    -572
    -573
    -574
    +            
    574
     575
     576
     577
    @@ -3737,49 +3689,71 @@ 

    591 592 593 -594

    @classmethod
    -def update_model(cls,
    -                 res_name: str,
    -                 model_name: Optional[str] = None,
    -                 format_name: Optional[str] = None,
    -                 genconf: Union[GenConf,str,None] = None):
    -
    -    """update model fields
    -
    -    Args:
    -        res_name: A name in the form "provider:model_name", for example "openai:gtp-4".
    -        model_name: Model name or filename identifier. Defaults to None.
    -        format_name: Format name used by model. Use "" to delete. Defaults to None.
    -        genconf: Base GenConf to use when creating model. Defaults to None.
    -
    -    Raises:
    -        ValueError: If unknown provider.
    -    """
    -
    -    cls._ensure()
    -
    -    provider,name = provider_name_from_urn(res_name, False)
    -    if provider not in cls.ALL_PROVIDER_NAMES:
    -        raise ValueError(f"Unknown provider '{provider}' in '{res_name}'")
    -
    -    entry = cls.models_dir[provider][name]
    -
    -    if model_name:
    -        entry["name"] = model_name
    -
    -    if format_name is not None:
    -        if format_name != "":
    -            if not cls.has_format_entry(format_name):
    -                raise ValueError(f"Could not find format '{format_name}'")
    -            entry["format"] = format_name
    -        else:
    -            del entry["format"]
    -
    -    if genconf is not None:
    -        if genconf != "":
    -            entry["genconf"] = genconf
    -        else:
    -            del entry["genconf"]
    +594
    +595
    +596
    +597
    +598
    +599
    +600
    +601
    +602
    +603
    +604
    +605
    +606
    +607
    +608
    +609
    +610
    +611
    +612
    +613
    +614
    +615
    +616
    @classmethod
    +def update_model(cls,
    +                 res_name: str,
    +                 model_name: Optional[str] = None,
    +                 format_name: Optional[str] = None,
    +                 genconf: Union[GenConf,str,None] = None):
    +
    +    """update model fields
    +
    +    Args:
    +        res_name: A name in the form "provider:model_name", for example "openai:gtp-4".
    +        model_name: Model name or filename identifier. Defaults to None.
    +        format_name: Format name used by model. Use "" to delete. Defaults to None.
    +        genconf: Base GenConf to use when creating model. Defaults to None.
    +
    +    Raises:
    +        ValueError: If unknown provider.
    +    """
    +
    +    cls._ensure()
    +
    +    provider,name = provider_name_from_urn(res_name, False)
    +    if provider not in cls.ALL_PROVIDER_NAMES:
    +        raise ValueError(f"Unknown provider '{provider}' in '{res_name}'")
    +
    +    entry = cls.models_dir[provider][name]
    +
    +    if model_name:
    +        entry["name"] = model_name
    +
    +    if format_name is not None:
    +        if format_name != "":
    +            if not cls.has_format_entry(format_name):
    +                raise ValueError(f"Could not find format '{format_name}'")
    +            entry["format"] = format_name
    +        else:
    +            del entry["format"]
    +
    +    if genconf is not None:
    +        if genconf != "":
    +            entry["genconf"] = genconf
    +        else:
    +            del entry["genconf"]
     
    @@ -3882,29 +3856,7 @@