Co-Authored-By: Classic298 <27028174+Classic298@users.noreply.github.com>
This commit is contained in:
Timothy Jaeryang Baek
2026-05-20 00:22:27 +04:00
co-authored by Classic298
parent d07fd7d6d8
commit 2b99945d27
2 changed files with 41 additions and 9 deletions
+27 -4
View File
@@ -30,7 +30,7 @@ from open_webui.config import (
from open_webui.constants import TASKS
from open_webui.env import (
BYPASS_MODEL_ACCESS_CONTROL,
CHAT_RESPONSE_MAX_TOOL_CALL_RETRIES,
CHAT_RESPONSE_MAX_TOOL_CALL_ITERATIONS,
CHAT_RESPONSE_STREAM_DELTA_CHUNK_SIZE,
ENABLE_CHAT_RESPONSE_BASE64_IMAGE_URL_CONVERSION,
ENABLE_QUERIES_CACHE,
@@ -4438,7 +4438,7 @@ async def streaming_chat_response_handler(response, ctx):
if response.background:
await response.background()
tool_call_retries = 0
tool_call_iterations = 0
tool_call_sources = [] # Track citation sources from tool results
all_tool_call_sources = [] # Accumulated sources across all iterations
user_message = get_last_user_message(form_data['messages'])
@@ -4458,8 +4458,11 @@ async def streaming_chat_response_handler(response, ctx):
get_content_from_message(original_system_message) if original_system_message else None
)
while len(tool_calls) > 0 and tool_call_retries < CHAT_RESPONSE_MAX_TOOL_CALL_RETRIES:
tool_call_retries += 1
while tool_calls and (
CHAT_RESPONSE_MAX_TOOL_CALL_ITERATIONS is None
or tool_call_iterations < CHAT_RESPONSE_MAX_TOOL_CALL_ITERATIONS
):
tool_call_iterations += 1
response_tool_calls = tool_calls.pop(0)
@@ -4832,6 +4835,26 @@ async def streaming_chat_response_handler(response, ctx):
log.debug(e)
break
if (
CHAT_RESPONSE_MAX_TOOL_CALL_ITERATIONS is not None
and tool_calls
and tool_call_iterations >= CHAT_RESPONSE_MAX_TOOL_CALL_ITERATIONS
):
log.warning('Tool-call iteration limit reached (%s)', CHAT_RESPONSE_MAX_TOOL_CALL_ITERATIONS)
error_content = f'Tool-call limit reached ({CHAT_RESPONSE_MAX_TOOL_CALL_ITERATIONS} iterations).'
if not metadata.get('chat_id', '').startswith('channel:'):
await Chats.upsert_message_to_chat_by_id_and_message_id(
metadata['chat_id'],
metadata['message_id'],
{'error': {'content': error_content}},
)
await event_emitter(
{
'type': 'chat:message:error',
'data': {'error': {'content': error_content}},
}
)
if DETECT_CODE_INTERPRETER:
MAX_RETRIES = 5
retries = 0