PromptTemplatesResource
PromptTemplatesResource ¶
PromptTemplatesResource(client: Union[Client, AsyncClient])
Bases: BaseResource
create ¶
create(messages: str | List[ChatCompletionMessageParam], name: str, parent_prompt_template: PromptTemplate | None = None, response_format: Type[BaseModel] | Dict[str, Any] | None = None, tools: List[FunctionTool] | None = None, tool_choice: AssistantToolChoiceOption | None = None) -> PromptTemplate
Create a new prompt template.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
messages
|
str | List[ChatCompletionMessageParam]
|
The template string with {{placeholders}}, or a list of ChatCompletionMessageParam dicts for multi-turn conversations. |
required |
name
|
str
|
Name for the template. |
required |
parent_prompt_template
|
PromptTemplate | None
|
Optional parent template to inherit from. |
None
|
response_format
|
Type[BaseModel] | Dict[str, Any] | None
|
Optional Pydantic model or OpenAI-style dict for structured output generation. |
None
|
tools
|
List[FunctionTool] | None
|
Optional list of tools available to the model. |
None
|
tool_choice
|
AssistantToolChoiceOption | None
|
Optional tool choice setting. |
None
|
delete ¶
Deletes a prompt template.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
prompt_template
|
PromptTemplate
|
The prompt template to delete. |
required |
Raises:
| Type | Description |
|---|---|
HTTPStatusError
|
If the prompt template doesn't exist or belongs to a different project. |
get ¶
get(*, name: str | None = None, id: int | None = None, version: int | Literal['latest'] = 'latest') -> PromptTemplate
Get a prompt template by name and version, or by id.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str | None
|
Name of the prompt template. |
None
|
id
|
int | None
|
ID of the prompt template. |
None
|
version
|
int | Literal['latest']
|
Version number or "latest". Defaults to "latest". Only used when looking up by name; ignored when looking up by id. |
'latest'
|
Returns:
| Type | Description |
|---|---|
PromptTemplate
|
The requested prompt template. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If neither or both name and id are provided. |
ValueError
|
If no template is found with given name and version. |
get_or_create ¶
get_or_create(messages: str | List[ChatCompletionMessageParam], name: str, parent_prompt_template: PromptTemplate | None = None, response_format: Type[BaseModel] | None = None, tools: List[FunctionTool] | None = None, tool_choice: AssistantToolChoiceOption | None = None) -> tuple[PromptTemplate, bool]
Gets the prompt template by its name and messages content if it exists. If the prompt template name does not exist, it creates a new prompt template with version 1. If a prompt template with the same name exists, but the messages content is new, then it creates a new prompt template version with the new messages which will be the new latest version. When a prompt template with the same name and messages already exists, it returns the existing prompt template, ignoring the given parent_prompt_template.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
messages
|
str | List[ChatCompletionMessageParam]
|
The template string with {{placeholders}}, or a list of ChatCompletionMessageParam dicts for multi-turn conversations. |
required |
name
|
str
|
Name for the template. |
required |
parent_prompt_template
|
PromptTemplate | None
|
Optional parent template to inherit from. |
None
|
response_format
|
Type[BaseModel] | None
|
Optional Pydantic model for structured output generation. |
None
|
tools
|
List[FunctionTool] | None
|
Optional list of tools available to the model. |
None
|
tool_choice
|
AssistantToolChoiceOption | None
|
Optional tool choice setting. |
None
|
Returns:
| Type | Description |
|---|---|
tuple[PromptTemplate, bool]
|
tuple[PromptTemplate, bool]: A tuple containing: - The prompt template - Boolean indicating if a new template was created (True) or existing one returned (False) |
Raises:
| Type | Description |
|---|---|
ValueError
|
If a 409 response is received without a prompt_template_id. |
list ¶
list(name: str | None = None, criterion_set: CriterionSet | None = None, compatible_collection: TemplateVariablesCollection | None = None) -> list[PromptTemplate]
Get a list of prompt templates.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str | None
|
Name of the prompt template to filter by. |
None
|
criterion_set
|
CriterionSet | None
|
Criterion set to filter by. |
None
|
compatible_collection
|
TemplateVariablesCollection | None
|
Compatible template variables collection to filter by. |
None
|
Returns:
| Type | Description |
|---|---|
list[PromptTemplate]
|
list[PromptTemplate]: A list of prompt templates. |