Skip to content

Commit 6dc0df2

Browse files
committed
refac
1 parent cd5e2be commit 6dc0df2

File tree

4 files changed

+33
-8
lines changed

4 files changed

+33
-8
lines changed

backend/open_webui/utils/middleware.py

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -710,9 +710,26 @@ async def chat_completion_files_handler(
710710

711711
log.debug(f"rag_contexts:sources: {sources}")
712712

713-
sources_count = 0
714-
for source in sources:
715-
sources_count += len(source.get("document", []))
713+
unique_ids = set()
714+
715+
for source in sources or []:
716+
if not source or len(source.keys()) == 0:
717+
continue
718+
719+
documents = source.get("document") or []
720+
metadatas = source.get("metadata") or []
721+
src_info = source.get("source") or {}
722+
723+
for index, _ in enumerate(documents):
724+
metadata = metadatas[index] if index < len(metadatas) else None
725+
_id = (
726+
(metadata or {}).get("source")
727+
or (src_info or {}).get("id")
728+
or "N/A"
729+
)
730+
unique_ids.add(_id)
731+
732+
sources_count = len(unique_ids)
716733

717734
await __event_emitter__(
718735
{

src/lib/components/chat/Messages/ResponseMessage.svelte

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -643,10 +643,12 @@
643643
<div>
644644
<div class="chat-{message.role} w-full min-w-full markdown-prose">
645645
<div>
646-
<StatusHistory
647-
statusHistory={message?.statusHistory}
648-
expand={message?.content === ''}
649-
/>
646+
{#if model?.info?.meta?.capabilities?.status_updates ?? true}
647+
<StatusHistory
648+
statusHistory={message?.statusHistory}
649+
expand={message?.content === ''}
650+
/>
651+
{/if}
650652

651653
{#if message?.files && message.files?.filter((f) => f.type === 'image').length > 0}
652654
<div class="my-1 w-full flex overflow-x-auto gap-2 flex-wrap">
@@ -732,7 +734,7 @@
732734
</div>
733735
{:else}
734736
<div class="w-full flex flex-col relative" id="response-content-container">
735-
{#if message.content === '' && !message.error && ((message?.statusHistory ?? [...(message?.status ? [message?.status] : [])]).length === 0 || (message?.statusHistory?.at(-1)?.hidden ?? false))}
737+
{#if message.content === '' && !message.error && ((model?.info?.meta?.capabilities?.status_updates ?? true) ? (message?.statusHistory ?? [...(message?.status ? [message?.status] : [])]).length === 0 || (message?.statusHistory?.at(-1)?.hidden ?? false) : true)}
736738
<Skeleton />
737739
{:else if message.content && message.error !== true}
738740
<!-- always show message contents even if there's an error -->

src/lib/components/workspace/Models/Capabilities.svelte

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,10 @@
3636
citations: {
3737
label: $i18n.t('Citations'),
3838
description: $i18n.t('Displays citations in the response')
39+
},
40+
status_updates: {
41+
label: $i18n.t('Status Updates'),
42+
description: $i18n.t('Displays status updates (e.g., web search progress) in the response')
3943
}
4044
};
4145
@@ -47,6 +51,7 @@
4751
code_interpreter?: boolean;
4852
usage?: boolean;
4953
citations?: boolean;
54+
status_updates?: boolean;
5055
} = {};
5156
</script>
5257

src/lib/components/workspace/Models/ModelEditor.svelte

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,7 @@
8686
image_generation: true,
8787
code_interpreter: true,
8888
citations: true,
89+
status_updates: true,
8990
usage: undefined
9091
};
9192

0 commit comments

Comments
 (0)