refac
This commit is contained in:
@@ -89,6 +89,7 @@ class PromptForm(BaseModel):
|
|||||||
access_control: Optional[dict] = None
|
access_control: Optional[dict] = None
|
||||||
version_id: Optional[str] = None # Active version
|
version_id: Optional[str] = None # Active version
|
||||||
commit_message: Optional[str] = None # For history tracking
|
commit_message: Optional[str] = None # For history tracking
|
||||||
|
is_production: Optional[bool] = True # Whether to set new version as production
|
||||||
|
|
||||||
|
|
||||||
class PromptsTable:
|
class PromptsTable:
|
||||||
@@ -252,8 +253,6 @@ class PromptsTable:
|
|||||||
prompt.data = form_data.data or prompt.data
|
prompt.data = form_data.data or prompt.data
|
||||||
prompt.meta = form_data.meta or prompt.meta
|
prompt.meta = form_data.meta or prompt.meta
|
||||||
prompt.access_control = form_data.access_control
|
prompt.access_control = form_data.access_control
|
||||||
if form_data.version_id is not None:
|
|
||||||
prompt.version_id = form_data.version_id
|
|
||||||
prompt.updated_at = int(time.time())
|
prompt.updated_at = int(time.time())
|
||||||
|
|
||||||
db.commit()
|
db.commit()
|
||||||
@@ -269,7 +268,7 @@ class PromptsTable:
|
|||||||
"access_control": form_data.access_control,
|
"access_control": form_data.access_control,
|
||||||
}
|
}
|
||||||
|
|
||||||
PromptHistories.create_history_entry(
|
history_entry = PromptHistories.create_history_entry(
|
||||||
prompt_id=prompt.id,
|
prompt_id=prompt.id,
|
||||||
snapshot=snapshot,
|
snapshot=snapshot,
|
||||||
user_id=user_id,
|
user_id=user_id,
|
||||||
@@ -277,6 +276,11 @@ class PromptsTable:
|
|||||||
commit_message=form_data.commit_message,
|
commit_message=form_data.commit_message,
|
||||||
db=db,
|
db=db,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
# Set as production if flag is True (default)
|
||||||
|
if form_data.is_production and history_entry:
|
||||||
|
prompt.version_id = history_entry.id
|
||||||
|
db.commit()
|
||||||
|
|
||||||
return PromptModel.model_validate(prompt)
|
return PromptModel.model_validate(prompt)
|
||||||
except Exception:
|
except Exception:
|
||||||
|
|||||||
@@ -39,6 +39,7 @@
|
|||||||
let command = '';
|
let command = '';
|
||||||
let content = '';
|
let content = '';
|
||||||
let commitMessage = '';
|
let commitMessage = '';
|
||||||
|
let isProduction = true;
|
||||||
|
|
||||||
let accessControl = {};
|
let accessControl = {};
|
||||||
let showAccessControlModal = false;
|
let showAccessControlModal = false;
|
||||||
@@ -69,10 +70,12 @@
|
|||||||
command,
|
command,
|
||||||
content,
|
content,
|
||||||
access_control: accessControl,
|
access_control: accessControl,
|
||||||
commit_message: commitMessage || undefined
|
commit_message: commitMessage || undefined,
|
||||||
|
is_production: isProduction
|
||||||
});
|
});
|
||||||
showEditModal = false;
|
showEditModal = false;
|
||||||
commitMessage = '';
|
commitMessage = '';
|
||||||
|
isProduction = true;
|
||||||
await loadHistory();
|
await loadHistory();
|
||||||
} else {
|
} else {
|
||||||
toast.error(
|
toast.error(
|
||||||
@@ -183,35 +186,6 @@
|
|||||||
</div>
|
</div>
|
||||||
|
|
||||||
<form on:submit|preventDefault={submitHandler}>
|
<form on:submit|preventDefault={submitHandler}>
|
||||||
<div class="my-2">
|
|
||||||
<Tooltip
|
|
||||||
content={`${$i18n.t('Only alphanumeric characters and hyphens are allowed')} - ${$i18n.t('Activate this command by typing "/{{COMMAND}}" to chat input.', { COMMAND: command })}`}
|
|
||||||
placement="bottom-start"
|
|
||||||
>
|
|
||||||
<div class="flex flex-col w-full">
|
|
||||||
<div class="flex items-center">
|
|
||||||
<input
|
|
||||||
class="text-2xl font-medium w-full bg-transparent outline-hidden"
|
|
||||||
placeholder={$i18n.t('Name')}
|
|
||||||
bind:value={name}
|
|
||||||
required
|
|
||||||
/>
|
|
||||||
</div>
|
|
||||||
<div class="flex gap-0.5 items-center text-xs text-gray-500">
|
|
||||||
<div>/</div>
|
|
||||||
<input
|
|
||||||
class="w-full bg-transparent outline-hidden"
|
|
||||||
placeholder={$i18n.t('Command')}
|
|
||||||
bind:value={command}
|
|
||||||
on:input={handleCommandInput}
|
|
||||||
required
|
|
||||||
disabled
|
|
||||||
/>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</Tooltip>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div class="my-2">
|
<div class="my-2">
|
||||||
<div class="flex w-full justify-between">
|
<div class="flex w-full justify-between">
|
||||||
<div class="text-gray-500 text-xs">{$i18n.t('Prompt Content')}</div>
|
<div class="text-gray-500 text-xs">{$i18n.t('Prompt Content')}</div>
|
||||||
@@ -225,27 +199,30 @@
|
|||||||
rows={6}
|
rows={6}
|
||||||
required
|
required
|
||||||
/>
|
/>
|
||||||
|
|
||||||
<div class="text-xs text-gray-400 dark:text-gray-500">
|
|
||||||
ⓘ {$i18n.t('Format your variables using brackets like this:')} <span
|
|
||||||
class="text-gray-600 dark:text-gray-300 font-medium"
|
|
||||||
>{'{{'}{$i18n.t('variable')}{'}}'}</span
|
|
||||||
>.
|
|
||||||
{$i18n.t('Make sure to enclose them with')}
|
|
||||||
<span class="text-gray-600 dark:text-gray-300 font-medium">{'{{'}</span>
|
|
||||||
{$i18n.t('and')}
|
|
||||||
<span class="text-gray-600 dark:text-gray-300 font-medium">{'}}'}</span>.
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div class="text-xs text-gray-400 dark:text-gray-500 underline">
|
|
||||||
<a href="https://docs.openwebui.com/features/workspace/prompts" target="_blank">
|
|
||||||
{$i18n.t('To learn more about powerful prompt variables, click here')}
|
|
||||||
</a>
|
|
||||||
</div>
|
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="mt-4 flex justify-end">
|
<div class="my-2">
|
||||||
|
<div class="text-gray-500 text-xs">{$i18n.t('Commit Message')} ({$i18n.t('optional')})</div>
|
||||||
|
<div class="mt-1">
|
||||||
|
<input
|
||||||
|
class="text-sm w-full bg-transparent outline-hidden"
|
||||||
|
placeholder={$i18n.t('Describe what changed...')}
|
||||||
|
bind:value={commitMessage}
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="mt-4 flex items-center justify-between">
|
||||||
|
<label class="flex items-center gap-2 cursor-pointer">
|
||||||
|
<input
|
||||||
|
type="checkbox"
|
||||||
|
bind:checked={isProduction}
|
||||||
|
class="w-4 h-4 rounded border-gray-300 dark:border-gray-600"
|
||||||
|
/>
|
||||||
|
<span class="text-sm text-gray-700 dark:text-gray-300">{$i18n.t('Set as Production')}</span>
|
||||||
|
</label>
|
||||||
|
<div>
|
||||||
<button
|
<button
|
||||||
class="text-sm px-4 py-2 transition rounded-full {loading
|
class="text-sm px-4 py-2 transition rounded-full {loading
|
||||||
? 'cursor-not-allowed bg-gray-200 text-gray-500 dark:bg-gray-700 dark:text-gray-400'
|
? 'cursor-not-allowed bg-gray-200 text-gray-500 dark:bg-gray-700 dark:text-gray-400'
|
||||||
@@ -260,6 +237,7 @@
|
|||||||
</div>
|
</div>
|
||||||
{/if}
|
{/if}
|
||||||
</button>
|
</button>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</form>
|
</form>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
Reference in New Issue
Block a user