Skip to content

Commit

Permalink
Admin default (#4032)
Browse files Browse the repository at this point in the history
* clean up

* minor cleanup

* building

* update agnetic message look

* k

* fix alembic history
  • Loading branch information
pablonyx authored Feb 19, 2025
1 parent 630bdf7 commit 9635522
Show file tree
Hide file tree
Showing 15 changed files with 113 additions and 60 deletions.
31 changes: 31 additions & 0 deletions backend/alembic/versions/b388730a2899_nullable_preferences.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
"""nullable preferences
Revision ID: b388730a2899
Revises: 1a03d2c2856b
Create Date: 2025-02-17 18:49:22.643902
"""
from alembic import op


# revision identifiers, used by Alembic.
revision = "b388730a2899"
down_revision = "1a03d2c2856b"
branch_labels = None
depends_on = None


def upgrade() -> None:
op.alter_column("user", "temperature_override_enabled", nullable=True)
op.alter_column("user", "auto_scroll", nullable=True)


def downgrade() -> None:
# Ensure no null values before making columns non-nullable
op.execute(
'UPDATE "user" SET temperature_override_enabled = false WHERE temperature_override_enabled IS NULL'
)
op.execute('UPDATE "user" SET auto_scroll = false WHERE auto_scroll IS NULL')

op.alter_column("user", "temperature_override_enabled", nullable=False)
op.alter_column("user", "auto_scroll", nullable=False)
9 changes: 5 additions & 4 deletions backend/onyx/db/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -148,11 +148,12 @@ class User(SQLAlchemyBaseUserTableUUID, Base):
putting here for simpicity
"""

# if specified, controls the assistants that are shown to the user + their order
# if not specified, all assistants are shown
temperature_override_enabled: Mapped[bool] = mapped_column(Boolean, default=False)
auto_scroll: Mapped[bool] = mapped_column(Boolean, default=True)
temperature_override_enabled: Mapped[bool | None] = mapped_column(
Boolean, default=None
)
auto_scroll: Mapped[bool | None] = mapped_column(Boolean, default=None)
shortcut_enabled: Mapped[bool] = mapped_column(Boolean, default=False)

chosen_assistants: Mapped[list[int] | None] = mapped_column(
postgresql.JSONB(), nullable=True, default=None
)
Expand Down
6 changes: 4 additions & 2 deletions backend/onyx/server/manage/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,11 @@ class UserPreferences(BaseModel):
hidden_assistants: list[int] = []
visible_assistants: list[int] = []
default_model: str | None = None
auto_scroll: bool | None = None
pinned_assistants: list[int] | None = None
shortcut_enabled: bool | None = None

# These will default to workspace settings on the frontend if not set
auto_scroll: bool | None = None
temperature_override_enabled: bool | None = None


Expand Down Expand Up @@ -86,12 +88,12 @@ def from_model(
preferences=(
UserPreferences(
shortcut_enabled=user.shortcut_enabled,
auto_scroll=user.auto_scroll,
chosen_assistants=user.chosen_assistants,
default_model=user.default_model,
hidden_assistants=user.hidden_assistants,
pinned_assistants=user.pinned_assistants,
visible_assistants=user.visible_assistants,
auto_scroll=user.auto_scroll,
temperature_override_enabled=user.temperature_override_enabled,
)
),
Expand Down
4 changes: 3 additions & 1 deletion backend/onyx/server/settings/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,9 @@ class Settings(BaseModel):
application_status: ApplicationStatus = ApplicationStatus.ACTIVE
anonymous_user_enabled: bool | None = None
pro_search_disabled: bool | None = None
auto_scroll: bool | None = None

temperature_override_enabled: bool = False
auto_scroll: bool = False


class UserSettings(Settings):
Expand Down
13 changes: 12 additions & 1 deletion web/src/app/admin/settings/SettingsForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -213,12 +213,23 @@ export function SettingsForm() {
<Title className="mb-4">Workspace Settings</Title>
<Checkbox
label="Auto-scroll"
sublabel="If set, the chat window will automatically scroll to the bottom as new lines of text are generated by the AI model."
sublabel="If set, the chat window will automatically scroll to the bottom as new lines of text are generated by the AI model. This can be overridden by individual user settings."
checked={settings.auto_scroll}
onChange={(e) =>
handleToggleSettingsField("auto_scroll", e.target.checked)
}
/>
<Checkbox
label="Override default temperature"
sublabel="If set, users will be able to override the default temperature for each assistant."
checked={settings.temperature_override_enabled}
onChange={(e) =>
handleToggleSettingsField(
"temperature_override_enabled",
e.target.checked
)
}
/>
<Checkbox
label="Anonymous Users"
sublabel="If set, users will not be required to sign in to use Onyx."
Expand Down
2 changes: 1 addition & 1 deletion web/src/app/admin/settings/interfaces.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ export interface Settings {
pro_search_disabled: boolean | null;
application_status: ApplicationStatus;
auto_scroll: boolean;
temperature_override_enabled: boolean;
}

export enum NotificationType {
Expand Down Expand Up @@ -54,7 +55,6 @@ export interface EnterpriseSettings {
custom_popup_header: string | null;
custom_popup_content: string | null;
enable_consent_screen: boolean | null;
auto_scroll: boolean;
}

export interface CombinedSettings {
Expand Down
4 changes: 1 addition & 3 deletions web/src/app/chat/ChatPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -1870,9 +1870,7 @@ export function ChatPage({
});

const autoScrollEnabled =
user?.preferences?.auto_scroll == null
? settings?.enterpriseSettings?.auto_scroll || false
: user?.preferences?.auto_scroll! && !agenticGenerating;
(user?.preferences?.auto_scroll && !agenticGenerating) ?? false;

useScrollonStream({
chatState: currentSessionChatState,
Expand Down
43 changes: 8 additions & 35 deletions web/src/app/chat/message/AgenticMessage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -537,7 +537,6 @@ export const AgenticMessage = ({
{includeMessageSwitcher && (
<div className="-mx-1 mr-auto">
<MessageSwitcher
disableForStreaming={!isComplete}
currentPage={currentMessageInd + 1}
totalPages={otherMessagesCanSwitchTo.length}
handlePrevious={() => {
Expand Down Expand Up @@ -624,7 +623,6 @@ export const AgenticMessage = ({
{includeMessageSwitcher && (
<div className="-mx-1 mr-auto">
<MessageSwitcher
disableForStreaming={!isComplete}
currentPage={currentMessageInd + 1}
totalPages={otherMessagesCanSwitchTo.length}
handlePrevious={() => {
Expand Down Expand Up @@ -703,52 +701,27 @@ function MessageSwitcher({
totalPages,
handlePrevious,
handleNext,
disableForStreaming,
}: {
currentPage: number;
totalPages: number;
handlePrevious: () => void;
handleNext: () => void;
disableForStreaming?: boolean;
}) {
return (
<div className="flex items-center text-sm space-x-0.5">
<TooltipProvider>
<Tooltip>
<TooltipTrigger asChild>
<div>
<Hoverable
icon={FiChevronLeft}
onClick={currentPage === 1 ? undefined : handlePrevious}
/>
</div>
</TooltipTrigger>
<TooltipContent>
{disableForStreaming ? "Disabled" : "Previous"}
</TooltipContent>
</Tooltip>
</TooltipProvider>
<Hoverable
icon={FiChevronLeft}
onClick={currentPage === 1 ? undefined : handlePrevious}
/>

<span className="text-text-darker select-none">
{currentPage} / {totalPages}
{disableForStreaming ? "Complete" : "Generating"}
</span>

<TooltipProvider>
<Tooltip>
<TooltipTrigger asChild>
<div>
<Hoverable
icon={FiChevronRight}
onClick={currentPage === totalPages ? undefined : handleNext}
/>
</div>
</TooltipTrigger>
<TooltipContent>
{disableForStreaming ? "Disabled" : "Next"}
</TooltipContent>
</Tooltip>
</TooltipProvider>
<Hoverable
icon={FiChevronRight}
onClick={currentPage === totalPages ? undefined : handleNext}
/>
</div>
);
}
Empty file removed web/src/app/chat/modal/Inpu
Empty file.
Empty file.
6 changes: 2 additions & 4 deletions web/src/app/chat/modal/UserSettingsModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -154,11 +154,9 @@ export function UserSettingsModal({
});
}
};
const defaultProvider = llmProviders.find(
(llmProvider) => llmProvider.is_default_provider
);

const settings = useContext(SettingsContext);
const autoScroll = settings?.enterpriseSettings?.auto_scroll;
const autoScroll = settings?.settings?.auto_scroll;

const checked =
user?.preferences?.auto_scroll === null
Expand Down
2 changes: 1 addition & 1 deletion web/src/app/ee/admin/whitelabeling/WhitelabelingForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ export function WhitelabelingForm() {
<div>
<Formik
initialValues={{
auto_scroll: enterpriseSettings?.auto_scroll || false,
auto_scroll: settings?.settings?.auto_scroll || false,
application_name: enterpriseSettings?.application_name || null,
use_custom_logo: enterpriseSettings?.use_custom_logo || false,
use_custom_logotype: enterpriseSettings?.use_custom_logotype || false,
Expand Down
13 changes: 7 additions & 6 deletions web/src/components/context/AppProvider.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
"use client";
import { CombinedSettings } from "@/app/admin/settings/interfaces";
import { UserProvider } from "../user/UserProvider";
import { ProviderContextProvider } from "../chat/ProviderContext";
Expand Down Expand Up @@ -27,18 +28,18 @@ export const AppProvider = ({
hasImageCompatibleModel,
}: AppProviderProps) => {
return (
<UserProvider user={user}>
<ProviderContextProvider>
<SettingsProvider settings={settings}>
<SettingsProvider settings={settings}>
<UserProvider settings={settings} user={user}>
<ProviderContextProvider>
<AssistantsProvider
initialAssistants={assistants}
hasAnyConnectors={hasAnyConnectors}
hasImageCompatibleModel={hasImageCompatibleModel}
>
{children}
</AssistantsProvider>
</SettingsProvider>
</ProviderContextProvider>
</UserProvider>
</ProviderContextProvider>
</UserProvider>
</SettingsProvider>
);
};
1 change: 1 addition & 0 deletions web/src/components/settings/lib.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ export async function fetchSettingsSS(): Promise<CombinedSettings | null> {
needs_reindexing: false,
anonymous_user_enabled: false,
pro_search_disabled: false,
temperature_override_enabled: true,
};
} else {
throw new Error(
Expand Down
39 changes: 37 additions & 2 deletions web/src/components/user/UserProvider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import React, { createContext, useContext, useState, useEffect } from "react";
import { User, UserRole } from "@/lib/types";
import { getCurrentUser } from "@/lib/user";
import { usePostHog } from "posthog-js/react";
import { CombinedSettings } from "@/app/admin/settings/interfaces";
import { SettingsContext } from "../settings/SettingsProvider";

interface UserContextType {
user: User | null;
Expand All @@ -26,14 +28,47 @@ const UserContext = createContext<UserContextType | undefined>(undefined);
export function UserProvider({
children,
user,
settings,
}: {
children: React.ReactNode;
user: User | null;
settings: CombinedSettings;
}) {
const [upToDateUser, setUpToDateUser] = useState<User | null>(user);

const updatedSettings = useContext(SettingsContext);
const posthog = usePostHog();

// For auto_scroll and temperature_override_enabled:
// - If user has a preference set, use that
// - Otherwise, use the workspace setting if available
function mergeUserPreferences(
currentUser: User | null,
currentSettings: CombinedSettings | null
): User | null {
if (!currentUser) return null;
return {
...currentUser,
preferences: {
...currentUser.preferences,
auto_scroll:
currentUser.preferences?.auto_scroll ??
currentSettings?.settings?.auto_scroll ??
false,
temperature_override_enabled:
currentUser.preferences?.temperature_override_enabled ??
currentSettings?.settings?.temperature_override_enabled ??
false,
},
};
}

const [upToDateUser, setUpToDateUser] = useState<User | null>(
mergeUserPreferences(user, settings)
);

useEffect(() => {
setUpToDateUser(mergeUserPreferences(user, updatedSettings));
}, [user, updatedSettings]);

useEffect(() => {
if (!posthog) return;

Expand Down

0 comments on commit 9635522

Please sign in to comment.