gen_ai_hub.orchestration.models.template module

class gen_ai_hub.orchestration.models.template.TemplateValue(name: str, value: str | int | float)

Bases: NamedTuple

Represents a named value for use in template substitution.

This class pairs a name with a corresponding value, which can be a string, integer, or float. It’s designed to be used in template rendering processes where named placeholders are replaced with specific values.

name: str

The identifier for this template value.

value: str | int | float

The actual value to be used in substitution.

class gen_ai_hub.orchestration.models.template.Template(messages: List[Message], defaults: List[TemplateValue] | None = None, tools: List[dict | ChatCompletionTool] | None = None, response_format: text | json_object | ResponseFormatJsonSchema | None = None)

Bases: JSONSerializable

Represents a configurable template for generating prompts or conversations.

__init__(messages: List[Message], defaults: List[TemplateValue] | None = None, tools: List[dict | ChatCompletionTool] | None = None, response_format: text | json_object | ResponseFormatJsonSchema | None = None)

Initializes a Template instance.

Parameters:
  • messages (List[Message]) – list of prompt messages that form the template._

  • defaults (Optional[List[TemplateValue]], optional) – list of default values for template variables, defaults to None

  • tools (Optional[List[Union[dict, ChatCompletionTool]]], optional) – list of tool definitions, defaults to None

  • response_format (Optional[Union[ ResponseFormatType.TEXT, ResponseFormatType.JSON_OBJECT, ResponseFormatJsonSchema ]], optional) – response format that the model output should adhere to, defaults to None

to_dict() Dict[str, Any]
Converts the Template instance to a dictionary representation.

Serializes the template to a dictionary, converting tools as needed.

Raises:

ValueError – If an invalid tool is encountered in the tools list.

Returns:

A dictionary representation of the Template instance.

Return type:

Dict[str, Any]