Generation configs, results and errors
Generation Configs#
GenConf
dataclass
#
Model generation configuration, used in Model.gen() and variants.
max_tokens
class-attribute
instance-attribute
#
Maximum output token length. Special value of 0 means all available context length, special values between -1 and -100 mean a -percentage of ctx_len. In some providers, a value of 0 also signals that max_tokens is not used/sent. For example -20 allows output up to 20% of ctx_len.
stop
class-attribute
instance-attribute
#
List of generation stop text sequences
temperature
class-attribute
instance-attribute
#
Generation temperature. Use 0 to always pick the most probable output, without random sampling. Larger positive values will produce more random outputs.
top_p
class-attribute
instance-attribute
#
Nucleus sampling top_p value. Only applies if temperature > 0.
format
class-attribute
instance-attribute
#
Output format: "text" or "json". For JSON output, text is validated as in json.loads(). Thread msgs must explicitly request JSON output or a warning will be emitted if string json not present (this is automatically done in Model.json() and related calls).
json_schema
class-attribute
instance-attribute
#
A JSON schema to validate the JSON output. Thread msgs must list the JSON schema and request its use; must also set the format to "json".
special
class-attribute
instance-attribute
#
Special model or provider-specific generation arguments. Args in the base dict are included unconditionally for a model, while args in sub-keys with the model's provider name are only used for models from that provider, for example "openai": {...} values are only used in OpenAI models.
__call__ #
Return a copy of the current GenConf updated with values in kwargs. Doesn't modify object. Key 'special' is updated element-wise.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
**kwargs |
Any
|
update settings of the same names in the returned copy. |
{}
|
Raises:
Type | Description |
---|---|
KeyError
|
If key does not exist. |
Returns:
Type | Description |
---|---|
Self
|
A copy of the current object with kwargs values updated. Doesn't modify object. |
Source code in sibila/gen.py
clone #
as_dict #
from_dict
staticmethod
#
resolve_max_tokens #
Calculate actual max_tokens value for cases where it's zero or a percentage of model's ctx_len)
Parameters:
Name | Type | Description | Default |
---|---|---|---|
ctx_len |
int
|
Model's context length. |
required |
max_tokens_limit |
Optional[int]
|
Optional model's limit for max_tokens. Defaults to None. |
None
|
Returns:
Type | Description |
---|---|
int
|
An actual model maximum number of output tokens. |
Source code in sibila/gen.py
resolve_special #
Compiles settings from the 'special' field, for model and provider.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
provider |
Optional[str]
|
If set will include any 'special' settings specified for that provider, inside a key named after the provider. If not given, only base keys are added. |
None
|
Returns:
Type | Description |
---|---|
dict
|
description |
Source code in sibila/gen.py
JSchemaConf
dataclass
#
Configuration for JSON schema massaging and validation.
resolve_refs
class-attribute
instance-attribute
#
Set for $ref references to be resolved and replaced with actual definition.
collapse_single_combines
class-attribute
instance-attribute
#
Any single-valued "oneOf"/"anyOf" is replaced with the actual value.
description_from_title
class-attribute
instance-attribute
#
If a value doesn't have a description entry, make one from its title or name.
- 0: don't make description from name
- 1: copy title or name to description
- 2: 1: + capitalize first letter and convert _ to space: class_label -> "class label".
force_all_required
class-attribute
instance-attribute
#
Force all entries in an object to be required (except removed defaults if remove_with_default=True).
remove_with_default
class-attribute
instance-attribute
#
Delete any values that have a "default" annotation.
default_to_last
class-attribute
instance-attribute
#
Move any default value entry into the last position of properties dict.
additional_allowed_root_keys
class-attribute
instance-attribute
#
By default only the following properties are allowed in schema's root: description, properties, type, required, additionalProperties, allOf, anyOf, oneOf, not Add to this list to allow additional root properties.
pydantic_strict_validation
class-attribute
instance-attribute
#
Validate JSON values in a strict manner or not. None means validate individually per each value in the obj. (for example in pydantic with: Field(strict=True)).
Results#
GenRes #
Model generation result.
OK_LENGTH
class-attribute
instance-attribute
#
Generation stopped due to reaching max_tokens.
ERROR_JSON
class-attribute
instance-attribute
#
Invalid JSON: this is often due to the model returning OK_LENGTH (finished due to max_tokens reached), which cuts off the JSON text.
ERROR_JSON_SCHEMA_VAL
class-attribute
instance-attribute
#
Failed JSON schema validation.
ERROR_JSON_SCHEMA_ERROR
class-attribute
instance-attribute
#
JSON schema itself is not valid.
from_finish_reason
staticmethod
#
Convert a ChatCompletion finish result into a GenRes.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
finish |
str
|
ChatCompletion finish result. |
required |
Returns:
Type | Description |
---|---|
Any
|
A GenRes result. |
Source code in sibila/gen.py
as_text
staticmethod
#
Returns a friendlier description of the result.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
res |
Any
|
Model output result. |
required |
Raises:
Type | Description |
---|---|
ValueError
|
If unknown GenRes. |
Returns:
Type | Description |
---|---|
str
|
A friendlier description of the GenRes. |
Source code in sibila/gen.py
Errors#
GenError #
Model generation exception, raised when the model was unable to return a response.
An error has happened during model generation.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
out |
GenOut
|
Model output |
required |
Source code in sibila/gen.py
raise_if_error
staticmethod
#
Raise an exception if the model returned an error
Parameters:
Name | Type | Description | Default |
---|---|---|---|
out |
GenOut
|
Model returned info. |
required |
ok_length_is_error |
bool
|
Should a result of GenRes.OK_LENGTH be considered an error? |
required |
Raises:
Type | Description |
---|---|
GenError
|
If an error was returned by model. |
Source code in sibila/gen.py
GenOut
dataclass
#
Model output, returned by gen_extract(), gen_json() and other model calls that don't raise exceptions.