enh: channels streaming agent
This commit is contained in:
1 parent
c951b4f262
commit
0037baeb26
4 files changed
+184
-114
No files matched your search
@@ -57,7 +57,7 @@ from open_webui.utils.models import (
|
||||
get_all_models,
|
||||
get_filtered_models,
|
||||
)
|
||||
from open_webui.utils.chat import generate_chat_completion
|
||||
|
||||
|
||||
|
||||
from open_webui.utils.auth import get_admin_user, get_verified_user
|
||||
@@ -979,57 +979,50 @@ async def model_response_handler(request, channel, message, user, db=None):
|
||||
],
|
||||
]
|
||||
|
||||
# Resolve model config (same helpers automations use)
|
||||
from open_webui.utils.automations import (
|
||||
_resolve_model_tool_ids,
|
||||
_resolve_model_features,
|
||||
_resolve_model_filter_ids,
|
||||
)
|
||||
|
||||
tool_ids = _resolve_model_tool_ids(request.app, model_id)
|
||||
features = _resolve_model_features(request.app, model_id)
|
||||
filter_ids = _resolve_model_filter_ids(request.app, model_id)
|
||||
|
||||
# Build full form_data — same shape as frontend POST.
|
||||
# The channel: prefix routes pipeline events to the
|
||||
# channel emitter in socket/main.py instead of the
|
||||
# default chat emitter.
|
||||
form_data = {
|
||||
'model': model_id,
|
||||
'messages': [
|
||||
system_message,
|
||||
{'role': 'user', 'content': content},
|
||||
],
|
||||
'stream': False,
|
||||
'stream': True,
|
||||
'chat_id': f'channel:{channel.id}',
|
||||
'id': response_message.id,
|
||||
'session_id': f'channel:{channel.id}',
|
||||
'background_tasks': {},
|
||||
}
|
||||
if tool_ids:
|
||||
form_data['tool_ids'] = tool_ids
|
||||
if features:
|
||||
form_data['features'] = features
|
||||
if filter_ids:
|
||||
form_data['filter_ids'] = filter_ids
|
||||
|
||||
res = await generate_chat_completion(
|
||||
request,
|
||||
form_data=form_data,
|
||||
user=user,
|
||||
# Call the full chat completion pipeline — streaming,
|
||||
# tools, filters, RAG — everything. The pipeline runs as
|
||||
# an async task; the channel emitter handles progressive
|
||||
# message updates via socket events.
|
||||
await request.app.state.CHAT_COMPLETION_HANDLER(
|
||||
request, form_data, user=user
|
||||
)
|
||||
|
||||
if res:
|
||||
if res.get('choices', []) and len(res['choices']) > 0:
|
||||
await update_message_by_id(
|
||||
request,
|
||||
channel.id,
|
||||
response_message.id,
|
||||
MessageForm(
|
||||
**{
|
||||
'content': res['choices'][0]['message']['content'],
|
||||
'meta': {
|
||||
'done': True,
|
||||
},
|
||||
}
|
||||
),
|
||||
user,
|
||||
db,
|
||||
)
|
||||
elif res.get('error', None):
|
||||
await update_message_by_id(
|
||||
request,
|
||||
channel.id,
|
||||
response_message.id,
|
||||
MessageForm(
|
||||
**{
|
||||
'content': f'Error: {res["error"]}',
|
||||
'meta': {
|
||||
'done': True,
|
||||
},
|
||||
}
|
||||
),
|
||||
user,
|
||||
db,
|
||||
)
|
||||
except Exception as e:
|
||||
log.info(e)
|
||||
pass
|
||||
log.exception(e)
|
||||
|
||||
return True
|
||||
|
||||
|
||||
Reference in new issue
Block a user