Skip to content

Commit e695d85

Browse files
committed
refac
1 parent 34d569d commit e695d85

1 file changed

Lines changed: 35 additions & 0 deletions

File tree

backend/open_webui/utils/middleware.py

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3755,6 +3755,40 @@ async def flush_pending_delta_data(threshold: int = 0):
37553755
elif data.get('type', '').startswith('response.'):
37563756
output, response_metadata = handle_responses_streaming_event(data, output)
37573757

3758+
# Emit citation sources from finalized output items
3759+
# (mirrors Chat Completions annotation handling at delta level)
3760+
if data.get('type') == 'response.output_item.done':
3761+
item = data.get('item', {})
3762+
if item.get('type') == 'message':
3763+
for part in item.get('content', []):
3764+
for annotation in part.get('annotations', []):
3765+
if annotation.get('type') == 'url_citation':
3766+
# Handle both flat (Responses API) and nested (Chat Completions) formats
3767+
url_citation = annotation.get('url_citation', annotation)
3768+
3769+
url = url_citation.get('url', '')
3770+
title = url_citation.get('title', url)
3771+
3772+
if url:
3773+
await event_emitter(
3774+
{
3775+
'type': 'source',
3776+
'data': {
3777+
'source': {
3778+
'name': title,
3779+
'url': url,
3780+
},
3781+
'document': [title],
3782+
'metadata': [
3783+
{
3784+
'source': url,
3785+
'name': title,
3786+
}
3787+
],
3788+
},
3789+
}
3790+
)
3791+
37583792
processed_data = {
37593793
'output': full_output(),
37603794
'content': serialize_output(full_output()),
@@ -4187,6 +4221,7 @@ async def flush_pending_delta_data(threshold: int = 0):
41874221
)
41884222
reasoning_item['status'] = 'completed'
41894223

4224+
41904225
if response_tool_calls:
41914226
tool_calls.append(_split_tool_calls(response_tool_calls))
41924227

0 commit comments

Comments
 (0)