diff --git a/packages/ragbits-chat/src/ragbits/chat/api.py b/packages/ragbits-chat/src/ragbits/chat/api.py index e018538976..d1d4dee545 100644 --- a/packages/ragbits-chat/src/ragbits/chat/api.py +++ b/packages/ragbits-chat/src/ragbits/chat/api.py @@ -61,6 +61,7 @@ def __init__( debug_mode: bool = False, auth_backend: AuthenticationBackend | type[AuthenticationBackend] | str | None = None, theme_path: str | None = None, + frontend_base_url: str | None = None, ) -> None: """ Initialize the RagbitsAPI. @@ -73,6 +74,7 @@ def __init__( debug_mode: Flag enabling debug tools in the default UI auth_backend: Authentication backend for user authentication. If None, no authentication required. theme_path: Path to a JSON file containing HeroUI theme configuration from heroui.com/themes + frontend_base_url: Base URL used for redirects to the frontend. Defaults to the configured base URL. """ self.chat_interface: ChatInterface = self._load_chat_interface(chat_interface) self.dist_dir = Path(ui_build_dir) if ui_build_dir else Path(__file__).parent / "ui-build" @@ -81,7 +83,7 @@ def __init__( self.auth_backend = self._load_auth_backend(auth_backend) self.theme_path = Path(theme_path) if theme_path else None - self.frontend_base_url = BASE_URL + self.frontend_base_url = frontend_base_url if frontend_base_url is not None else BASE_URL @asynccontextmanager async def lifespan(app: FastAPI) -> AsyncGenerator[None, None]: diff --git a/packages/ragbits-chat/tests/unit/test_api.py b/packages/ragbits-chat/tests/unit/test_api.py index 86718b0930..66ce176f2a 100644 --- a/packages/ragbits-chat/tests/unit/test_api.py +++ b/packages/ragbits-chat/tests/unit/test_api.py @@ -463,3 +463,10 @@ def test_feedback_endpoint_unauthenticated(client: TestClient) -> None: assert response.status_code == 401 data = response.json() assert data["detail"] == "Authentication required" + + +def test_frontend_base_url_can_be_configured(mock_chat_interface: type[MockChatInterface]) -> None: + """RagbitsAPI accepts a frontend base URL for OAuth redirects.""" + api = RagbitsAPI(mock_chat_interface, frontend_base_url="https://frontend.example") + + assert api.frontend_base_url == "https://frontend.example"