Config: Add option to disable fetching content from URLs
This commit is contained in:
parent
dd41eec8a4
commit
c42655336b
3 changed files with 19 additions and 0 deletions
|
|
@ -9,6 +9,7 @@ import aiohttp
|
|||
from common.networking import (
|
||||
handle_request_error,
|
||||
)
|
||||
from common.tabby_config import config
|
||||
from fastapi import HTTPException
|
||||
from exllamav2.generator import ExLlamaV2MMEmbedding
|
||||
from async_lru import alru_cache
|
||||
|
|
@ -31,6 +32,14 @@ async def get_image(url: str) -> Image:
|
|||
|
||||
else:
|
||||
# Handle image URL
|
||||
if config.network.disable_fetch_requests:
|
||||
error_message = handle_request_error(
|
||||
f"Failed to fetch image from {url} as fetch requests are disabled.",
|
||||
exc_info=False,
|
||||
).error.message
|
||||
|
||||
raise HTTPException(400, error_message)
|
||||
|
||||
async with aiohttp.ClientSession() as session:
|
||||
async with session.get(url) as response:
|
||||
if response.status == 200:
|
||||
|
|
|
|||
|
|
@ -78,6 +78,13 @@ class NetworkConfig(BaseConfigModel):
|
|||
"Turn on this option if you are ONLY connecting from localhost."
|
||||
),
|
||||
)
|
||||
disable_fetch_requests: Optional[bool] = Field(
|
||||
False,
|
||||
description=(
|
||||
"Disable fetching external content in response to requests,"
|
||||
"such as images from URLs."
|
||||
),
|
||||
)
|
||||
send_tracebacks: Optional[bool] = Field(
|
||||
False,
|
||||
description=(
|
||||
|
|
|
|||
|
|
@ -20,6 +20,9 @@ network:
|
|||
# Turn on this option if you are ONLY connecting from localhost.
|
||||
disable_auth: false
|
||||
|
||||
# Disable fetching external content in response to requests, such as images from URLs.
|
||||
disable_fetch_requests: false
|
||||
|
||||
# Send tracebacks over the API (default: False).
|
||||
# NOTE: Only enable this for debug purposes.
|
||||
send_tracebacks: false
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue