add pro search disable

This commit is contained in:
pablodanswer 2025-02-02 17:54:42 -08:00 committed by Evan Lohn
parent 9a3ce504bc
commit c984c6c7f2
8 changed files with 41 additions and 10 deletions

View File

@ -36,6 +36,8 @@ basic_router = APIRouter(prefix="/settings")
def put_settings( def put_settings(
settings: Settings, _: User | None = Depends(current_admin_user) settings: Settings, _: User | None = Depends(current_admin_user)
) -> None: ) -> None:
print("PUTTING SETTINGS")
print(settings)
store_settings(settings) store_settings(settings)
@ -47,7 +49,10 @@ def fetch_settings(
) -> UserSettings: ) -> UserSettings:
"""Settings and notifications are stuffed into this single endpoint to reduce number of """Settings and notifications are stuffed into this single endpoint to reduce number of
Postgres calls""" Postgres calls"""
print("FETCHING SETTINGS")
general_settings = load_settings() general_settings = load_settings()
print("LOADED SETTINGS")
print(general_settings)
settings_notifications = get_settings_notifications(user, db_session) settings_notifications = get_settings_notifications(user, db_session)
try: try:

View File

@ -45,6 +45,8 @@ class Settings(BaseModel):
gpu_enabled: bool | None = None gpu_enabled: bool | None = None
product_gating: GatingType = GatingType.NONE product_gating: GatingType = GatingType.NONE
anonymous_user_enabled: bool | None = None anonymous_user_enabled: bool | None = None
pro_search_disabled: bool | None = None
auto_scroll: bool | None = None
class UserSettings(Settings): class UserSettings(Settings):

View File

@ -11,6 +11,14 @@ logger = setup_logger()
def load_settings() -> Settings: def load_settings() -> Settings:
kv_store = get_kv_store()
try:
stored_settings = kv_store.load(KV_SETTINGS_KEY)
settings = Settings(**stored_settings)
except Exception as e:
logger.error(f"Error loading settings from KV store: {str(e)}")
settings = Settings()
tenant_id = CURRENT_TENANT_ID_CONTEXTVAR.get() if MULTI_TENANT else None tenant_id = CURRENT_TENANT_ID_CONTEXTVAR.get() if MULTI_TENANT else None
redis_client = get_redis_client(tenant_id=tenant_id) redis_client = get_redis_client(tenant_id=tenant_id)
@ -26,10 +34,10 @@ def load_settings() -> Settings:
redis_client.set(OnyxRedisLocks.ANONYMOUS_USER_ENABLED, "0") redis_client.set(OnyxRedisLocks.ANONYMOUS_USER_ENABLED, "0")
except Exception as e: except Exception as e:
# Log the error and reset to default # Log the error and reset to default
logger.error(f"Error loading settings from Redis: {str(e)}") logger.error(f"Error loading anonymous user setting from Redis: {str(e)}")
anonymous_user_enabled = False anonymous_user_enabled = False
settings = Settings(anonymous_user_enabled=anonymous_user_enabled) settings.anonymous_user_enabled = anonymous_user_enabled
return settings return settings

View File

@ -228,6 +228,15 @@ export function SettingsForm() {
} }
/> />
<Checkbox
label="Pro Search Disabled"
sublabel="If set, users will not be able to use Pro Search."
checked={settings.pro_search_disabled}
onChange={(e) =>
handleToggleSettingsField("pro_search_disabled", e.target.checked)
}
/>
{NEXT_PUBLIC_CLOUD_ENABLED && settings.anonymous_user_enabled && ( {NEXT_PUBLIC_CLOUD_ENABLED && settings.anonymous_user_enabled && (
<AnonymousUserPath setPopup={setPopup} /> <AnonymousUserPath setPopup={setPopup} />
)} )}

View File

@ -10,6 +10,7 @@ export interface Settings {
notifications: Notification[]; notifications: Notification[];
needs_reindexing: boolean; needs_reindexing: boolean;
gpu_enabled: boolean; gpu_enabled: boolean;
pro_search_disabled: boolean;
product_gating: GatingType; product_gating: GatingType;
auto_scroll: boolean; auto_scroll: boolean;
} }

