From c42655336be23e20baa52aa3ed7d8e84572eb04c Mon Sep 17 00:00:00 2001 From: DocShotgun <126566557+DocShotgun@users.noreply.github.com> Date: Sun, 17 Nov 2024 23:05:17 -0800 Subject: [PATCH] Config: Add option to disable fetching content from URLs --- backends/exllamav2/vision.py | 9 +++++++++ common/config_models.py | 7 +++++++ config_sample.yml | 3 +++ 3 files changed, 19 insertions(+) diff --git a/backends/exllamav2/vision.py b/backends/exllamav2/vision.py index d207d3e..168c80c 100644 --- a/backends/exllamav2/vision.py +++ b/backends/exllamav2/vision.py @@ -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: diff --git a/common/config_models.py b/common/config_models.py index 8102333..b8e7606 100644 --- a/common/config_models.py +++ b/common/config_models.py @@ -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=( diff --git a/config_sample.yml b/config_sample.yml index 388dcf4..48e58d9 100644 --- a/config_sample.yml +++ b/config_sample.yml @@ -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