Source code for smarter.apps.prompt.views.detailviews.prompt_sandbox_view

# pylint: disable=W0613,C0302
"""PromptSandboxView is a Django class-based view that serves as the base URL."""

from django.http import (
    HttpRequest,
    HttpResponseNotFound,
)

from smarter.common.conf import smarter_settings
from smarter.lib import logging
from smarter.lib.django import waffle
from smarter.lib.django.views import SmarterAuthenticatedNeverCachedWebView
from smarter.lib.django.waffle import SmarterWaffleSwitches


[docs] def should_log(level): """Check if logging should be done based on the waffle switch.""" return waffle.switch_is_active(SmarterWaffleSwitches.PROMPT_LOGGING)
logger = logging.getSmarterLogger(__name__, condition_func=should_log)
[docs] def should_log_verbose(level): """Check if logging should be done based on the waffle switch.""" return smarter_settings.verbose_logging
verbose_logger = logging.getSmarterLogger(__name__, condition_func=should_log_verbose)
[docs] class PromptSandboxView(SmarterAuthenticatedNeverCachedWebView): """ Base url for LLMClient.sandbox_url. This a a noop view that is used for generating the base URL for the workbench prompt /prompt/ and /prompt/config/ endpoints, both of which are constructed inside of the React app and are not actual Django views. """ @property def formatted_class_name(self) -> str: """Returns a formatted string of the class name for logging purposes.""" class_name = f"{__name__}.{PromptSandboxView.__name__}[{id(self)}]" return self.formatted_text(class_name)
[docs] def dispatch(self, request: HttpRequest, *args, **kwargs): """ Return 404 for every request: the sandbox has no Django view of its own. :param request: The request. :param args: Unused positional arguments. :param kwargs: Unused keyword arguments. :returns: An ``HttpResponseNotFound``. """ return HttpResponseNotFound()