View File

@ -1327,7 +1327,8 @@ export function ChatPage({
systemPromptOverride: systemPromptOverride:
searchParams.get(SEARCH_PARAM_NAMES.SYSTEM_PROMPT) || undefined, searchParams.get(SEARCH_PARAM_NAMES.SYSTEM_PROMPT) || undefined,
useExistingUserMessage: isSeededChat, useExistingUserMessage: isSeededChat,
useLanggraph: proSearchEnabled, useLanggraph:
!settings?.settings.pro_search_disabled && proSearchEnabled,
}); });
const delay = (ms: number) => { const delay = (ms: number) => {

View File

@ -1,4 +1,4 @@
import React, { useEffect, useRef, useState } from "react"; import React, { useContext, useEffect, useRef, useState } from "react";
import { FiPlusCircle, FiPlus, FiInfo, FiX, FiFilter } from "react-icons/fi"; import { FiPlusCircle, FiPlus, FiInfo, FiX, FiFilter } from "react-icons/fi";
import { ChatInputOption } from "./ChatInputOption"; import { ChatInputOption } from "./ChatInputOption";
import { Persona } from "@/app/admin/assistants/interfaces"; import { Persona } from "@/app/admin/assistants/interfaces";
@ -35,6 +35,7 @@ import { truncateString } from "@/lib/utils";
import { buildImgUrl } from "../files/images/utils"; import { buildImgUrl } from "../files/images/utils";
import { useUser } from "@/components/user/UserProvider"; import { useUser } from "@/components/user/UserProvider";
import { AgenticToggle } from "./AgenticToggle"; import { AgenticToggle } from "./AgenticToggle";
import { SettingsContext } from "@/components/settings/SettingsProvider";
const MAX_INPUT_HEIGHT = 200; const MAX_INPUT_HEIGHT = 200;
export const SourceChip2 = ({ export const SourceChip2 = ({
@ -225,6 +226,7 @@ export function ChatInputBar({
setProSearchEnabled, setProSearchEnabled,
}: ChatInputBarProps) { }: ChatInputBarProps) {
const { user } = useUser(); const { user } = useUser();
const settings = useContext(SettingsContext);
useEffect(() => { useEffect(() => {
const textarea = textAreaRef.current; const textarea = textAreaRef.current;
if (textarea) { if (textarea) {
@ -789,12 +791,13 @@ export function ChatInputBar({
)} )}
</div> </div>
<div className="flex items-center my-auto"> <div className="flex items-center my-auto">
{retrievalEnabled && ( {retrievalEnabled &&
<AgenticToggle !settings?.settings.pro_search_disabled && (
proSearchEnabled={proSearchEnabled} <AgenticToggle
setProSearchEnabled={setProSearchEnabled} proSearchEnabled={proSearchEnabled}
/> setProSearchEnabled={setProSearchEnabled}
)} />
)}
<button <button
id="onyx-chat-input-send-button" id="onyx-chat-input-send-button"
className={`cursor-pointer ${ className={`cursor-pointer ${

View File

@ -51,6 +51,7 @@ export async function fetchSettingsSS(): Promise<CombinedSettings | null> {
notifications: [], notifications: [],
needs_reindexing: false, needs_reindexing: false,
anonymous_user_enabled: false, anonymous_user_enabled: false,
pro_search_disabled: false,
}; };
} else { } else {
throw new Error( throw new Error(
@ -62,6 +63,7 @@ export async function fetchSettingsSS(): Promise<CombinedSettings | null> {
} else { } else {
settings = await results[0].json(); settings = await results[0].json();
} }
console.log(JSON.stringify(settings));
let enterpriseSettings: EnterpriseSettings | null = null; let enterpriseSettings: EnterpriseSettings | null = null;
if (tasks.length > 1) { if (tasks.length > 1) {