Skip to content

Commit 5b04f37

Browse files
committed
frontend/llm: hide account/llm settings only if all LLM services are disabled, including user defined LLMs
1 parent 7930560 commit 5b04f37

File tree

3 files changed

+32
-20
lines changed

3 files changed

+32
-20
lines changed

src/packages/frontend/account/other-settings.tsx

Lines changed: 28 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -20,16 +20,16 @@ import {
2020
import AIAvatar from "@cocalc/frontend/components/ai-avatar";
2121
import { IS_MOBILE, IS_TOUCH } from "@cocalc/frontend/feature";
2222
import LLMSelector from "@cocalc/frontend/frame-editors/llm/llm-selector";
23-
import { NewFilenameFamilies } from "@cocalc/frontend/project/utils";
24-
import track from "@cocalc/frontend/user-tracking";
25-
import { webapp_client } from "@cocalc/frontend/webapp-client";
26-
import { DEFAULT_NEW_FILENAMES, NEW_FILENAMES } from "@cocalc/util/db-schema";
2723
import {
2824
VBAR_EXPLANATION,
2925
VBAR_KEY,
3026
VBAR_OPTIONS,
3127
getValidVBAROption,
32-
} from "../project/page/vbar";
28+
} from "@cocalc/frontend/project/page/vbar";
29+
import { NewFilenameFamilies } from "@cocalc/frontend/project/utils";
30+
import track from "@cocalc/frontend/user-tracking";
31+
import { webapp_client } from "@cocalc/frontend/webapp-client";
32+
import { DEFAULT_NEW_FILENAMES, NEW_FILENAMES } from "@cocalc/util/db-schema";
3333
import { dark_mode_mins, get_dark_mode_config } from "./dark-mode";
3434
import Tours from "./tours";
3535
import { useLanguageModelSetting } from "./useLanguageModelSetting";
@@ -44,6 +44,7 @@ interface Props {
4444
export function OtherSettings(props: Readonly<Props>): JSX.Element {
4545
const isCoCalcCom = useTypedRedux("customize", "is_cocalc_com");
4646
const user_defined_llm = useTypedRedux("customize", "user_defined_llm");
47+
4748
const [model, setModel] = useLanguageModelSetting();
4849

4950
function on_change(name: string, value: any): void {
@@ -398,24 +399,33 @@ export function OtherSettings(props: Readonly<Props>): JSX.Element {
398399
return <UserDefinedLLMComponent on_change={on_change} />;
399400
}
400401

402+
function render_llm_settings() {
403+
// we hide this panel, if all servers and user defined LLms are disabled
404+
const customize = redux.getStore("customize");
405+
const enabledLLMs = customize.getEnabledLLMs();
406+
const anyLLMenabled = Object.values(enabledLLMs).some((v) => v);
407+
if (!anyLLMenabled) return;
408+
return (
409+
<Panel
410+
header={
411+
<>
412+
<AIAvatar size={22} /> AI Settings
413+
</>
414+
}
415+
>
416+
{render_disable_all_llm()}
417+
{render_language_model()}
418+
{render_custom_llm()}
419+
</Panel>
420+
);
421+
}
422+
401423
if (props.other_settings == null) {
402424
return <Loading />;
403425
}
404426
return (
405427
<>
406-
{redux.getStore("customize").get("openai_enabled") ? (
407-
<Panel
408-
header={
409-
<>
410-
<AIAvatar size={22} /> AI Settings
411-
</>
412-
}
413-
>
414-
{render_disable_all_llm()}
415-
{render_language_model()}
416-
{render_custom_llm()}
417-
</Panel>
418-
) : undefined}
428+
{render_llm_settings()}
419429

420430
<Panel
421431
header={

src/packages/frontend/customize.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,7 @@ export interface CustomizeState {
165165
custom_openai?: TypedMap<{ [key: string]: TypedMap<CustomLLMPublic> }>;
166166
selectable_llms: List<string>;
167167
default_llm?: string;
168-
user_defined_llm?: boolean;
168+
user_defined_llm: boolean;
169169
}
170170

171171
export class CustomizeStore extends Store<CustomizeState> {
@@ -193,7 +193,7 @@ export class CustomizeStore extends Store<CustomizeState> {
193193
custom_openai: this.get("custom_openai_enabled"),
194194
mistralai: this.get("mistral_enabled"),
195195
anthropic: this.get("anthropic_enabled"),
196-
user: !this.get("is_cocalc_com"),
196+
user: this.get("user_defined_llm"),
197197
};
198198
}
199199
}

src/packages/frontend/project/context.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,7 @@ export function useProjectContextProvider(
108108
const haveCustomOpenAI = useTypedRedux("customize", "custom_openai_enabled");
109109
const haveMistral = useTypedRedux("customize", "mistral_enabled");
110110
const haveAnthropic = useTypedRedux("customize", "anthropic_enabled");
111+
const userDefinedLLM = useTypedRedux("customize", "user_defined_llm");
111112

112113
const enabledLLMs = useMemo(() => {
113114
const projectsStore = redux.getStore("projects");
@@ -119,6 +120,7 @@ export function useProjectContextProvider(
119120
haveCustomOpenAI,
120121
haveMistral,
121122
haveAnthropic,
123+
userDefinedLLM,
122124
]);
123125

124126
return {

0 commit comments

Comments
 (0)