gen_ai_hub.prompt_registry package

class gen_ai_hub.prompt_registry.PromptTemplateClient(proxy_client: GenAIHubProxyClient | None = None)

Bases: PromptRegistryClient

Client for interacting with the Prompt Registry Prompt Template API.

https://api.sap.com/api/PROMPT_REGISTRY_API/overview

create_prompt_template(name: str, version: str, scenario: str, prompt_template_spec: PromptTemplateSpec) PromptTemplatePostResponse

Create or update a prompt template.

Parameters:
  • name (str) – the name of the prompt template.

  • version (str) – the version of the prompt template.

  • scenario (str) – the scenario name of the prompt template.

  • prompt_template_spec (PromptTemplateSpec) – the specification of the prompt template.

Returns:

A PromptTemplatePostResponse object.

Return type:

PromptTemplatePostResponse

delete_prompt_template_by_id(template_id: str) PromptTemplateDeleteResponse

Delete a specific version of the prompt template by ID.

Parameters:

template_id (str) – The ID of the prompt template to delete.

Returns:

A PromptTemplateDeleteResponse object.

Return type:

PromptTemplateDeleteResponse

export_prompt_template(template_id: str) bytes

Export a design time template in a declarative compatible yaml file. Supports only single file export.

Parameters:

template_id (str) – The id of the prompt template to export.

Returns:

bytes: The content of the exported file

Return type:

bytes

fill_prompt_template(scenario: str, name: str, version: str, input_params: dict, metadata: bool = False) PromptTemplateSubstitutionResponse

Replace the placeholders of the prompt template referenced via scenario-name-version with user provided values.

Parameters:
  • scenario (str) – the scenario name of the prompt template.

  • name (str) – the name of the prompt template.

  • version (str) – the version of the prompt template.

  • input_params (dict) – User provided values to replace the placeholders of the prompt template.

  • metadata (bool, optional) – False(default), True return resource object with all details.

Returns:

A PromptTemplateSubstitutionResponse object.

Return type:

PromptTemplateSubstitutionResponse

fill_prompt_template_by_id(template_id: str, input_params: dict, metadata: bool = False) PromptTemplateSubstitutionResponse

Replace the placeholders of the prompt template referenced via template_id with user provided values.

Parameters:
  • template_id (str) – The ID of the prompt template.

  • input_params (dict) – User provided values to replace the placeholders of the prompt template.

  • metadata (bool, optional) – False(default), True return resource object with all details.

Returns:

A PromptTemplateSubstitutionResponse object.

Return type:

PromptTemplateSubstitutionResponse

get_prompt_template_by_id(template_id: str) PromptTemplateGetResponse

Retrieve a specific version of the prompt template by ID.

Parameters:

template_id (str) – The ID of the prompt template to retrieve.

Returns:

A PromptTemplateGetResponse object.

Return type:

PromptTemplateGetResponse

get_prompt_template_history(scenario: str, name: str, version: str) PromptTemplateListResponse

Retrieve the history of edits to the prompt template. Only for imperative managed prompt templates.

Parameters:
  • scenario (str) – The scenario name of the prompt template.

  • name (str) – The name of the prompt template.

  • version (str) – The version ID of the prompt template.

Returns:

A PromptTemplateListResponse object.

Return type:

PromptTemplateListResponse

get_prompt_templates(scenario: str, name: str, version: str, retrieve: str = None, include_spec: bool = None) PromptTemplateListResponse

Retrieve the latest version of every prompt template based on the filters.

Parameters:
  • scenario (str) – the scenario name of the prompt template.

  • name (str) – the name of the prompt template.

  • version (str) – the version of the prompt template.

  • retrieve (str, optional) – both(default), imperative, declarative

  • include_spec (bool, optional) – false(default), true

Returns:

A PromptTemplateListResponse object.

Return type:

PromptTemplateListResponse

import_prompt_template(file: bytes) PromptTemplatePostResponse

Import a runtime/declarative prompt template into the design time environment.

Parameters:

file (bytes) – binary file content

Returns:

A PromptTemplatePostResponse object.

Return type:

PromptTemplatePostResponse

class gen_ai_hub.prompt_registry.OrchestrationConfigClient(proxy_client: GenAIHubProxyClient | None = None)

