mirror of
https://github.com/meta-llama/llama-stack.git
synced 2025-10-06 20:44:58 +00:00
fixed update_prompt to properly handle latest and default version, made version a required parameter, and removed unused CreatePromptRequest
Signed-off-by: Francisco Javier Arceo <farceo@redhat.com>
This commit is contained in:
parent
1390660dcf
commit
beb2db487d
6 changed files with 43 additions and 41 deletions
|
@ -4,6 +4,6 @@
|
|||
# This source code is licensed under the terms described in the LICENSE file in
|
||||
# the root directory of this source tree.
|
||||
|
||||
from .prompts import CreatePromptRequest, ListPromptsResponse, Prompt, Prompts, UpdatePromptRequest
|
||||
from .prompts import ListPromptsResponse, Prompt, Prompts, UpdatePromptRequest
|
||||
|
||||
__all__ = ["Prompt", "Prompts", "ListPromptsResponse", "CreatePromptRequest", "UpdatePromptRequest"]
|
||||
__all__ = ["Prompt", "Prompts", "ListPromptsResponse", "UpdatePromptRequest"]
|
||||
|
|
|
@ -21,7 +21,7 @@ class Prompt(BaseModel):
|
|||
:param prompt: The system prompt text with variable placeholders. Variables are only supported when using the Responses API.
|
||||
:param version: Version string (integer start at 1 cast as string, incremented on save)
|
||||
:param prompt_id: Unique identifier formatted as 'pmpt_<48-digit-hash>'
|
||||
:param variables: Dictionary of prompt variable names and values
|
||||
:param variables: List of prompt variable names that can be used in the prompt template
|
||||
:param is_default: Boolean indicating whether this version is the default version for this prompt
|
||||
"""
|
||||
|
||||
|
@ -90,13 +90,6 @@ class Prompt(BaseModel):
|
|||
return f"pmpt_{hex_string}"
|
||||
|
||||
|
||||
class CreatePromptRequest(BaseModel):
|
||||
"""Request model to create a prompt."""
|
||||
|
||||
prompt: str = Field(description="The prompt text content")
|
||||
variables: list[str] = Field(default_factory=list, description="List of variable names for dynamic injection")
|
||||
|
||||
|
||||
class UpdatePromptRequest(BaseModel):
|
||||
"""Request model for updating a prompt."""
|
||||
|
||||
|
@ -168,15 +161,15 @@ class Prompts(Protocol):
|
|||
self,
|
||||
prompt_id: str,
|
||||
prompt: str,
|
||||
version: str,
|
||||
variables: list[str] | None = None,
|
||||
version: str | None = None,
|
||||
) -> Prompt:
|
||||
"""Update an existing prompt (increments version).
|
||||
|
||||
:param prompt_id: The identifier of the prompt to update.
|
||||
:param prompt: The updated prompt text content.
|
||||
:param variables: Updated list of variable names that can be used in the prompt template.
|
||||
:param version: The current version of the prompt being updated (as a string).
|
||||
:param variables: Updated list of variable names that can be used in the prompt template.
|
||||
:returns: The updated Prompt resource with incremented version.
|
||||
"""
|
||||
...
|
||||
|
|
|
@ -142,20 +142,22 @@ class PromptServiceImpl(Prompts):
|
|||
self,
|
||||
prompt_id: str,
|
||||
prompt: str,
|
||||
version: str,
|
||||
variables: list[str] | None = None,
|
||||
version: str | None = None,
|
||||
) -> Prompt:
|
||||
"""Update an existing prompt (increments version)."""
|
||||
if variables is None:
|
||||
variables = []
|
||||
|
||||
current_prompt = await self.get_prompt(prompt_id)
|
||||
if version and current_prompt.version != version:
|
||||
prompt_versions = await self.list_prompt_versions(prompt_id)
|
||||
latest_prompt = max(prompt_versions.data, key=lambda x: int(x.version))
|
||||
|
||||
if version and latest_prompt.version != version:
|
||||
raise ValueError(
|
||||
f"'{version}' is not the latest prompt version for prompt_id='{prompt_id}'. Use the latest version '{current_prompt.version}' in request."
|
||||
f"'{version}' is not the latest prompt version for prompt_id='{prompt_id}'. Use the latest version '{latest_prompt.version}' in request."
|
||||
)
|
||||
|
||||
current_version = current_prompt.version if version is None else version
|
||||
current_version = latest_prompt.version if version is None else version
|
||||
new_version = str(int(current_version) + 1)
|
||||
|
||||
updated_prompt = Prompt(prompt_id=prompt_id, prompt=prompt, version=new_version, variables=variables)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue