mirror of
https://github.com/theroyallab/tabbyAPI.git
synced 2026-04-28 18:21:42 +00:00
Config: Add option to disable fetching content from URLs
This commit is contained in:
@@ -9,6 +9,7 @@ import aiohttp
|
|||||||
from common.networking import (
|
from common.networking import (
|
||||||
handle_request_error,
|
handle_request_error,
|
||||||
)
|
)
|
||||||
|
from common.tabby_config import config
|
||||||
from fastapi import HTTPException
|
from fastapi import HTTPException
|
||||||
from exllamav2.generator import ExLlamaV2MMEmbedding
|
from exllamav2.generator import ExLlamaV2MMEmbedding
|
||||||
from async_lru import alru_cache
|
from async_lru import alru_cache
|
||||||
@@ -31,6 +32,14 @@ async def get_image(url: str) -> Image:
|
|||||||
|
|
||||||
else:
|
else:
|
||||||
# Handle image URL
|
# 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 aiohttp.ClientSession() as session:
|
||||||
async with session.get(url) as response:
|
async with session.get(url) as response:
|
||||||
if response.status == 200:
|
if response.status == 200:
|
||||||
|
|||||||
@@ -78,6 +78,13 @@ class NetworkConfig(BaseConfigModel):
|
|||||||
"Turn on this option if you are ONLY connecting from localhost."
|
"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(
|
send_tracebacks: Optional[bool] = Field(
|
||||||
False,
|
False,
|
||||||
description=(
|
description=(
|
||||||
|
|||||||
@@ -20,6 +20,9 @@ network:
|
|||||||
# Turn on this option if you are ONLY connecting from localhost.
|
# Turn on this option if you are ONLY connecting from localhost.
|
||||||
disable_auth: false
|
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).
|
# Send tracebacks over the API (default: False).
|
||||||
# NOTE: Only enable this for debug purposes.
|
# NOTE: Only enable this for debug purposes.
|
||||||
send_tracebacks: false
|
send_tracebacks: false
|
||||||
|
|||||||
Reference in New Issue
Block a user