Skip to main content

GlobalPromptTemplates

create

def create(self,
           name: str,
           template: Union[builtins.list[Message], str],
           project_id: Optional[str]=None,
           project_name: Optional[str]=None) -> PromptTemplate
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

def delete(self,
           *,
           template_id: Optional[str]=None,
           name: Optional[str]=None) -> None
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

def list(self,
         *,
         name_filter: Optional[str]=None,
         project_id: Optional[str]=None,
         project_name: Optional[str]=None,
         limit: Union[Unset, int]=100,
         starting_token: int=0) -> builtins.list[PromptTemplate]
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

def render_template(self,
                    *,
                    template: str,
                    data: Union[DatasetData, StringData],
                    starting_token: Union[Unset, int]=0,
                    limit: Union[Unset, int]=100) -> RenderTemplateResponse
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

def update(self, *, template_id: str, name: str) -> PromptTemplate
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

def create(self,
           name: str,
           template: Union[builtins.list[Message], str]) -> PromptTemplate
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

def delete(self, *, name: str) -> None
Delete a template by name from this project. Arguments
  • name (str): The template name.

get

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

list

def list(self) -> builtins.list[PromptTemplate]
List templates for this project. Returns
  • list[PromptTemplate]: List of templates associated with the project.

create_prompt

def create_prompt(name: str,
                  template: Union[builtins.list[Message], str],
                  project_id: Optional[str]=None,
                  project_name: Optional[str]=None) -> PromptTemplate
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

def create_prompt_template(name: str,
                           project: str,
                           messages: builtins.list[Message]) -> PromptTemplate
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

def delete_prompt(*,
                  id: Optional[str]=None,
                  name: Optional[str]=None,
                  project_id: Optional[str]=None,
                  project_name: Optional[str]=None) -> None
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

def get_prompt(*,
               id: Optional[str]=None,
               name: Optional[str]=None,
               project_id: Optional[str]=None,
               project_name: Optional[str]=None) -> Optional[PromptTemplate]
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

def get_prompt_template(name: str, project: str) -> Optional[PromptTemplate]
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

def get_prompts(name_filter: Optional[str]=None,
                project_id: Optional[str]=None,
                project_name: Optional[str]=None,
                limit: Union[Unset, int]=100) -> builtins.list[PromptTemplate]
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

def list_prompt_templates(project: str) -> builtins.list[PromptTemplate]
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

def render_template(*,
                    template: str,
                    data: Union[DatasetData, StringData, list[str], str],
                    starting_token: Union[Unset, int]=0,
                    limit: Union[Unset, int]=100) -> RenderTemplateResponse
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

def update_prompt(*,
                  id: Optional[str]=None,
                  name: Optional[str]=None,
                  new_name: str) -> PromptTemplate
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.
I