belso package
Subpackages
- belso.schemas package
- belso.translator package
- Subpackages
- belso.translator.providers package
- Submodules
- belso.translator.providers.anthropic module
- belso.translator.providers.google module
- belso.translator.providers.huggingface module
- belso.translator.providers.langchain module
- belso.translator.providers.mistral module
- belso.translator.providers.ollama module
- belso.translator.providers.openai module
- Module contents
- belso.translator.serialization package
- belso.translator.utils package
- belso.translator.providers package
- Submodules
- belso.translator.translator module
- Module contents
- Subpackages
- belso.validator package
- belso.utils package
Module contents
- class belso.SchemaTranslator[source]
Bases:
object
- static detect_format(schema)[source]
Detect the format of a schema.
- Return type:
str
Args
schema: the schema to detect.
Returns
str: the detected format as a string.
- static from_json(json_input)[source]
Convert JSON data or a JSON file to a belso schema.
- Return type:
Type
Args
- param json_input:
either a JSON dictionary or a file path to a JSON file.
- type json_input:
Union[Dict[str, Any], str]
Returns
Type: the converted schema as a belso Schema subclass.
- static from_xml(xml_input)[source]
Convert XML data or an XML file to a belso schema.
- Return type:
Type
Args
- param xml_input:
either an XML string, Element, or a file path to an XML file.
- type xml_input:
Union[str, Any]
Returns
Type: the converted schema as a belso Schema subclass.
- static standardize(schema, from_format)[source]
Convert a schema from a specific format to our internal belso format.
- Return type:
Type
Args
schema: the schema to convert.
from_format: the format of the input schema (“google”, “ollama”, “openai”, “anthropic”, “json”, “xml”).
Returns
Type: the converted schema as a belso Schema subclass.
- static to_json(schema, file_path=None)[source]
Convert a schema to standardized JSON format and optionally save to a file.
- Return type:
Dict
[str
,Any
]
Args
- param schema:
the schema to convert.
- type schema:
Type
- param file_path:
optional path to save the JSON to a file.
- type file_path:
Optional[str]
Returns
Dict[str, Any]: the schema in JSON format.
- static to_xml(schema, file_path=None)[source]
Convert a schema to XML format and optionally save to a file.
- Return type:
str
Args
- param schema:
the schema to convert.
- type schema:
Type
- param file_path:
optional path to save the XML to a file.
- type file_path:
Optional[str]
Returns
str: the schema in XML format.
- static translate(schema, to, from_format=None)[source]
Translate a schema to a specific format. This method can automatically detect the input schema format and convert it to our internal format before translating to the target format.
- Return type:
Union
[Dict
[str
,Any
],Type
,str
]
Args
- param schema:
the schema to translate.
- type schema:
Any
- param to:
the target format. Can be a string or a belso.utils.PROVIDERS attribute.
- type to:
str
- param from_format:
optional format hint for the input schema, if None, the format will be auto-detected.
- type from_format:
Optional[str]
Returns
Union[Dict[str, Any], Type, str]: the translated schema in the target format.