Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion packages/ragbits-chat/src/ragbits/chat/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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"
Expand All @@ -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]:
Expand Down
7 changes: 7 additions & 0 deletions packages/ragbits-chat/tests/unit/test_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"