chore: format

This commit is contained in:
Timothy Jaeryang Baek
2026-03-24 06:07:20 -05:00
parent 9f946dec60
commit f7e07f3ca1
73 changed files with 1820 additions and 114 deletions
@@ -226,7 +226,9 @@ def filter_allowed_access_grants(
return access_grants
# Check if user can share publicly
if (has_public_read_access_grant(access_grants) or has_public_write_access_grant(access_grants)) and not has_permission(
if (
has_public_read_access_grant(access_grants) or has_public_write_access_grant(access_grants)
) and not has_permission(
user_id,
public_permission_key,
default_permissions,
+29 -31
View File
@@ -3534,7 +3534,6 @@ async def streaming_chat_response_handler(response, ctx):
)
# Check for Responses API events (type field starts with "response.")
elif data.get('type', '').startswith('response.'):
output, response_metadata = handle_responses_streaming_event(data, output)
processed_data = {
@@ -3973,19 +3972,20 @@ async def streaming_chat_response_handler(response, ctx):
}
responses_api_tool_calls = []
for item in output:
if (
item.get('type') == 'function_call'
and item.get('call_id') not in handled_call_ids
):
if item.get('type') == 'function_call' and item.get('call_id') not in handled_call_ids:
arguments = item.get('arguments', '{}')
responses_api_tool_calls.append({
'id': item.get('call_id', ''),
'index': len(responses_api_tool_calls),
'function': {
'name': item.get('name', ''),
'arguments': arguments if isinstance(arguments, str) else json.dumps(arguments),
},
})
responses_api_tool_calls.append(
{
'id': item.get('call_id', ''),
'index': len(responses_api_tool_calls),
'function': {
'name': item.get('name', ''),
'arguments': arguments
if isinstance(arguments, str)
else json.dumps(arguments),
},
}
)
if responses_api_tool_calls:
tool_calls.append(_split_tool_calls(responses_api_tool_calls))
@@ -4021,10 +4021,7 @@ async def streaming_chat_response_handler(response, ctx):
# Append function_call items for each tool call
# (Responses API already has them from streaming, so skip duplicates)
existing_call_ids = {
item.get('call_id') for item in output
if item.get('type') == 'function_call'
}
existing_call_ids = {item.get('call_id') for item in output if item.get('type') == 'function_call'}
for tc in response_tool_calls:
call_id = tc.get('id', '')
if call_id not in existing_call_ids:
@@ -4312,9 +4309,8 @@ async def streaming_chat_response_handler(response, ctx):
if ENABLE_RESPONSES_API_STATEFUL and last_response_id:
system_message = get_system_message(form_data['messages'])
new_form_data['messages'] = (
([system_message] if system_message else [])
+ convert_output_to_messages(output, raw=True)
)
[system_message] if system_message else []
) + convert_output_to_messages(output, raw=True)
new_form_data['previous_response_id'] = last_response_id
else:
tool_messages = convert_output_to_messages(output, raw=True)
@@ -4338,13 +4334,18 @@ async def streaming_chat_response_handler(response, ctx):
]
if image_urls:
new_form_data['messages'].append({
'role': 'user',
'content': [
{'type': 'text', 'text': 'Here are the images from the tool results above. Please analyze them.'},
*[{'type': 'image_url', 'image_url': {'url': url}} for url in image_urls],
],
})
new_form_data['messages'].append(
{
'role': 'user',
'content': [
{
'type': 'text',
'text': 'Here are the images from the tool results above. Please analyze them.',
},
*[{'type': 'image_url', 'image_url': {'url': url}} for url in image_urls],
],
}
)
res = await generate_chat_completion(
request,
@@ -4370,10 +4371,7 @@ async def streaming_chat_response_handler(response, ctx):
and prior_output[-1].get('status') == 'in_progress'
):
msg_parts = prior_output[-1].get('content', [])
if (
not msg_parts
or (len(msg_parts) == 1 and not msg_parts[0].get('text', '').strip())
):
if not msg_parts or (len(msg_parts) == 1 and not msg_parts[0].get('text', '').strip()):
prior_output.pop()
output = []
await stream_body_handler(res, new_form_data)
+1 -6
View File
@@ -433,11 +433,7 @@ def strip_empty_content_blocks(messages: list[dict]) -> list[dict]:
cleaned = [
block
for block in content
if not (
isinstance(block, dict)
and block.get('type') == 'text'
and not block.get('text', '').strip()
)
if not (isinstance(block, dict) and block.get('type') == 'text' and not block.get('text', '').strip())
]
if cleaned:
message['content'] = cleaned
@@ -521,7 +517,6 @@ def get_gravatar_url(email):
return f'https://www.gravatar.com/avatar/{hash_hex}?d=mp'
# Give us each day the data we require, and forgive us our
# technical debts as we forgive those who commit upstream.
# Lead the bits not into corruption but deliver them from
+1 -4
View File
@@ -862,9 +862,7 @@ async def get_terminal_system_prompt(
return None
# 2. Fetch system prompt
async with session.get(
f'{base}/system', headers=headers, cookies=cookies or {}
) as resp:
async with session.get(f'{base}/system', headers=headers, cookies=cookies or {}) as resp:
if resp.status == 200:
data = await resp.json()
return data.get('prompt')
@@ -1190,7 +1188,6 @@ async def get_tool_servers_data(servers: List[Dict[str, Any]]) -> List[Dict[str,
return results
async def execute_tool_server(
url: str,
headers: Dict[str, str],