Skip to main content

GlobalPromptTemplates

create

Create a new global prompt template. Arguments
  • name (str): The name for the new template.
  • template (Union[list[Message], str]): The template content. Can be either a list of Message objects or a JSON string.
  • project_id (Optional[str]): The project ID to associate with this template. Defaults to None.
  • project_name (Optional[str]): The project name to associate with this template. Defaults to None. Cannot be used together with project_id.
Raises
  • PromptTemplateAPIException: If the API request fails or returns an error.
  • ValueError: If both project_id and project_name are provided, or if project_name doesn’t exist.
Returns
  • PromptTemplate: The created prompt template.

delete

Delete a global prompt template by ID or name. Arguments
  • template_id (Optional[str]): The unique identifier of the template to delete. Defaults to None.
  • name (Optional[str]): The name of the template to delete. Defaults to None.
Raises
  • ValueError: If neither or both template_id and name are provided, or if the template is not found.

list

List global prompt templates with optional filtering. Arguments
  • name_filter (Optional[str]): Filter templates by name containing this string. Defaults to None.
  • project_id (Optional[str]): Filter templates by project ID. Returns templates used in the specified project. Defaults to None.
  • project_name (Optional[str]): Filter templates by project name. Returns templates used in the specified project. Defaults to None. Cannot be used together with project_id.
  • limit (Union[Unset, int]): Maximum number of templates to return. Defaults to 100.
  • starting_token (int): Starting token for pagination. Defaults to 0.
Raises
  • ValueError: If both project_id and project_name are provided, or if project_name doesn’t exist.
Returns
  • list[PromptTemplate]: List of prompt templates matching the criteria.

render_template

Render a template with provided data. Arguments
  • template (str): The template string to render.
  • data (Union[DatasetData, StringData]): The data to use for rendering the template. Can be either dataset data or string data.
  • starting_token (Union[Unset, int]): Starting token for pagination. Defaults to 0.
  • limit (Union[Unset, int]): Maximum number of rendered templates to return. Defaults to 100.
Raises
  • PromptTemplateAPIException: If the API request fails or returns an error.
Returns
  • Optional[RenderTemplateResponse]: The rendered template response if successful, None otherwise.

update

Update a global prompt template. Arguments
  • template_id (str): The ID of the template to update.
  • name (str): The new name for the template.
Raises
  • PromptTemplateAPIException: If the API request fails or returns an error.
Returns
  • PromptTemplate: The updated prompt template.

PromptTemplates

Class for managing project-specific prompt templates.
Deprecated. This class is deprecated as templates are now global. Use the module-level functions get_prompts, create_prompt, etc. instead. This class will be removed in a future version.

create

Create a template in this project. Arguments
  • name (str): The template name.
  • template (Union[list[Message], str]): The template content.
Returns
  • PromptTemplate: The created template.

delete

Delete a template by name from this project. Arguments
  • name (str): The template name.

get

Get a template by name from this project. Arguments
  • name (str): The template name.
Returns
  • Optional[PromptTemplate]: The template if found, None otherwise.

list

List templates for this project. Returns
  • list[PromptTemplate]: List of templates associated with the project.

create_prompt

Create a new global prompt template. Arguments
  • name (str): The name for the new template.
  • template (Union[list[Message], str]): The template content. Can be either a list of Message objects or a JSON string representing the message structure.
  • project_id (Optional[str]): The project ID to associate with this template. When provided, the template will be linked to the specified project. Defaults to None.
  • project_name (Optional[str]): The project name to associate with this template. When provided, the template will be linked to the specified project. Defaults to None. Cannot be used together with project_id.
Raises
  • PromptTemplateAPIException: If the API request fails or returns an error.
  • ValueError: If both project_id and project_name are provided, or if project_name doesn’t exist.
Returns
  • PromptTemplate: The created prompt template.

create_prompt_template

