Utilities

Constants

FORMATS

class belso.utils.formats.FORMATS[source]

Bases: object

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

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

Get a list of all supported providers.

Returns

  • list: a list of all provider constants.

Logging

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

Get a logger instance for a specific module within belso.

Args

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

Returns

  • logging.Logger: the logger instance.

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.

Args

  • level (int): the logging level. Defaults to logging.INFO.

  • log_file (Optional[str]): the path to the log file. Defaults to None.

  • log_format (Optional[str]): the log format. Defaults to None.

  • propagate (bool): whether to propagate logs to parent loggers. Defaults to true.

  • handler_config (Optional[Dict[str, Any]]): additional configuration for handlers. Defaults to None.

Detecting

belso.utils.detecting.detect_schema_format(schema)[source]

Detect the format of the input schema.

Args

  • schema (Any): the schema to detect.

Returns

  • str: the detected format.

Helpers

Mapping

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

Map Python type to JSON Schema type.

Args

  • field_type (Type): the Python type to map.

Returns

  • str: the JSON Schema type.

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

Map JSON Schema type to Python type.

Args

  • json_type (str): the JSON Schema type to map.

Returns

  • Type: the Python type.

Properties

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

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

Args

  • schema (Type[belso.Schema]): the schema to build the properties dictionary from.

Returns

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

Fallback

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

Create a standard fallback schema when conversion fails.

Returns

  • Type[belso.Schema]: the fallback schema.