mirror of
https://github.com/meta-llama/llama-stack.git
synced 2025-10-05 04:17:32 +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
|
@ -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