Bases: PromptRegistryClient

Client for interacting with the Prompt Registry Orchestration Config API.

https://api.sap.com/api/PROMPT_REGISTRY_API/overview

create_orchestration_config(name: str, version: str, scenario: str, spec: OrchestrationConfig | dict) OrchestrationConfigPostResponse

Create an orchestration config.

Parameters:
  • name (str) – the name of the orchestration config.

  • version (str) – the version of the orchestration config.

  • scenario (str) – the scenario name of the orchestration config.

  • spec (Union[dict, OrchestrationConfig]) – the specification of the orchestration config.

Returns:

An OrchestrationConfigPostResponse object.

Return type:

OrchestrationConfigPostResponse

delete_orchestration_config_by_id(config_id: str) OrchestrationConfigDeleteResponse

Delete a specific version of the orchestration config by ID.

Parameters:

config_id (str) – The ID of the orchestration config.

Returns:

An OrchestrationConfigDeleteResponse object.

Return type:

OrchestrationConfigDeleteResponse

export_orchestration_config(config_id: str) bytes

Export a design orchestration config in a declarative compatible yaml file. Supports only single file export.

Parameters:

config_id (str) – The id of the orchestration config to export.

Returns:

bytes: The content of the exported file

Return type:

bytes

get_orchestration_config_by_id(config_id: str, resolve_template_ref: bool = None) OrchestrationConfigGetResponse

Retrieve a specific version of the orchestration config by ID.

Parameters:
  • config_id (str) – The ID of the orchestration config to retrieve.

  • resolve_template_ref (bool, optional) – false(default), true

Returns:

An OrchestrationConfigGetResponse object.

Return type:

OrchestrationConfigGetResponse

get_orchestration_config_history(scenario: str, name: str, version: str, include_spec: bool = None, resolve_template_ref: bool = None) OrchestrationConfigListResponse

Retrieve the history of edits to the orchestration config.

Parameters:
  • scenario (str) – The scenario name of the orchestration config.

  • name (str) – The name of the orchestration config.

  • version (str) – The version ID of the orchestration config.

  • include_spec (bool, optional) – false(default), true

  • resolve_template_ref (bool, optional) – false(default), true

Returns:

An OrchestrationConfigListResponse object.

Return type:

OrchestrationConfigListResponse

get_orchestration_configs(scenario: str, name: str, version: str, retrieve: str = None, include_spec: bool = None, resolve_template_ref: bool = None) OrchestrationConfigListResponse

Retrieve the latest version of every orchestration config based on the filters.

Parameters:
  • scenario (str) – the scenario name of the orchestration config.

  • name (str) – the name of the orchestration config.

  • version (str) – the version of the orchestration config.

  • retrieve (str, optional) – both(default), imperative, declarative

  • include_spec (bool, optional) – false(default), true

  • resolve_template_ref (bool, optional) – false(default), true

Returns:

An OrchestrationConfigListResponse object.

Return type:

OrchestrationConfigListResponse

import_orchestration_config(file: bytes) OrchestrationConfigPostResponse

Import a runtime/declarative orchestration config into the design time environment.

Parameters:

file (bytes) – binary file content

Returns:

A OrchestrationConfigPostResponse object.

Return type:

OrchestrationConfigPostResponse

class gen_ai_hub.prompt_registry.PromptTemplate(*, role: str, content: str | List[str | TextPart | ImagePart | ImageItem])

Bases: BaseModel

Represents a prompt template.

Parameters:
  • role – The role of the prompt template.

  • content – The content of the prompt template.

classmethod content_validation(content)

Validates and maps the content field to the appropriate types.

model_config: ClassVar[ConfigDict] = {}

Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].

role: str

The role of the prompt template.

content: str | List[str | TextPart | ImagePart | ImageItem]

The content of the prompt template.

class gen_ai_hub.prompt_registry.PromptTemplateSpec(*, template: ~typing.List[~gen_ai_hub.prompt_registry.models.prompt_template.PromptTemplate], defaults: dict | None = None, response_format: ~gen_ai_hub.orchestration_v2.models.response_format.ResponseFormatText | ~gen_ai_hub.orchestration_v2.models.response_format.ResponseFormatJsonObject | ~gen_ai_hub.orchestration_v2.models.response_format.ResponseFormatJsonSchema | None = None, tools: ~typing.List[dict | ~gen_ai_hub.orchestration_v2.models.tools.FunctionTool] | None = None, additional_fields: ~typing.Dict[~typing.Any, ~typing.Any] | None = <factory>)

