This commit is contained in:
Timothy Jaeryang Baek 2025-06-23 12:54:50 +04:00
parent 9b2c3dec3a
commit f4b92868c4

View File

@ -804,7 +804,6 @@ async def process_chat_payload(request, form_data, user, metadata, model):
raise e
try:
filter_functions = [
Functions.get_function_by_id(filter_id)
for filter_id in get_sorted_filter_ids(
@ -1741,7 +1740,7 @@ async def process_chat_response(
},
)
async def stream_body_handler(response):
async def stream_body_handler(response, form_data):
nonlocal content
nonlocal content_blocks
@ -1770,7 +1769,7 @@ async def process_chat_response(
filter_functions=filter_functions,
filter_type="stream",
form_data=data,
extra_params=extra_params,
extra_params={"__body__": form_data, **extra_params},
)
if data:
@ -2032,7 +2031,7 @@ async def process_chat_response(
if response.background:
await response.background()
await stream_body_handler(response)
await stream_body_handler(response, form_data)
MAX_TOOL_CALL_RETRIES = 10
tool_call_retries = 0
@ -2181,9 +2180,7 @@ async def process_chat_response(
)
try:
res = await generate_chat_completion(
request,
{
new_form_data = {
"model": model_id,
"stream": True,
"tools": form_data["tools"],
@ -2191,12 +2188,16 @@ async def process_chat_response(
*form_data["messages"],
*convert_content_blocks_to_messages(content_blocks),
],
},
}
res = await generate_chat_completion(
request,
new_form_data,
user,
)
if isinstance(res, StreamingResponse):
await stream_body_handler(res)
await stream_body_handler(res, new_form_data)
else:
break
except Exception as e: