gen_ai_hub.orchestration.models.response_format module

class gen_ai_hub.orchestration.models.response_format.ResponseFormatType(*values)

Bases: str, Enum

Enumerates the supported response format.

Response format that the model output should adhere to. This is the same as the OpenAI definition.

Values:

TEXT: Response format as text JSON_OBJECT: Response format as json object JSON_SCHEMA: Response format as defined json schema

TEXT = 'text'
JSON_OBJECT = 'json_object'
JSON_SCHEMA = 'json_schema'
class gen_ai_hub.orchestration.models.response_format.ResponseFormatText

Bases: JSONSerializable

Response format that the model output should adhere to.

to_dict()

Converts the ResponseFormatText instance to a dictionary.

Returns:

A dictionary representation of the ResponseFormatText.

Return type:

dict

class gen_ai_hub.orchestration.models.response_format.ResponseFormatJsonObject

Bases: JSONSerializable

Response format JSON Object that the model output should adhere to.

to_dict()

Converts the ResponseFormatJsonObject instance to a dictionary.

Returns:

A dictionary representation of the ResponseFormatJsonObject.

Return type:

dict

class gen_ai_hub.orchestration.models.response_format.ResponseFormatJsonSchema(name, schema: object = None, description: str | None = None, strict: bool = False)

Bases: JSONSerializable

Response format JSON Schema that the model output should adhere to.

__init__(name, schema: object = None, description: str | None = None, strict: bool = False)

Initializes a ResponseFormatJsonSchema instance.

Parameters:
  • name (str) – the name of the response format.

  • schema (object, optional) – the schema for the response format described as a JSON Schema object, defaults to None

  • description (Optional[str], optional) – A description of what the response format is for, defaults to None

  • strict (bool, optional) – Whether to enable strict schema adherence when generating the output, defaults to False

to_dict()

Converts the ResponseFormatJsonSchema instance to a dictionary.

Returns:

A dictionary representation of the ResponseFormatJsonSchema.

Return type:

dict

class gen_ai_hub.orchestration.models.response_format.ResponseFormatFactory

Bases: object

Factory class that maps response format input to classes that can handle to_dict conversion.

static create_response_format_object(response_format)

Creates a response format object based on the provided response format.

Parameters:

response_format (Union[ResponseFormatType, ResponseFormatJsonSchema]) – The response format input.

Returns:

An instance of the corresponding response format class.

Return type:

Optional[JSONSerializable]

class gen_ai_hub.orchestration.models.response_format.Validator

Bases: object

A utility class for validating response format names.

This class provides methods to validate the names of response formats to ensure they adhere to specified patterns and length constraints.

static validate_name(name)

Validates the name of the response format.

Parameters:

name (str) – The name to validate.

Raises:

ValueError – If the name does not match the required pattern or exceeds the maximum length.

Returns:

The validated name.

Return type:

str