Bases: BaseModel

Represents a prompt template specification.

Parameters:
  • Args

  • template – A list of prompt messages that form the template.

  • defaults – A dict of default values for template variables.

  • tools – A list of tool definitions.

  • response_format – A response format that the model output should adhere to.

  • additional_fields – Additional fields for the prompt template.

model_config: ClassVar[ConfigDict] = {}

Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].

template: List[PromptTemplate]
defaults: dict | None
response_format: ResponseFormatText | ResponseFormatJsonObject | ResponseFormatJsonSchema | None
tools: List[dict | FunctionTool] | None
additional_fields: Dict[Any, Any] | None
class gen_ai_hub.prompt_registry.PromptTemplatePostRequest(*, name: str, version: str, scenario: str, spec: PromptTemplateSpec)

Bases: BaseModel

Represents a request to create a prompt template.

Parameters:
  • name – The name of the prompt template.

  • version – The version of the prompt template.

  • scenario – The scenario of the prompt template.

  • spec – The specification of the prompt template.

model_config: ClassVar[ConfigDict] = {}

Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].

name: str

The name of the prompt template.

version: str

The version of the prompt template.

scenario: str

The scenario of the prompt template.

spec: PromptTemplateSpec

The specification of the prompt template.

class gen_ai_hub.prompt_registry.PromptTemplateSubstitutionRequest(*, inputParams: ~typing.Dict[~typing.Any, ~typing.Any] | None = <factory>)

Bases: BaseModel

Represents a request to substitute a prompt template.

Parameters:

input_params – User provided values to replace the placeholders of the prompt template.

model_config: ClassVar[ConfigDict] = {'populate_by_name': True, 'validate_by_alias': True, 'validate_by_name': True}

Pydantic configuration to allow population by field name.

input_params: Dict[Any, Any] | None

User provided values to replace the placeholders of the prompt template.

class gen_ai_hub.prompt_registry.PromptTemplateSubstitutionResponse(*, parsed_prompt: List[PromptTemplate], resource: PromptTemplateGetResponse | None = None)

Bases: BaseModel

Represents a response to a request to substitute a prompt template.

Parameters:
  • parsed_prompt – The parsed prompt.

  • resource – List of TemplateGetResponse objects.

model_config: ClassVar[ConfigDict] = {}

Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].

parsed_prompt: List[PromptTemplate]

The parsed prompt.

resource: PromptTemplateGetResponse | None

List of TemplateGetResponse objects.

class gen_ai_hub.prompt_registry.PromptTemplateGetResponse(*, id: str, name: str, version: str, scenario: str, creation_timestamp: str | None = None, managed_by: str | None = None, is_version_head: bool | None = None, spec: PromptTemplateSpec | None = None)

Bases: BaseModel

Represents a response to a request to get a prompt template.

Parameters:
  • id – The ID of the prompt template.

  • name – The name of the prompt template.

  • version – The version of the prompt template.

  • scenario – The scenario of the prompt template.

  • creation_timestamp – The creation timestamp of the prompt template.

  • managed_by – The manager of the prompt template.

  • is_version_head – Whether the version is the head version.

  • spec – The specification of the prompt template.

model_config: ClassVar[ConfigDict] = {}

Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].

id: str

The ID of the prompt template.

name: str

The name of the prompt template.

version: str

The version of the prompt template.

scenario: str

The scenario of the prompt template.

creation_timestamp: str | None

The creation timestamp of the prompt template.

managed_by: str | None

The manager of the prompt template.

is_version_head: bool | None

Whether the version is the head version.

spec: PromptTemplateSpec | None

The specification of the prompt template.

class gen_ai_hub.prompt_registry.PromptTemplatePostResponse(*, message: str, id: str, scenario: str, name: str, version: str)

Bases: BaseModel

Represents a response to a request to create a prompt template.

