mirror of
https://github.com/open-webui/open-webui
synced 2025-05-17 12:03:41 +00:00
enh: Actions __webui__
flag support
This commit is contained in:
parent
dc6ca61548
commit
8c2ba7f7ea
@ -1026,6 +1026,10 @@ async def get_all_models():
|
|||||||
function_module, _, _ = load_function_module_by_id(action_id)
|
function_module, _, _ = load_function_module_by_id(action_id)
|
||||||
webui_app.state.FUNCTIONS[action_id] = function_module
|
webui_app.state.FUNCTIONS[action_id] = function_module
|
||||||
|
|
||||||
|
__webui__ = False
|
||||||
|
if hasattr(function_module, "__webui__"):
|
||||||
|
__webui__ = function_module.__webui__
|
||||||
|
|
||||||
if hasattr(function_module, "actions"):
|
if hasattr(function_module, "actions"):
|
||||||
actions = function_module.actions
|
actions = function_module.actions
|
||||||
model["actions"].extend(
|
model["actions"].extend(
|
||||||
@ -1039,6 +1043,7 @@ async def get_all_models():
|
|||||||
"icon_url": _action.get(
|
"icon_url": _action.get(
|
||||||
"icon_url", action.meta.manifest.get("icon_url", None)
|
"icon_url", action.meta.manifest.get("icon_url", None)
|
||||||
),
|
),
|
||||||
|
**({"__webui__": __webui__} if __webui__ else {}),
|
||||||
}
|
}
|
||||||
for _action in actions
|
for _action in actions
|
||||||
]
|
]
|
||||||
@ -1050,6 +1055,7 @@ async def get_all_models():
|
|||||||
"name": action.name,
|
"name": action.name,
|
||||||
"description": action.meta.description,
|
"description": action.meta.description,
|
||||||
"icon_url": action.meta.manifest.get("icon_url", None),
|
"icon_url": action.meta.manifest.get("icon_url", None),
|
||||||
|
**({"__webui__": __webui__} if __webui__ else {}),
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -430,7 +430,7 @@
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
const chatActionHandler = async (chatId, actionId, modelId, responseMessageId) => {
|
const chatActionHandler = async (chatId, actionId, modelId, responseMessageId, event = null) => {
|
||||||
const res = await chatAction(localStorage.token, actionId, {
|
const res = await chatAction(localStorage.token, actionId, {
|
||||||
model: modelId,
|
model: modelId,
|
||||||
messages: messages.map((m) => ({
|
messages: messages.map((m) => ({
|
||||||
@ -440,6 +440,7 @@
|
|||||||
info: m.info ? m.info : undefined,
|
info: m.info ? m.info : undefined,
|
||||||
timestamp: m.timestamp
|
timestamp: m.timestamp
|
||||||
})),
|
})),
|
||||||
|
...(event ? { event: event } : {}),
|
||||||
chat_id: chatId,
|
chat_id: chatId,
|
||||||
session_id: $socket?.id,
|
session_id: $socket?.id,
|
||||||
id: responseMessageId
|
id: responseMessageId
|
||||||
|
@ -342,7 +342,13 @@
|
|||||||
{continueGeneration}
|
{continueGeneration}
|
||||||
{regenerateResponse}
|
{regenerateResponse}
|
||||||
on:action={async (e) => {
|
on:action={async (e) => {
|
||||||
await chatActionHandler(chatId, e.detail, message.model, message.id);
|
console.log('action', e);
|
||||||
|
if (typeof e.detail === 'string') {
|
||||||
|
await chatActionHandler(chatId, e.detail, message.model, message.id);
|
||||||
|
} else {
|
||||||
|
const { id, event } = e.detail;
|
||||||
|
await chatActionHandler(chatId, id, message.model, message.id, event);
|
||||||
|
}
|
||||||
}}
|
}}
|
||||||
on:save={async (e) => {
|
on:save={async (e) => {
|
||||||
console.log('save', e);
|
console.log('save', e);
|
||||||
|
@ -57,7 +57,10 @@
|
|||||||
message.annotation.reason = selectedReason;
|
message.annotation.reason = selectedReason;
|
||||||
message.annotation.comment = comment;
|
message.annotation.comment = comment;
|
||||||
|
|
||||||
dispatch('submit');
|
dispatch('submit', {
|
||||||
|
reason: selectedReason,
|
||||||
|
comment: comment
|
||||||
|
});
|
||||||
|
|
||||||
toast.success($i18n.t('Thanks for your feedback!'));
|
toast.success($i18n.t('Thanks for your feedback!'));
|
||||||
show = false;
|
show = false;
|
||||||
|
@ -821,10 +821,24 @@
|
|||||||
?.annotation?.rating ?? null) === 1
|
?.annotation?.rating ?? null) === 1
|
||||||
? 'bg-gray-100 dark:bg-gray-800'
|
? 'bg-gray-100 dark:bg-gray-800'
|
||||||
: ''} dark:hover:text-white hover:text-black transition"
|
: ''} dark:hover:text-white hover:text-black transition"
|
||||||
on:click={() => {
|
on:click={async () => {
|
||||||
rateMessage(message.id, 1);
|
await rateMessage(message.id, 1);
|
||||||
showRateComment = true;
|
|
||||||
|
|
||||||
|
(model?.actions ?? [])
|
||||||
|
.filter((action) => action?.__webui__ ?? false)
|
||||||
|
.forEach((action) => {
|
||||||
|
dispatch('action', {
|
||||||
|
id: action.id,
|
||||||
|
event: {
|
||||||
|
id: 'good-response',
|
||||||
|
data: {
|
||||||
|
messageId: message.id
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
showRateComment = true;
|
||||||
window.setTimeout(() => {
|
window.setTimeout(() => {
|
||||||
document
|
document
|
||||||
.getElementById(`message-feedback-${message.id}`)
|
.getElementById(`message-feedback-${message.id}`)
|
||||||
@ -856,8 +870,23 @@
|
|||||||
?.annotation?.rating ?? null) === -1
|
?.annotation?.rating ?? null) === -1
|
||||||
? 'bg-gray-100 dark:bg-gray-800'
|
? 'bg-gray-100 dark:bg-gray-800'
|
||||||
: ''} dark:hover:text-white hover:text-black transition"
|
: ''} dark:hover:text-white hover:text-black transition"
|
||||||
on:click={() => {
|
on:click={async () => {
|
||||||
rateMessage(message.id, -1);
|
await rateMessage(message.id, -1);
|
||||||
|
|
||||||
|
(model?.actions ?? [])
|
||||||
|
.filter((action) => action?.__webui__ ?? false)
|
||||||
|
.forEach((action) => {
|
||||||
|
dispatch('action', {
|
||||||
|
id: action.id,
|
||||||
|
event: {
|
||||||
|
id: 'bad-response',
|
||||||
|
data: {
|
||||||
|
messageId: message.id
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
showRateComment = true;
|
showRateComment = true;
|
||||||
window.setTimeout(() => {
|
window.setTimeout(() => {
|
||||||
document
|
document
|
||||||
@ -891,6 +920,20 @@
|
|||||||
: 'invisible group-hover:visible'} p-1.5 hover:bg-black/5 dark:hover:bg-white/5 rounded-lg dark:hover:text-white hover:text-black transition regenerate-response-button"
|
: 'invisible group-hover:visible'} p-1.5 hover:bg-black/5 dark:hover:bg-white/5 rounded-lg dark:hover:text-white hover:text-black transition regenerate-response-button"
|
||||||
on:click={() => {
|
on:click={() => {
|
||||||
continueGeneration();
|
continueGeneration();
|
||||||
|
|
||||||
|
(model?.actions ?? [])
|
||||||
|
.filter((action) => action?.__webui__ ?? false)
|
||||||
|
.forEach((action) => {
|
||||||
|
dispatch('action', {
|
||||||
|
id: action.id,
|
||||||
|
event: {
|
||||||
|
id: 'continue-response',
|
||||||
|
data: {
|
||||||
|
messageId: message.id
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
<svg
|
<svg
|
||||||
@ -924,6 +967,20 @@
|
|||||||
on:click={() => {
|
on:click={() => {
|
||||||
showRateComment = false;
|
showRateComment = false;
|
||||||
regenerateResponse(message);
|
regenerateResponse(message);
|
||||||
|
|
||||||
|
(model?.actions ?? [])
|
||||||
|
.filter((action) => action?.__webui__ ?? false)
|
||||||
|
.forEach((action) => {
|
||||||
|
dispatch('action', {
|
||||||
|
id: action.id,
|
||||||
|
event: {
|
||||||
|
id: 'regenerate-response',
|
||||||
|
data: {
|
||||||
|
messageId: message.id
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
<svg
|
<svg
|
||||||
@ -943,7 +1000,7 @@
|
|||||||
</button>
|
</button>
|
||||||
</Tooltip>
|
</Tooltip>
|
||||||
|
|
||||||
{#each model?.actions ?? [] as action}
|
{#each (model?.actions ?? []).filter((action) => !(action?.__webui__ ?? false)) as action}
|
||||||
<Tooltip content={action.name} placement="bottom">
|
<Tooltip content={action.name} placement="bottom">
|
||||||
<button
|
<button
|
||||||
type="button"
|
type="button"
|
||||||
@ -980,8 +1037,24 @@
|
|||||||
messageId={message.id}
|
messageId={message.id}
|
||||||
bind:show={showRateComment}
|
bind:show={showRateComment}
|
||||||
bind:message
|
bind:message
|
||||||
on:submit={() => {
|
on:submit={(e) => {
|
||||||
updateChatMessages();
|
updateChatMessages();
|
||||||
|
|
||||||
|
(model?.actions ?? [])
|
||||||
|
.filter((action) => action?.__webui__ ?? false)
|
||||||
|
.forEach((action) => {
|
||||||
|
dispatch('action', {
|
||||||
|
id: action.id,
|
||||||
|
event: {
|
||||||
|
id: 'rate-comment',
|
||||||
|
data: {
|
||||||
|
messageId: message.id,
|
||||||
|
comment: e.detail.comment,
|
||||||
|
reason: e.detail.reason
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
}}
|
}}
|
||||||
/>
|
/>
|
||||||
{/if}
|
{/if}
|
||||||
|
Loading…
Reference in New Issue
Block a user