Create a new global prompt template.
Deprecated. Use create_prompt instead.
Arguments
  • name (str): The name for the new template.
  • project (str): The project name to associate with this template.
  • messages (list[Message]): The template content as a list of Message objects.
Raises
  • PromptTemplateAPIException: If the API request fails or returns an error.
  • ValueError: If project doesn’t exist.
Returns
  • PromptTemplate: The created prompt template.

delete_prompt

Delete a global prompt template by ID or name. You must provide either ‘id’ or ‘name’, but not both. Arguments
  • id (str): The unique identifier of the template to delete. Defaults to None.
  • name (str): The name of the template to delete. Defaults to None.
  • project_id (str): Deprecated. This parameter is ignored.
  • project_name (str): Deprecated. This parameter is ignored.
Raises
  • ValueError: If neither or both id and name are provided, or if the template is not found.
Returns
  • None:

get_prompt

Retrieves a global prompt template. You must provide either ‘id’ or ‘name’, but not both. Arguments
  • id (str): The unique identifier of the template to retrieve. Defaults to None.
  • name (str): The name of the template to retrieve. Defaults to None.
  • project_id (str): Deprecated. This parameter is ignored. Use get_prompts(project_id=…) to filter templates by project.
  • project_name (str): Deprecated. This parameter is ignored. Use get_prompts(project_name=…) to filter templates by project.
Raises
  • ValueError: If neither or both ‘id’ and ‘name’ are provided.
Returns
  • Optional[PromptTemplate]: The template if found, None otherwise.

get_prompt_template

Get a prompt template by name from a specific project.
Deprecated. Use get_prompt with name parameter or get_prompts with project_name parameter instead. This function is deprecated and will be removed in a future version.
Arguments
  • name (str): The name of the template.
  • project (str): The project name (ignored - templates are now global).
Returns
  • Optional[PromptTemplate]: The template if found, None otherwise.

get_prompts

List global prompt templates with optional filtering. Arguments
  • name_filter (Optional[str]): Filter templates by name containing this string. Defaults to None (no filtering).
  • project_id (Optional[str]): Filter templates by project ID. Returns templates used in the specified project. Defaults to None.
  • project_name (Optional[str]): Filter templates by project name. Returns templates used in the specified project. Defaults to None. Cannot be used together with project_id.
  • limit (Union[Unset, int]): Maximum number of templates to return. Defaults to 100.
Raises
  • ValueError: If both project_id and project_name are provided, or if project_name doesn’t exist.
Returns
  • list[PromptTemplate]: List of prompt templates matching the criteria.

list_prompt_templates

List prompt templates for a project.
Deprecated. Use get_prompts with project_name parameter instead. This function is deprecated and will be removed in a future version.
Arguments
  • project (str): The project name to filter templates by.
Returns
  • list[PromptTemplate]: List of prompt templates associated with the project.

render_template

Render a template with provided data. Arguments
  • template (str): The template string to render.
  • data (Union[DatasetData, StringData, list[str], str]): The data to use for rendering the template. Can be:
    • DatasetData: Reference to a dataset
    • StringData: List of input strings
    • list[str]: List of input strings (will be converted to StringData)
    • str: Dataset ID (will be converted to DatasetData)
  • starting_token (Union[Unset, int]): Starting token for pagination. Defaults to 0.
  • limit (Union[Unset, int]): Maximum number of rendered templates to return. Defaults to 100.
Raises
  • PromptTemplateAPIException: If the API request fails or returns an error.
Returns
  • Optional[RenderTemplateResponse]: The rendered template response if successful, None otherwise.

update_prompt

Update a global prompt template by ID or name. Arguments
  • id (str): The unique identifier of the template to update. Defaults to None.
  • name (str): The name of the template to update. Defaults to None.
  • new_name (str): The new name for the template.
Raises
  • ValueError: If neither or both id and name are provided, or if the template is not found.
  • PromptTemplateAPIException: If the API request fails or returns an error.
Returns
  • PromptTemplate: The updated prompt template.