Parameters:
  • message – The message of the response.

  • id – The ID of the prompt template.

  • scenario – The scenario of the prompt template.

  • name – The name of the prompt template.

  • version – The version of the prompt template.

model_config: ClassVar[ConfigDict] = {}

Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].

message: str

The message of the response.

id: str

The ID of the prompt template.

scenario: str

The scenario of the prompt template.

name: str

The name of the prompt template.

version: str

The version of the prompt template.

class gen_ai_hub.prompt_registry.PromptTemplateDeleteResponse(*, message: str)

Bases: BaseModel

Represents a response to a request to delete a prompt template.

Parameters:

message – The message of the response.

model_config: ClassVar[ConfigDict] = {}

Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].

message: str

The message of the response.

class gen_ai_hub.prompt_registry.PromptTemplateListResponse(*, count: int, resources: List[PromptTemplateGetResponse])

Bases: BaseModel

Represents a response to a request to list prompt templates.

Parameters:
  • count – The number of prompt templates.

  • resources – The list of PromptGetResponse objects.

model_config: ClassVar[ConfigDict] = {}

Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].

count: int

The number of prompt templates.

resources: List[PromptTemplateGetResponse]

The list of PromptGetResponse objects.

class gen_ai_hub.prompt_registry.OrchestrationConfigPostRequest(*, name: Annotated[str, MaxLen(max_length=120)], version: Annotated[str, MaxLen(max_length=10)], scenario: Annotated[str, MaxLen(max_length=120)], spec: OrchestrationConfig)

Bases: BaseModel

Request to create an orchestration config.

Parameters:
  • name – The name of the orchestration config.

  • version – The version of the orchestration config.

  • scenario – The scenario of the orchestration config.

  • spec – The orchestration config specification.

model_config: ClassVar[ConfigDict] = {}

Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].

model_dump(**kwargs)

Dumps the model to a dictionary with default settings.

name: str
version: str
scenario: str
spec: OrchestrationConfig
class gen_ai_hub.prompt_registry.OrchestrationConfigPostResponse(*, message: str, id: str, scenario: str, name: str, version: str)

Bases: BaseModel

Response to the orchestration config post request.

Parameters:
  • message – Response message.

  • id – UUID of the created/updated config.

  • scenario – The scenario name.

  • name – The config name.

  • version – The config version.

model_config: ClassVar[ConfigDict] = {}

Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].

message: str
id: str
scenario: str
name: str
version: str
class gen_ai_hub.prompt_registry.OrchestrationConfigGetResponse(*, id: str | None = None, name: str | None = None, version: str | None = None, scenario: str | None = None, creation_timestamp: str | None = None, managed_by: str | None = None, is_version_head: bool | None = None, resource_group_id: str | None = None, spec: OrchestrationConfig | None = None)

Bases: BaseModel

Response to a get orchestration config request.

Parameters:
  • id – UUID of the config.

  • name – Config name.

  • version – Config version.

  • scenario – Scenario name.

  • creation_timestamp – When the config was created.

  • managed_by – Who manages the config.

  • is_version_head – Whether this is the head version.

  • spec – The orchestration config specification (optional).

model_config: ClassVar[ConfigDict] = {}

Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].

model_dump(**kwargs)

Dumps the model to a dictionary with default settings.

id: str | None
name: str | None
version: str | None
scenario: str | None
creation_timestamp: str | None
managed_by: str | None
is_version_head: bool | None
resource_group_id: str | None
spec: OrchestrationConfig | None
class gen_ai_hub.prompt_registry.OrchestrationConfigListResponse(*, count: int, resources: List[OrchestrationConfigGetResponse])

Bases: BaseModel

Response to list orchestration configs request.

Parameters:
  • count – Number of configs returned.

  • resources – List of OrchestrationConfigGetResponse objects.

model_config: ClassVar[ConfigDict] = {}

Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].

model_dump(**kwargs)

Dumps the model to a dictionary with default settings.

count: int
resources: List[OrchestrationConfigGetResponse]
class gen_ai_hub.prompt_registry.OrchestrationConfigDeleteResponse(*, message: str)

Bases: BaseModel

Response to a delete orchestration config request.

Parameters:

message – Response message.

model_config: ClassVar[ConfigDict] = {}

Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].

message: str

Subpackages

Submodules