belso.utils package

Submodules

belso.utils.classes module

class belso.utils.classes.PROVIDERS[source]

Bases: object

A class that provides constants for supported schema providers. This allows for more readable code when specifying providers in the translate method.

ANTHROPIC = 'anthropic'
AZURE_OPENAI = 'azure_openai'
BELSO = 'belso'
GOOGLE = 'google'
HUGGINGFACE = 'huggingface'
JSON = 'json'
LANGCHAIN = 'langchain'
MISTRAL = 'mistral'
OLLAMA = 'ollama'
OPENAI = 'openai'
XML = 'xml'
classmethod get_all_providers()[source]

Get a list of all supported providers.

Return type:

list

Returns

  • list: A list of all provider constants.

belso.utils.logging module

belso.utils.logging.configure_logger(level=20, log_file=None, log_format=None, propagate=True, handler_config=None)[source]

Configure the belso logger without affecting parent loggers.

Return type:

None

Args

param level:

the logging level.

type level:

int

param log_file:

the path to the log file.

type log_file:

str

param log_format:

the log format.

type log_format:

str

param propagate:

whether to propagate logs to parent loggers.

type propagate:

bool

param handler_config:

additional configuration for handlers.

type handler_config:

Dict[str, Any]

belso.utils.logging.disable_logging()[source]

Temporarily disable belso logging.

Return type:

None

belso.utils.logging.get_logger(name=None)[source]

Get a logger instance for a specific module within belso.

Return type:

Logger

Args

param name:

the name of the module (will be prefixed with ‘belso.’).

type name:

str

Returns

  • logging.Logger: the logger instance.

belso.utils.logging.log_exception(e, message='An error occurred')[source]

Log an exception with consistent formatting.

Return type:

None

Args

param e:

the exception to log.

type e:

Exception

param message:

a message to accompany the exception.

type message:

str

belso.utils.logging.restore_logging()[source]

Restore belso logging to its previous state.

Return type:

None

belso.utils.schema_helpers module

belso.utils.schema_helpers.build_properties_dict(schema)[source]

Build a properties dictionary from a schema for JSON Schema formats.

Return type:

Dict[str, Dict[str, Any]]

Args

param schema:

the schema to build the properties dictionary from.

type schema:

Type[Schema]

Returns

  • Dict[str, Dict[str, Any]]: the properties dictionary.

belso.utils.schema_helpers.create_fallback_schema()[source]

Create a standard fallback schema when conversion fails.

Return type:

Type[Schema]

Returns

  • Type[Schema]: the fallback schema.

belso.utils.schema_helpers.is_schema_supported(schema, provider)[source]

Check if a schema is supported by a provider.

Return type:

bool

Args

param schema:

the schema to check.

type schema:

Type[Schema]

param provider:

the provider to check against.

type provider:

str

Returns

  • bool: True if the schema is supported, False otherwise.

belso.utils.schema_helpers.map_json_to_python_type(json_type)[source]

Map JSON Schema type to Python type.

Return type:

Type

Args

param json_type:

the JSON Schema type to map.

type json_type:

str

Returns

  • Type: the Python type.

belso.utils.schema_helpers.map_python_to_json_type(field_type)[source]

Map Python type to JSON Schema type.

Return type:

str

Args

param field_type:

the Python type to map.

type field_type:

Type

Returns

  • str: the JSON Schema type.

Module contents

class belso.utils.PROVIDERS[source]

Bases: object

A class that provides constants for supported schema providers. This allows for more readable code when specifying providers in the translate method.

ANTHROPIC = 'anthropic'
AZURE_OPENAI = 'azure_openai'
BELSO = 'belso'
GOOGLE = 'google'
HUGGINGFACE = 'huggingface'
JSON = 'json'
LANGCHAIN = 'langchain'
MISTRAL = 'mistral'
OLLAMA = 'ollama'
OPENAI = 'openai'
XML = 'xml'
classmethod get_all_providers()[source]

Get a list of all supported providers.

Return type:

list

Returns

  • list: A list of all provider constants.